Update app.py
Browse files
app.py
CHANGED
@@ -69,31 +69,32 @@ class AdvancedPdfChatbot:
|
|
69 |
self.overall_chain = self.CustomChain(refinement_chain=refinement_chain, qa_chain=qa_chain)
|
70 |
|
71 |
class CustomChain(Chain):
|
72 |
-
def __init__(self, refinement_chain, qa_chain):
|
73 |
-
super().__init__()
|
74 |
-
self.refinement_chain = refinement_chain
|
75 |
-
self.qa_chain = qa_chain
|
76 |
-
|
77 |
-
@property
|
78 |
-
def input_keys(self):
|
79 |
-
return ["query", "chat_history"]
|
80 |
-
|
81 |
-
@property
|
82 |
-
def output_keys(self):
|
83 |
-
return ["answer"]
|
84 |
-
|
85 |
-
def _call(self, inputs):
|
86 |
-
query = inputs['query']
|
87 |
-
chat_history = inputs.get('chat_history', [])
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
|
99 |
|
|
|
69 |
self.overall_chain = self.CustomChain(refinement_chain=refinement_chain, qa_chain=qa_chain)
|
70 |
|
71 |
class CustomChain(Chain):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
def __init__(self, refinement_chain, qa_chain):
|
74 |
+
super().__init__()
|
75 |
+
self.refinement_chain = refinement_chain
|
76 |
+
self.qa_chain = qa_chain
|
77 |
+
|
78 |
+
@property
|
79 |
+
def input_keys(self):
|
80 |
+
return ["query", "chat_history"]
|
81 |
+
|
82 |
+
@property
|
83 |
+
def output_keys(self):
|
84 |
+
return ["answer"]
|
85 |
+
|
86 |
+
def _call(self, inputs):
|
87 |
+
query = inputs['query']
|
88 |
+
chat_history = inputs.get('chat_history', [])
|
89 |
+
|
90 |
+
# Run the refinement chain to refine the query
|
91 |
+
refined_query = self.refinement_chain.run({'query': query, 'chat_history': chat_history})
|
92 |
+
|
93 |
+
# Run the QA chain using the refined query and the chat history
|
94 |
+
response = self.qa_chain({'question': refined_query, 'chat_history': chat_history})
|
95 |
+
|
96 |
+
# Return the answer
|
97 |
+
return {"answer": response['answer']}
|
98 |
|
99 |
|
100 |
|