Spaces:
Runtime error
Runtime error
Cascade Bot
commited on
Commit
·
b065baa
1
Parent(s):
5901371
fix: update chatbot to use new message format
Browse files- Added type='messages' to use OpenAI-style message format
- Updated history handling to use role/content dictionaries
- Fixed retry functionality for new message format
- Resolved deprecated tuple format warning
app.py
CHANGED
@@ -251,7 +251,8 @@ class ChatInterface:
|
|
251 |
show_copy_button=True,
|
252 |
render_markdown=True,
|
253 |
container=True,
|
254 |
-
elem_classes=["chat-window"]
|
|
|
255 |
)
|
256 |
|
257 |
with gr.Row():
|
@@ -287,34 +288,32 @@ class ChatInterface:
|
|
287 |
"""Handle chat responses with proper formatting."""
|
288 |
try:
|
289 |
# Convert history to the format expected by process_message
|
290 |
-
history_list = [[
|
291 |
response = await self.process_message(message, history_list)
|
292 |
|
293 |
# Format response for markdown rendering
|
294 |
formatted_response = response.replace('```', '\n```\n')
|
295 |
|
296 |
-
# Update history
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
return "", history
|
302 |
except Exception as e:
|
303 |
logger.error(f"Error in chat response: {str(e)}")
|
304 |
error_msg = "I apologize, but I encountered an error. Please try again."
|
305 |
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
return "", history
|
311 |
|
312 |
async def retry_last(history):
|
313 |
"""Retry the last message with proper formatting."""
|
314 |
if not history:
|
315 |
return history
|
316 |
-
last_user_msg = history[-
|
317 |
-
history = history[:-
|
318 |
return await respond(last_user_msg, history)
|
319 |
|
320 |
# Submit handlers with loading states
|
|
|
251 |
show_copy_button=True,
|
252 |
render_markdown=True,
|
253 |
container=True,
|
254 |
+
elem_classes=["chat-window"],
|
255 |
+
type="messages" # Use the new message format
|
256 |
)
|
257 |
|
258 |
with gr.Row():
|
|
|
288 |
"""Handle chat responses with proper formatting."""
|
289 |
try:
|
290 |
# Convert history to the format expected by process_message
|
291 |
+
history_list = [[msg["content"] for msg in exchange] for exchange in history] if history else []
|
292 |
response = await self.process_message(message, history_list)
|
293 |
|
294 |
# Format response for markdown rendering
|
295 |
formatted_response = response.replace('```', '\n```\n')
|
296 |
|
297 |
+
# Update history with the new message format
|
298 |
+
return "", history + [
|
299 |
+
{"role": "user", "content": message},
|
300 |
+
{"role": "assistant", "content": formatted_response}
|
301 |
+
]
|
|
|
302 |
except Exception as e:
|
303 |
logger.error(f"Error in chat response: {str(e)}")
|
304 |
error_msg = "I apologize, but I encountered an error. Please try again."
|
305 |
|
306 |
+
return "", history + [
|
307 |
+
{"role": "user", "content": message},
|
308 |
+
{"role": "assistant", "content": error_msg}
|
309 |
+
]
|
|
|
310 |
|
311 |
async def retry_last(history):
|
312 |
"""Retry the last message with proper formatting."""
|
313 |
if not history:
|
314 |
return history
|
315 |
+
last_user_msg = history[-2]["content"] # Get the last user message
|
316 |
+
history = history[:-2] # Remove last exchange
|
317 |
return await respond(last_user_msg, history)
|
318 |
|
319 |
# Submit handlers with loading states
|