Spaces:
Sleeping
Sleeping
updated app.py
Browse files
app.py
CHANGED
|
@@ -66,9 +66,36 @@ def chat_with_agent(question: str, file_uploads, history: list) -> tuple:
|
|
| 66 |
else:
|
| 67 |
response = agent(question)
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
# Add question and response to history in the correct format
|
| 70 |
history.append({"role": "user", "content": question})
|
| 71 |
-
history.append({"role": "assistant", "content":
|
| 72 |
|
| 73 |
return history, ""
|
| 74 |
except Exception as e:
|
|
|
|
| 66 |
else:
|
| 67 |
response = agent(question)
|
| 68 |
|
| 69 |
+
# Format the response to show thought process
|
| 70 |
+
formatted_response = ""
|
| 71 |
+
if "Thought:" in response:
|
| 72 |
+
# Split the response into sections
|
| 73 |
+
sections = response.split("\n\n")
|
| 74 |
+
for section in sections:
|
| 75 |
+
if section.startswith("Thought:"):
|
| 76 |
+
formatted_response += f"🤔 {section[7:].strip()}\n\n"
|
| 77 |
+
elif section.startswith("Action:"):
|
| 78 |
+
# Extract the tool being used
|
| 79 |
+
if "action" in section and "action_input" in section:
|
| 80 |
+
try:
|
| 81 |
+
import json
|
| 82 |
+
action_json = json.loads(section.split("```json")[1].split("```")[0].strip())
|
| 83 |
+
tool_name = action_json.get("action", "").replace("_", " ").title()
|
| 84 |
+
formatted_response += f"🛠️ Using {tool_name}...\n\n"
|
| 85 |
+
except:
|
| 86 |
+
formatted_response += f"🛠️ {section[7:].strip()}\n\n"
|
| 87 |
+
elif section.startswith("Observation:"):
|
| 88 |
+
formatted_response += f"📝 {section[11:].strip()}\n\n"
|
| 89 |
+
elif section.startswith("Final Answer:"):
|
| 90 |
+
formatted_response += f"✨ {section[12:].strip()}\n\n"
|
| 91 |
+
else:
|
| 92 |
+
formatted_response += f"{section}\n\n"
|
| 93 |
+
else:
|
| 94 |
+
formatted_response = response
|
| 95 |
+
|
| 96 |
# Add question and response to history in the correct format
|
| 97 |
history.append({"role": "user", "content": question})
|
| 98 |
+
history.append({"role": "assistant", "content": formatted_response})
|
| 99 |
|
| 100 |
return history, ""
|
| 101 |
except Exception as e:
|