Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
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'
|
141 |
latest_question = message['input']
|
142 |
-
|
|
|
143 |
break
|
144 |
|
145 |
-
|
|
|
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,
|