Spaces:
Running
Running
kenghuoxiong
commited on
Commit
•
adbbf1a
1
Parent(s):
63b723e
Update app.py
Browse files
app.py
CHANGED
@@ -39,10 +39,26 @@ prompt_template = """
|
|
39 |
The above content is a form of biological background knowledge. Please answer the questions according to the above content. Please be sure to answer the questions according to the background knowledge and attach the doi number of the information source when answering.
|
40 |
Question: {question}
|
41 |
Answer in English:"""
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
)
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
def respond(
|
48 |
message,
|
|
|
39 |
The above content is a form of biological background knowledge. Please answer the questions according to the above content. Please be sure to answer the questions according to the background knowledge and attach the doi number of the information source when answering.
|
40 |
Question: {question}
|
41 |
Answer in English:"""
|
42 |
+
PROMPT = PromptTemplate(
|
43 |
+
template=prompt_template, input_variables=["context", "question"]
|
44 |
+
)
|
45 |
+
chain_type_kwargs = {"prompt": PROMPT}
|
46 |
+
retriever = db.as_retriever()
|
47 |
+
qa = RetrievalQA.from_chain_type(
|
48 |
+
llm=llm,
|
49 |
+
chain_type="stuff",
|
50 |
+
retriever=retriever,
|
51 |
+
chain_type_kwargs=chain_type_kwargs,
|
52 |
+
return_source_documents=True
|
53 |
)
|
54 |
+
|
55 |
+
def chat(question, history):
|
56 |
+
if len(history) == 0:
|
57 |
+
response = qa.invoke(question)['result']
|
58 |
+
else:
|
59 |
+
response = qwen_api(question, gradio_history=history)
|
60 |
+
return response
|
61 |
+
|
62 |
|
63 |
def respond(
|
64 |
message,
|