paloma99 commited on
Commit
457b66b
·
verified ·
1 Parent(s): e08fbf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -125,7 +125,7 @@ qa_chain = ConversationalRetrievalChain.from_llm(
125
  )
126
 
127
  def chat_interface(question, history):
128
- # Invoke the QA chain to get the latest answer
129
  result = qa_chain.invoke({"question": question})
130
 
131
  # Access the history stored in the memory
@@ -137,12 +137,14 @@ def chat_interface(question, history):
137
  for message in all_messages[::-1]:
138
  if message['output_key'] == 'answer':
139
  latest_answer = message['output']
140
- elif message['input_key'] == 'question' and latest_question is None:
141
  latest_question = message['input']
142
- if latest_question is not None and latest_answer is not None:
 
143
  break
144
 
145
- return latest_answer # Return the answer to the latest question
 
146
 
147
  chatbot_gradio_app = gr.ChatInterface(
148
  fn=chat_interface,
 
125
  )
126
 
127
  def chat_interface(question, history):
128
+ # Invoke the QA chain to get the result for the latest question
129
  result = qa_chain.invoke({"question": question})
130
 
131
  # Access the history stored in the memory
 
137
  for message in all_messages[::-1]:
138
  if message['output_key'] == 'answer':
139
  latest_answer = message['output']
140
+ elif message['input_key'] == 'question':
141
  latest_question = message['input']
142
+ # If we have found the latest question and its corresponding answer,
143
+ # break out of the loop to avoid unnecessary iterations
144
  break
145
 
146
+ # Return the latest answer if available, otherwise return an empty string
147
+ return latest_answer
148
 
149
  chatbot_gradio_app = gr.ChatInterface(
150
  fn=chat_interface,