hadadrjt commited on
Commit
13c3084
·
1 Parent(s): e0729bd

ai: Support multiple stream.

Browse files
Files changed (1) hide show
  1. jarvis.py +13 -2
jarvis.py CHANGED
@@ -159,9 +159,20 @@ def respond(multi_input, history, selected_model_display, sess):
159
  history.append([combined_input, ""])
160
  ai_response = chat_with_model(history, combined_input, selected_model_display, sess)
161
  history[-1][1] = ""
 
 
 
 
 
 
 
 
 
 
 
162
  for character in ai_response:
163
- history[-1][1] += str(character)
164
- time.sleep(0.0009)
165
  yield history, gr.MultimodalTextbox(value=None, interactive=True), sess
166
 
167
  def change_model(new_model_display):
 
159
  history.append([combined_input, ""])
160
  ai_response = chat_with_model(history, combined_input, selected_model_display, sess)
161
  history[-1][1] = ""
162
+ def convert_to_string(data):
163
+ if isinstance(data, (str, int, float)):
164
+ return str(data)
165
+ elif isinstance(data, bytes):
166
+ return data.decode("utf-8", errors="ignore")
167
+ elif isinstance(data, (list, tuple)):
168
+ return "".join(map(convert_to_string, data))
169
+ elif isinstance(data, dict):
170
+ return json.dumps(data, ensure_ascii=False)
171
+ else:
172
+ return repr(data)
173
  for character in ai_response:
174
+ history[-1][1] += convert_to_string(character)
175
+ time.sleep(0.0005)
176
  yield history, gr.MultimodalTextbox(value=None, interactive=True), sess
177
 
178
  def change_model(new_model_display):