Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,7 @@ from langchain.schema import (
|
|
| 23 |
SystemMessage
|
| 24 |
)
|
| 25 |
|
|
|
|
| 26 |
import time
|
| 27 |
import langchain
|
| 28 |
import os
|
|
@@ -37,14 +38,15 @@ embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-large-en")
|
|
| 37 |
docsearch = FAISS.load_local("./faiss_index", embeddings)
|
| 38 |
template="您是回答ANSYS软件使用查询的得力助手,所有回复必需用中文"
|
| 39 |
chain = load_qa_chain(OpenAI(temperature=0,model_name="gpt-3.5-turbo"), chain_type="stuff",verbose=True)
|
| 40 |
-
|
|
|
|
| 41 |
history_langchain_format = []
|
| 42 |
for human, ai in history:
|
| 43 |
history_langchain_format.append(HumanMessage(content=human))
|
| 44 |
history_langchain_format.append(AIMessage(content=ai))
|
| 45 |
history_langchain_format.append(HumanMessage(content=en_message))
|
| 46 |
docs = docsearch.similarity_search(message)
|
| 47 |
-
response = chain.run(input_documents=docs, question=message + template)
|
| 48 |
|
| 49 |
partial_message = ""
|
| 50 |
for chunk in response:
|
|
|
|
| 23 |
SystemMessage
|
| 24 |
)
|
| 25 |
|
| 26 |
+
import asyncio
|
| 27 |
import time
|
| 28 |
import langchain
|
| 29 |
import os
|
|
|
|
| 38 |
docsearch = FAISS.load_local("./faiss_index", embeddings)
|
| 39 |
template="您是回答ANSYS软件使用查询的得力助手,所有回复必需用中文"
|
| 40 |
chain = load_qa_chain(OpenAI(temperature=0,model_name="gpt-3.5-turbo"), chain_type="stuff",verbose=True)
|
| 41 |
+
|
| 42 |
+
async def predict(message, history):
|
| 43 |
history_langchain_format = []
|
| 44 |
for human, ai in history:
|
| 45 |
history_langchain_format.append(HumanMessage(content=human))
|
| 46 |
history_langchain_format.append(AIMessage(content=ai))
|
| 47 |
history_langchain_format.append(HumanMessage(content=en_message))
|
| 48 |
docs = docsearch.similarity_search(message)
|
| 49 |
+
response = await chain.run(input_documents=docs, question=message + template)
|
| 50 |
|
| 51 |
partial_message = ""
|
| 52 |
for chunk in response:
|