guangliang.yin commited on
Commit
1a58e38
1 Parent(s): 80b6833

改为简单链-3

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -19,6 +19,7 @@ from langchain.chains.combine_documents.refine import RefineDocumentsChain
19
  from langchain.chains.llm import LLMChain
20
  from langchain.chains.combine_documents import create_stuff_documents_chain
21
  from langchain.chains import StuffDocumentsChain
 
22
 
23
  chain: Optional[Callable] = None
24
 
@@ -80,10 +81,21 @@ def web_loader(file, openai_key, puzhiai_key, zilliz_uri, user, password):
80
  # document_prompt=EXAMPLE_PROMPT,
81
  #)
82
 
 
 
 
 
 
 
 
 
 
 
 
83
  combine_documents_chain = StuffDocumentsChain(
84
- llm_chain=llm,
85
- document_prompt=QUESTION_PROMPT,
86
- document_variable_name="context"
87
  )
88
 
89
  chain = RetrievalQAWithSourcesChain(combine_documents_chain=combine_documents_chain,
 
19
  from langchain.chains.llm import LLMChain
20
  from langchain.chains.combine_documents import create_stuff_documents_chain
21
  from langchain.chains import StuffDocumentsChain
22
+ from langchain_core.prompts import PromptTemplate
23
 
24
  chain: Optional[Callable] = None
25
 
 
81
  # document_prompt=EXAMPLE_PROMPT,
82
  #)
83
 
84
+ document_prompt = PromptTemplate(
85
+ input_variables=["page_content"],
86
+ template="{page_content}"
87
+ )
88
+ document_variable_name = "context"
89
+ # The prompt here should take as an input variable the
90
+ # `document_variable_name`
91
+ prompt = PromptTemplate.from_template(
92
+ "Summarize this content: {context}"
93
+ )
94
+ llm_chain = LLMChain(llm=llm, prompt=prompt)
95
  combine_documents_chain = StuffDocumentsChain(
96
+ llm_chain=llm_chain,
97
+ document_prompt=document_prompt,
98
+ document_variable_name=document_variable_name
99
  )
100
 
101
  chain = RetrievalQAWithSourcesChain(combine_documents_chain=combine_documents_chain,