This commit is contained in:
parent
ebe7f87009
commit
e71c4823ef
19
meta_ui.py
19
meta_ui.py
|
|
@ -148,14 +148,21 @@ def chat(
|
||||||
except Empty:
|
except Empty:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# 你之前在 worker() 中把完整字符串放进 result_q,所以这里只是字符串
|
||||||
if isinstance(result, str):
|
if isinstance(result, str):
|
||||||
result = {"text": result}
|
# 假设是 JSON 字符串(但你原来实际放的是 content 文本)
|
||||||
elif not isinstance(result, dict) or "text" not in result:
|
try:
|
||||||
result = {"text": str(result)}
|
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()
|
||||||
|
|
||||||
# ❌ 不 append 到 history(让前端 UI 不显示之前的历史)
|
# ✅ 推荐返回结构,自动渲染 + 自动 history 追加
|
||||||
# ✅ 但我们已经在前面把 history 全部传给 LLM 推理了
|
yield {"text": txt}, log_state
|
||||||
yield result["text"], None # UI 只显示当前回复
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
while thread.is_alive():
|
while thread.is_alive():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue