Spaces:
Sleeping
Sleeping
repair multiturn
Browse files
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
|
| 99 |
-
for
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|