Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,6 @@ from langchain.schema import (
|
|
23 |
SystemMessage
|
24 |
)
|
25 |
|
26 |
-
import asyncio
|
27 |
import time
|
28 |
import langchain
|
29 |
import os
|
@@ -39,14 +38,14 @@ 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 |
-
|
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 =
|
50 |
|
51 |
partial_message = ""
|
52 |
for chunk in response:
|
@@ -58,7 +57,7 @@ async def predict(message, history):
|
|
58 |
langchain.llm_cache = InMemoryCache()
|
59 |
|
60 |
gr.ChatInterface(predict,
|
61 |
-
textbox=gr.Textbox(placeholder="
|
62 |
title="欢迎使用ANSYS软件AI机器人",
|
63 |
examples=["你是谁?", "请介绍一下Fluent 软件", "create-bounding-box","ANSYS Fluent Architecture","ANSYS Fluent 的软件架构是怎么样的"],
|
64 |
-
description="
|
|
|
23 |
SystemMessage
|
24 |
)
|
25 |
|
|
|
26 |
import time
|
27 |
import langchain
|
28 |
import os
|
|
|
38 |
template="您是回答ANSYS软件使用查询的得力助手,所有回复必需用中文"
|
39 |
chain = load_qa_chain(OpenAI(temperature=0,model_name="gpt-3.5-turbo"), chain_type="stuff",verbose=True)
|
40 |
|
41 |
+
def predict(message, history):
|
42 |
history_langchain_format = []
|
43 |
for human, ai in history:
|
44 |
history_langchain_format.append(HumanMessage(content=human))
|
45 |
history_langchain_format.append(AIMessage(content=ai))
|
46 |
history_langchain_format.append(HumanMessage(content=en_message))
|
47 |
docs = docsearch.similarity_search(message)
|
48 |
+
response = chain.run(input_documents=docs, question=message + template)
|
49 |
|
50 |
partial_message = ""
|
51 |
for chunk in response:
|
|
|
57 |
langchain.llm_cache = InMemoryCache()
|
58 |
|
59 |
gr.ChatInterface(predict,
|
60 |
+
textbox=gr.Textbox(placeholder="请提问关于ANSYS软件的问题", container=False, scale=7),
|
61 |
title="欢迎使用ANSYS软件AI机器人",
|
62 |
examples=["你是谁?", "请介绍一下Fluent 软件", "create-bounding-box","ANSYS Fluent Architecture","ANSYS Fluent 的软件架构是怎么样的"],
|
63 |
+
description="请避免输入有违公序良俗的问题,模型可能无法回答不合适的问题🐇",).queue().launch(debug=True)
|