Spaces:
Runtime error
Runtime error
Fix chatbot response format for streaming output
Browse files
app.py
CHANGED
|
@@ -75,11 +75,11 @@ async def research_assistant(query):
|
|
| 75 |
|
| 76 |
for chunk in stream:
|
| 77 |
full_response += chunk
|
| 78 |
-
yield
|
| 79 |
|
| 80 |
citations = generate_citations(search_results)
|
| 81 |
citation_text = format_citations(citations)
|
| 82 |
-
full_output =
|
| 83 |
|
| 84 |
cache_result(query, full_output)
|
| 85 |
server_monitor.report_success()
|
|
@@ -161,7 +161,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI Research Assistant") as demo:
|
|
| 161 |
""")
|
| 162 |
|
| 163 |
with gr.Column(scale=2):
|
| 164 |
-
chatbot = gr.Chatbot(height=500, label="Research Conversation")
|
| 165 |
msg = gr.Textbox(
|
| 166 |
label="Research Question",
|
| 167 |
placeholder="Ask a complex research question...",
|
|
@@ -183,10 +183,17 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI Research Assistant") as demo:
|
|
| 183 |
)
|
| 184 |
|
| 185 |
def respond(message, chat_history):
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
for partial_response in research_assistant_wrapper(message):
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
| 190 |
|
| 191 |
submit_btn.click(respond, [msg, chatbot], chatbot)
|
| 192 |
msg.submit(respond, [msg, chatbot], chatbot)
|
|
|
|
| 75 |
|
| 76 |
for chunk in stream:
|
| 77 |
full_response += chunk
|
| 78 |
+
yield full_response # Yield plain string for chatbot processing
|
| 79 |
|
| 80 |
citations = generate_citations(search_results)
|
| 81 |
citation_text = format_citations(citations)
|
| 82 |
+
full_output = full_response + citation_text
|
| 83 |
|
| 84 |
cache_result(query, full_output)
|
| 85 |
server_monitor.report_success()
|
|
|
|
| 161 |
""")
|
| 162 |
|
| 163 |
with gr.Column(scale=2):
|
| 164 |
+
chatbot = gr.Chatbot(height=500, label="Research Conversation", latex_delimiters=[{"left": "$$", "right": "$$", "display": True}])
|
| 165 |
msg = gr.Textbox(
|
| 166 |
label="Research Question",
|
| 167 |
placeholder="Ask a complex research question...",
|
|
|
|
| 183 |
)
|
| 184 |
|
| 185 |
def respond(message, chat_history):
|
| 186 |
+
# Add user message to chat history
|
| 187 |
+
chat_history.append((message, ""))
|
| 188 |
+
yield chat_history
|
| 189 |
+
|
| 190 |
+
# Get streaming response
|
| 191 |
+
full_response = ""
|
| 192 |
for partial_response in research_assistant_wrapper(message):
|
| 193 |
+
full_response = partial_response
|
| 194 |
+
# Update the last message in chat history with the partial response
|
| 195 |
+
chat_history[-1] = (message, full_response)
|
| 196 |
+
yield chat_history
|
| 197 |
|
| 198 |
submit_btn.click(respond, [msg, chatbot], chatbot)
|
| 199 |
msg.submit(respond, [msg, chatbot], chatbot)
|