aimeri commited on
Commit
9f83467
·
1 Parent(s): 417050f

Refactor chat history processing in app.py to support both dictionary and list formats for messages, enhancing compatibility with previous data structures. Update text input handling to align with new message format, ensuring consistent user experience.

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -75,9 +75,13 @@ def process_input(image, audio, video, text, chat_history, voice_type, enable_au
75
 
76
  # Add previous chat history
77
  if isinstance(chat_history, list):
78
- for item in chat_history:
79
- if isinstance(item, list) and len(item) == 2:
80
- user_msg, bot_msg = item
 
 
 
 
81
  if bot_msg is not None: # Only add complete message pairs
82
  # Convert display format back to processable format
83
  processed_msg = user_msg
@@ -346,7 +350,7 @@ def create_demo():
346
 
347
  # Text input handling
348
  text_submit.click(
349
- fn=lambda text: [[text if text is not None else "", None]],
350
  inputs=text_input,
351
  outputs=[chatbot],
352
  queue=False
 
75
 
76
  # Add previous chat history
77
  if isinstance(chat_history, list):
78
+ for message in chat_history:
79
+ if isinstance(message, dict) and "role" in message and "content" in message:
80
+ # Messages are already in the correct format
81
+ conversation.append(message)
82
+ elif isinstance(message, list) and len(message) == 2:
83
+ # Convert old format to new format
84
+ user_msg, bot_msg = message
85
  if bot_msg is not None: # Only add complete message pairs
86
  # Convert display format back to processable format
87
  processed_msg = user_msg
 
350
 
351
  # Text input handling
352
  text_submit.click(
353
+ fn=lambda text: [{"role": "user", "content": text if text is not None else ""}],
354
  inputs=text_input,
355
  outputs=[chatbot],
356
  queue=False