This commit is contained in:
parent
91194df5d8
commit
9cb53f50f6
33
meta_ui.py
33
meta_ui.py
|
|
@ -115,22 +115,43 @@ def chat(
|
|||
out = backend(user, samp, api_suffix)
|
||||
result_q.put(out)
|
||||
|
||||
threading.Thread(target=worker).start()
|
||||
# threading.Thread(target=worker).start()
|
||||
thread = threading.Thread(target=worker, daemon=True)
|
||||
yield "⏳ 正在生成中...", log_state
|
||||
|
||||
|
||||
while True:
|
||||
# ⚠️ 线程已结束且队列已空 → 直接 return 让生成器终止
|
||||
if not thread.is_alive() and result_q.empty():
|
||||
return # ← 新增这一行
|
||||
|
||||
try:
|
||||
result = result_q.get(timeout=0.1)
|
||||
# ★ 不论 /generate(纯 str)还是 /v1/completions(dict),都转成 {"text": ...}
|
||||
except Empty:
|
||||
continue
|
||||
|
||||
# 统一格式
|
||||
if isinstance(result, str):
|
||||
result = {"text": result}
|
||||
elif not isinstance(result, dict) or "text" not in result:
|
||||
result = {"text": str(result)}
|
||||
|
||||
yield result, log_state
|
||||
break
|
||||
except Empty:
|
||||
continue
|
||||
yield result, log_state # 第一次真正把模型回复丢给前端
|
||||
return # ← 把旧的 break 换成 return
|
||||
|
||||
# while True:
|
||||
# try:
|
||||
# result = result_q.get(timeout=0.1)
|
||||
# # ★ 不论 /generate(纯 str)还是 /v1/completions(dict),都转成 {"text": ...}
|
||||
# if isinstance(result, str):
|
||||
# result = {"text": result}
|
||||
# elif not isinstance(result, dict) or "text" not in result:
|
||||
# result = {"text": str(result)}
|
||||
|
||||
# yield result, log_state
|
||||
# break
|
||||
# except Empty:
|
||||
# continue
|
||||
|
||||
|
||||
# ────────────────── Gradio UI ──────────────────
|
||||
|
|
|
|||
Loading…
Reference in New Issue