guangliang.yin commited on
Commit
3de91d2
1 Parent(s): 08e79a1

提示词改为自定义

Browse files
app.py CHANGED
@@ -8,6 +8,11 @@ from langchain.text_splitter import CharacterTextSplitter
8
  from langchain.chains import RetrievalQAWithSourcesChain
9
  import uuid
10
  from project.llm.zhipuai_llm import ZhipuAILLM
 
 
 
 
 
11
 
12
  chain: Optional[Callable] = None
13
 
@@ -43,9 +48,17 @@ def web_loader(file, openai_key, puzhiai_key, zilliz_uri, user, password):
43
  return "docsearch not"
44
 
45
  global chain
46
- chain = RetrievalQAWithSourcesChain.from_chain_type(
 
 
 
 
 
 
47
  ZhipuAILLM(model="glm-3-turbo", temperature=0.1, zhipuai_api_key=puzhiai_key),
48
- chain_type="refine",
 
 
49
  retriever=docsearch.as_retriever(),
50
  )
51
  return "success to load data"
@@ -68,7 +81,7 @@ if __name__ == "__main__":
68
  """
69
  <h1><center>Langchain And Zilliz App</center></h1>
70
 
71
- v.2.27.11.21
72
 
73
  """
74
  )
 
8
  from langchain.chains import RetrievalQAWithSourcesChain
9
  import uuid
10
  from project.llm.zhipuai_llm import ZhipuAILLM
11
+ from project.prompt.answer_by_private_prompt import (
12
+ COMBINE_PROMPT,
13
+ EXAMPLE_PROMPT,
14
+ QUESTION_PROMPT,
15
+ )
16
 
17
  chain: Optional[Callable] = None
18
 
 
48
  return "docsearch not"
49
 
50
  global chain
51
+ #chain = RetrievalQAWithSourcesChain.from_chain_type(
52
+ # ZhipuAILLM(model="glm-3-turbo", temperature=0.1, zhipuai_api_key=puzhiai_key),
53
+ # chain_type="refine",
54
+ # retriever=docsearch.as_retriever(),
55
+ #)
56
+
57
+ chain = RetrievalQAWithSourcesChain.from_llm(
58
  ZhipuAILLM(model="glm-3-turbo", temperature=0.1, zhipuai_api_key=puzhiai_key),
59
+ EXAMPLE_PROMPT,
60
+ QUESTION_PROMPT,
61
+ COMBINE_PROMPT,
62
  retriever=docsearch.as_retriever(),
63
  )
64
  return "success to load data"
 
81
  """
82
  <h1><center>Langchain And Zilliz App</center></h1>
83
 
84
+ v.2.27.13.58
85
 
86
  """
87
  )
project/prompt/__init__.py ADDED
File without changes
project/prompt/answer_by_private_prompt.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_core.prompts import PromptTemplate
2
+
3
+ question_prompt_template = """用提供给你的文档去回答问题,不需要编造或者虚构答案,也不需要回答文档之外的内容。
4
+ 如果在文档中没有找到相关的答案,那么就直接回答'知识库中没有相关问题解答'
5
+ 请用中文回答。
6
+ 下边是我给你提供的文档,其中文档格式都是一问一答。问题答案也完全来自所提供的回答:
7
+ {context}
8
+
9
+ 问题: {question}
10
+ 答:"""
11
+ QUESTION_PROMPT = PromptTemplate(
12
+ template=question_prompt_template, input_variables=["context", "question"]
13
+ )
14
+
15
+ combine_prompt_template = """
16
+ QUESTION: {question}
17
+ =========
18
+ {summaries}
19
+ =========
20
+ FINAL ANSWER:"""
21
+ COMBINE_PROMPT = PromptTemplate(
22
+ template=combine_prompt_template, input_variables=["summaries", "question"]
23
+ )
24
+
25
+ EXAMPLE_PROMPT = PromptTemplate(
26
+ template="Content: {page_content}\nSource: {source}",
27
+ input_variables=["page_content", "source"],
28
+ )