Update app.py
Browse files
app.py
CHANGED
@@ -69,34 +69,34 @@ class AdvancedPdfChatbot:
|
|
69 |
|
70 |
self.overall_chain = self.CustomChain(refinement_chain=refinement_chain, qa_chain=qa_chain)
|
71 |
|
72 |
-
|
73 |
def __init__(self, refinement_chain, qa_chain):
|
74 |
"""Initialize refinement and QA chains as instance attributes."""
|
75 |
super().__init__()
|
76 |
-
self.
|
77 |
-
self.
|
78 |
-
|
79 |
@property
|
80 |
def input_keys(self):
|
81 |
"""Define the input keys that this chain expects."""
|
82 |
return ["query", "chat_history"]
|
83 |
-
|
84 |
@property
|
85 |
def output_keys(self):
|
86 |
"""Define the output keys that this chain returns."""
|
87 |
return ["answer"]
|
88 |
-
|
89 |
def _call(self, inputs):
|
90 |
query = inputs['query']
|
91 |
chat_history = inputs.get('chat_history', [])
|
92 |
|
93 |
# Run the refinement chain to refine the query
|
94 |
refinement_inputs = {'query': query, 'chat_history': chat_history}
|
95 |
-
refined_query = self.
|
96 |
|
97 |
# Run the QA chain using the refined query and the chat history
|
98 |
qa_inputs = {"question": refined_query, "chat_history": chat_history}
|
99 |
-
response = self.
|
100 |
|
101 |
return {"answer": response['answer']}
|
102 |
|
|
|
69 |
|
70 |
self.overall_chain = self.CustomChain(refinement_chain=refinement_chain, qa_chain=qa_chain)
|
71 |
|
72 |
+
class CustomChain(Chain):
|
73 |
def __init__(self, refinement_chain, qa_chain):
|
74 |
"""Initialize refinement and QA chains as instance attributes."""
|
75 |
super().__init__()
|
76 |
+
self._refinement_chain = refinement_chain # Use a different attribute name
|
77 |
+
self._qa_chain = qa_chain
|
78 |
+
|
79 |
@property
|
80 |
def input_keys(self):
|
81 |
"""Define the input keys that this chain expects."""
|
82 |
return ["query", "chat_history"]
|
83 |
+
|
84 |
@property
|
85 |
def output_keys(self):
|
86 |
"""Define the output keys that this chain returns."""
|
87 |
return ["answer"]
|
88 |
+
|
89 |
def _call(self, inputs):
|
90 |
query = inputs['query']
|
91 |
chat_history = inputs.get('chat_history', [])
|
92 |
|
93 |
# Run the refinement chain to refine the query
|
94 |
refinement_inputs = {'query': query, 'chat_history': chat_history}
|
95 |
+
refined_query = self._refinement_chain.run(refinement_inputs) # Use the renamed attribute
|
96 |
|
97 |
# Run the QA chain using the refined query and the chat history
|
98 |
qa_inputs = {"question": refined_query, "chat_history": chat_history}
|
99 |
+
response = self._qa_chain(qa_inputs) # Use the renamed attribute
|
100 |
|
101 |
return {"answer": response['answer']}
|
102 |
|