Skip to content

Commit a859617

Browse files
committed
changes
1 parent ba6a494 commit a859617

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

demo/cache_demo/run.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,29 @@ async def translate(text, target_language):
5252
}
5353

5454

55+
def _message_plain_text(message):
56+
content = message["content"]
57+
if isinstance(content, str):
58+
return content
59+
if isinstance(content, list):
60+
parts = []
61+
for part in content:
62+
if isinstance(part, str):
63+
parts.append(part)
64+
elif isinstance(part, dict) and part.get("type") == "text":
65+
parts.append(part.get("text", ""))
66+
return "".join(parts)
67+
return str(content)
68+
69+
5570
@gr.cache
5671
def chat_respond(history):
5772
if not history:
5873
yield history
5974
return
60-
last_msg = history[-1]["content"].lower().strip()
61-
response = RESPONSES.get(last_msg, f"You said: '{history[-1]['content']}'")
75+
user_text = _message_plain_text(history[-1])
76+
last_msg = user_text.lower().strip()
77+
response = RESPONSES.get(last_msg, f"You said: '{user_text}'")
6278
history.append({"role": "assistant", "content": ""})
6379
for i in range(len(response)):
6480
history[-1]["content"] = response[: i + 1]

0 commit comments

Comments
 (0)