hadadrjt commited on
Commit
933e48c
·
1 Parent(s): 3ef53bc

ai: Hanlde file upload issue.

Browse files
Files changed (1) hide show
  1. jarvis.py +13 -6
jarvis.py CHANGED
@@ -165,18 +165,25 @@ async def respond_async(multi, history, model_display, sess, custom_prompt):
165
  return
166
  inp = ""
167
  for f in msg["files"]:
168
- p = f["name"] if isinstance(f, dict) and "name" in f else f
169
- inp += f"{Path(p).name}\n\n{extract_file_content(p)}\n\n"
 
 
 
170
  if msg["text"]:
171
  inp += msg["text"]
172
  history.append([inp, ""])
173
  ai = await chat_with_model_async(history, inp, model_display, sess, custom_prompt)
174
  history[-1][1] = ""
175
  def to_str(d):
176
- if isinstance(d, (str, int, float)): return str(d)
177
- if isinstance(d, bytes): return d.decode("utf-8", errors="ignore")
178
- if isinstance(d, (list, tuple)): return "".join(map(to_str, d))
179
- if isinstance(d, dict): return json.dumps(d, ensure_ascii=False)
 
 
 
 
180
  return repr(d)
181
  for c in ai:
182
  history[-1][1] += to_str(c)
 
165
  return
166
  inp = ""
167
  for f in msg["files"]:
168
+ if isinstance(f, dict):
169
+ fp = f.get("data", f.get("name", ""))
170
+ else:
171
+ fp = f
172
+ inp += f"{Path(fp).name}\n\n{extract_file_content(fp)}\n\n"
173
  if msg["text"]:
174
  inp += msg["text"]
175
  history.append([inp, ""])
176
  ai = await chat_with_model_async(history, inp, model_display, sess, custom_prompt)
177
  history[-1][1] = ""
178
  def to_str(d):
179
+ if isinstance(d, (str, int, float)):
180
+ return str(d)
181
+ if isinstance(d, bytes):
182
+ return d.decode("utf-8", errors="ignore")
183
+ if isinstance(d, (list, tuple)):
184
+ return "".join(map(to_str, d))
185
+ if isinstance(d, dict):
186
+ return json.dumps(d, ensure_ascii=False)
187
  return repr(d)
188
  for c in ai:
189
  history[-1][1] += to_str(c)