Pavan178 commited on
Commit
b3de9a3
·
verified ·
1 Parent(s): 873a6e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
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
- 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
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)
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)
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