Spaces:
Sleeping
Sleeping
barathvasan-dev commited on
Commit ·
f9bd7d7
1
Parent(s): 72f433c
Fix: Resolve Chatbot message format error, asyncio event loop issues, and Mistral API compatibility
Browse files
app.py
CHANGED
|
@@ -664,8 +664,9 @@ with gr.Blocks(
|
|
| 664 |
if not message or len(message.strip()) < 2:
|
| 665 |
return chat_history, conv_state, inv_results
|
| 666 |
|
| 667 |
-
#
|
| 668 |
-
|
|
|
|
| 669 |
|
| 670 |
# Run investigation
|
| 671 |
result = ask_investigation_question(message)
|
|
@@ -673,14 +674,7 @@ with gr.Blocks(
|
|
| 673 |
# Format response for chat
|
| 674 |
if result.get("status") == "error":
|
| 675 |
error_msg = result.get("message", "Investigation failed")
|
| 676 |
-
ai_response = f"❌ **Investigation Failed**\n\n{error_msg}
|
| 677 |
-
|
| 678 |
-
# Add suggestions
|
| 679 |
-
follow_ups = result.get("follow_ups", [])
|
| 680 |
-
if follow_ups:
|
| 681 |
-
ai_response += "**💡 Try asking:**\n"
|
| 682 |
-
for q in follow_ups[:3]:
|
| 683 |
-
ai_response += f"• {q}\n"
|
| 684 |
else:
|
| 685 |
# Build comprehensive response for chat
|
| 686 |
answer = result.get("answer", "")
|
|
@@ -705,17 +699,8 @@ with gr.Blocks(
|
|
| 705 |
# Store full results for detailed tabs
|
| 706 |
inv_results = result
|
| 707 |
|
| 708 |
-
# Add
|
| 709 |
-
chat_history
|
| 710 |
-
|
| 711 |
-
# Add follow-up suggestions as next message
|
| 712 |
-
follow_ups = result.get("follow_ups", [])
|
| 713 |
-
if follow_ups and result.get("status") == "success":
|
| 714 |
-
follow_up_msg = "**💬 Would you like to know more about:**\n\n"
|
| 715 |
-
for idx, q in enumerate(follow_ups[:3], 1):
|
| 716 |
-
follow_up_msg += f"{idx}. {q}\n"
|
| 717 |
-
|
| 718 |
-
chat_history.append([None, follow_up_msg])
|
| 719 |
|
| 720 |
return chat_history, conv_state + [message], inv_results
|
| 721 |
|
|
|
|
| 664 |
if not message or len(message.strip()) < 2:
|
| 665 |
return chat_history, conv_state, inv_results
|
| 666 |
|
| 667 |
+
# Ensure chat_history is a list
|
| 668 |
+
if chat_history is None:
|
| 669 |
+
chat_history = []
|
| 670 |
|
| 671 |
# Run investigation
|
| 672 |
result = ask_investigation_question(message)
|
|
|
|
| 674 |
# Format response for chat
|
| 675 |
if result.get("status") == "error":
|
| 676 |
error_msg = result.get("message", "Investigation failed")
|
| 677 |
+
ai_response = f"❌ **Investigation Failed**\n\n{error_msg}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 678 |
else:
|
| 679 |
# Build comprehensive response for chat
|
| 680 |
answer = result.get("answer", "")
|
|
|
|
| 699 |
# Store full results for detailed tabs
|
| 700 |
inv_results = result
|
| 701 |
|
| 702 |
+
# Add complete [user, assistant] pair to chat history
|
| 703 |
+
chat_history = chat_history + [[message, ai_response]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 704 |
|
| 705 |
return chat_history, conv_state + [message], inv_results
|
| 706 |
|