This commit is contained in:
parent
db9e41c3e0
commit
45c24387d9
17
meta_ui.py
17
meta_ui.py
|
|
@ -148,20 +148,9 @@ def chat(
|
||||||
except Empty:
|
except Empty:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 你之前在 worker() 中把完整字符串放进 result_q,所以这里只是字符串
|
# 你用 backend 返回的其实已经是 content 字符串了,不要再转 json!
|
||||||
if isinstance(result, str):
|
txt = result.strip() if isinstance(result, str) else str(result).strip()
|
||||||
# 假设是 JSON 字符串(但你原来实际放的是 content 文本)
|
# 注意,这里必须 yield {"text": txt}, log_state
|
||||||
try:
|
|
||||||
parsed = json.loads(result)
|
|
||||||
txt = parsed["choices"][0]["message"]["content"].strip()
|
|
||||||
except Exception:
|
|
||||||
txt = result.strip()
|
|
||||||
elif isinstance(result, dict):
|
|
||||||
txt = result.get("text", "").strip()
|
|
||||||
else:
|
|
||||||
txt = str(result).strip()
|
|
||||||
|
|
||||||
# ✅ 推荐返回结构,自动渲染 + 自动 history 追加
|
|
||||||
yield {"text": txt}, log_state
|
yield {"text": txt}, log_state
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue