Update app.py
Browse files
app.py
CHANGED
|
@@ -113,7 +113,7 @@ def respond(msg, chat_history, temperature, max_new_tokens, max_tokens, multi_ag
|
|
| 113 |
|
| 114 |
message = msg.strip()
|
| 115 |
chat_history.append({"role": "user", "content": message})
|
| 116 |
-
formatted_history = [(m["role"], m["content"]) for m in chat_history]
|
| 117 |
|
| 118 |
try:
|
| 119 |
response_generator = agent.run_gradio_chat(
|
|
@@ -129,17 +129,21 @@ def respond(msg, chat_history, temperature, max_new_tokens, max_tokens, multi_ag
|
|
| 129 |
call_agent_level=None,
|
| 130 |
sub_agent_task=None
|
| 131 |
)
|
|
|
|
| 132 |
collected = ""
|
| 133 |
for chunk in response_generator:
|
| 134 |
-
if chunk
|
| 135 |
-
|
| 136 |
-
elif isinstance(chunk,
|
| 137 |
-
collected += chunk
|
| 138 |
-
|
| 139 |
collected += str(chunk)
|
| 140 |
-
|
|
|
|
|
|
|
| 141 |
except Exception as e:
|
| 142 |
-
chat_history.append({"role": "assistant", "content": f"Error: {e}"})
|
|
|
|
| 143 |
return chat_history
|
| 144 |
|
| 145 |
def create_demo(agent):
|
|
|
|
| 113 |
|
| 114 |
message = msg.strip()
|
| 115 |
chat_history.append({"role": "user", "content": message})
|
| 116 |
+
formatted_history = [(m["role"], m["content"]) for m in chat_history if "role" in m and "content" in m]
|
| 117 |
|
| 118 |
try:
|
| 119 |
response_generator = agent.run_gradio_chat(
|
|
|
|
| 129 |
call_agent_level=None,
|
| 130 |
sub_agent_task=None
|
| 131 |
)
|
| 132 |
+
|
| 133 |
collected = ""
|
| 134 |
for chunk in response_generator:
|
| 135 |
+
if isinstance(chunk, dict) and "content" in chunk:
|
| 136 |
+
collected += chunk["content"]
|
| 137 |
+
elif isinstance(chunk, str):
|
| 138 |
+
collected += chunk
|
| 139 |
+
elif chunk is not None:
|
| 140 |
collected += str(chunk)
|
| 141 |
+
|
| 142 |
+
chat_history.append({"role": "assistant", "content": collected or "⚠️ No content returned."})
|
| 143 |
+
|
| 144 |
except Exception as e:
|
| 145 |
+
chat_history.append({"role": "assistant", "content": f"❌ Error: {str(e)}"})
|
| 146 |
+
|
| 147 |
return chat_history
|
| 148 |
|
| 149 |
def create_demo(agent):
|