Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -175,10 +175,15 @@ def respond_with_enhanced_streaming(message, history):
|
|
| 175 |
try:
|
| 176 |
api_messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
|
| 177 |
if history:
|
| 178 |
-
#
|
| 179 |
-
for exchange in history[-5:]:
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
api_messages.append({"role": "user", "content": message})
|
| 184 |
|
|
@@ -191,7 +196,7 @@ def respond_with_enhanced_streaming(message, history):
|
|
| 191 |
temperature=0.7,
|
| 192 |
top_p=0.9,
|
| 193 |
stream=True,
|
| 194 |
-
tools=tools,
|
| 195 |
)
|
| 196 |
|
| 197 |
# Buffers to handle multi-chunk tool calls
|
|
@@ -236,7 +241,6 @@ def respond_with_enhanced_streaming(message, history):
|
|
| 236 |
|
| 237 |
except json.JSONDecodeError:
|
| 238 |
logger.error("JSON parsing failed for tool arguments.")
|
| 239 |
-
# Yield an error or handle it silently
|
| 240 |
full_response += f"<p style='color:red;'>Error parsing graph data.</p>"
|
| 241 |
yield full_response
|
| 242 |
except Exception as e:
|
|
|
|
| 175 |
try:
|
| 176 |
api_messages = [{"role": "system", "content": SYSTEM_MESSAGE}]
|
| 177 |
if history:
|
| 178 |
+
# Handle the new messages format from Gradio
|
| 179 |
+
for exchange in history[-5:]: # Only use last 5 exchanges for context
|
| 180 |
+
if isinstance(exchange, dict):
|
| 181 |
+
# New format: {"role": "user", "content": "..."}
|
| 182 |
+
api_messages.append(exchange)
|
| 183 |
+
else:
|
| 184 |
+
# Old format: [user_message, assistant_message]
|
| 185 |
+
api_messages.append({"role": "user", "content": exchange[0]})
|
| 186 |
+
api_messages.append({"role": "assistant", "content": exchange[1]})
|
| 187 |
|
| 188 |
api_messages.append({"role": "user", "content": message})
|
| 189 |
|
|
|
|
| 196 |
temperature=0.7,
|
| 197 |
top_p=0.9,
|
| 198 |
stream=True,
|
| 199 |
+
tools=tools,
|
| 200 |
)
|
| 201 |
|
| 202 |
# Buffers to handle multi-chunk tool calls
|
|
|
|
| 241 |
|
| 242 |
except json.JSONDecodeError:
|
| 243 |
logger.error("JSON parsing failed for tool arguments.")
|
|
|
|
| 244 |
full_response += f"<p style='color:red;'>Error parsing graph data.</p>"
|
| 245 |
yield full_response
|
| 246 |
except Exception as e:
|