TobDeBer commited on
Commit
f8491dd
·
1 Parent(s): 799a37c

repair multiturn

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -95,15 +95,28 @@ def chat_predict(message, history, max_length, temperature, top_p, repetition_pe
95
  if system_prompt:
96
  messages.append({"role": "system", "content": system_prompt})
97
 
98
- # history is a list of lists: [[user_msg, bot_msg], ...]
99
- for user_msg, assistant_msg in history:
100
- if user_msg:
101
- messages.append({"role": "user", "content": user_msg})
102
- if assistant_msg:
103
- # Clean up history messages (remove stats if they were appended)
104
- if "\n\n---\n*Generated" in assistant_msg:
105
- assistant_msg = assistant_msg.split("\n\n---\n*Generated")[0]
106
- messages.append({"role": "assistant", "content": assistant_msg})
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
  messages.append({"role": "user", "content": message})
109
 
 
95
  if system_prompt:
96
  messages.append({"role": "system", "content": system_prompt})
97
 
98
+ # Handle history which can be list of dicts with multimodal content
99
+ for msg in history:
100
+ role = msg.get("role", "user")
101
+ content = msg.get("content", "")
102
+
103
+ # Extract text if content is a list (multimodal format in Gradio 6)
104
+ if isinstance(content, list):
105
+ text_content = ""
106
+ for part in content:
107
+ if isinstance(part, dict) and part.get("type") == "text":
108
+ text_content += part.get("text", "")
109
+ content = text_content
110
+
111
+ # Ensure content is string
112
+ if not isinstance(content, str):
113
+ content = str(content)
114
+
115
+ # Clean up assistant stats
116
+ if role == "assistant" and "\n\n---\n*Generated" in content:
117
+ content = content.split("\n\n---\n*Generated")[0]
118
+
119
+ messages.append({"role": role, "content": content})
120
 
121
  messages.append({"role": "user", "content": message})
122