File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
5671def 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 ]
You can’t perform that action at this time.
0 commit comments