Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,9 @@ import langchain
|
|
28 |
import os
|
29 |
OPENAI_API_KEY=os.getenv('OPENAI_API_KEY')
|
30 |
|
|
|
|
|
|
|
31 |
# 嵌入模型
|
32 |
#embeddings = OpenAIEmbeddings()
|
33 |
embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-large-en")
|
@@ -35,16 +38,19 @@ embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-large-en")
|
|
35 |
# 加载数据
|
36 |
#docsearch = FAISS.from_texts(texts, embeddings)
|
37 |
docsearch = FAISS.load_local("./faiss_index", embeddings)
|
38 |
-
chain = load_qa_chain(OpenAI(temperature=0,model_name="gpt-3.5-turbo", verbose=True), chain_type="stuff",verbose=True)
|
39 |
|
|
|
40 |
|
41 |
|
42 |
-
|
|
|
43 |
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
|
44 |
human_template="{text}"
|
45 |
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
|
46 |
|
47 |
-
|
|
|
|
|
48 |
|
49 |
def predict(message, history):
|
50 |
history_langchain_format = []
|
|
|
28 |
import os
|
29 |
OPENAI_API_KEY=os.getenv('OPENAI_API_KEY')
|
30 |
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
# 嵌入模型
|
35 |
#embeddings = OpenAIEmbeddings()
|
36 |
embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-large-en")
|
|
|
38 |
# 加载数据
|
39 |
#docsearch = FAISS.from_texts(texts, embeddings)
|
40 |
docsearch = FAISS.load_local("./faiss_index", embeddings)
|
|
|
41 |
|
42 |
+
#chain = load_qa_chain(OpenAI(temperature=0,model_name="gpt-3.5-turbo",prompt=chat_prompt), chain_type="stuff",verbose=True)
|
43 |
|
44 |
|
45 |
+
|
46 |
+
template="您是回答ANSYS软件使用查询的得力助手,所有回复必需用中文 {input_language} to {output_language}."
|
47 |
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
|
48 |
human_template="{text}"
|
49 |
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
|
50 |
|
51 |
+
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
|
52 |
+
chain = load_qa_chain(OpenAI(temperature=0,model_name="gpt-3.5-turbo",prompt=chat_prompt), chain_type="stuff",verbose=True)
|
53 |
+
|
54 |
|
55 |
def predict(message, history):
|
56 |
history_langchain_format = []
|