Spaces:
Build error
Build error
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
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
|
79 |
-
if isinstance(
|
80 |
-
|
|
|
|
|
|
|
|
|
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: [
|
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
|