This commit is contained in:
hailin 2025-07-27 18:25:42 +08:00
parent 4bb857f22f
commit 900be3e02d
1 changed files with 13 additions and 9 deletions

View File

@ -46,8 +46,12 @@ def backend(text, sampling, api_suffix):
url = f"http://localhost:30000{api_suffix}"
if api_suffix == "/generate":
payload = {"model": MODEL_NAME, "text": text, "sampling_params": sampling}
else: # "/v1/completion"
payload = {"model": MODEL_NAME, "prompt": text, **sampling}
else: # "/v1/chat/completions"
payload = {
"model": MODEL_NAME,
"messages": [{"role": "user", "content": text}],
**sampling
}
log(f"\n🟡 [{now()}] POST {url}\n{json.dumps(payload, ensure_ascii=False, indent=2)}")
try:
@ -59,16 +63,18 @@ def backend(text, sampling, api_suffix):
data = r.json()
except Exception:
data = {}
if api_suffix == "/generate":
txt = data.get("text", "").strip()
meta = data.get("meta_info", {})
fr = meta.get("finish_reason")
ctok = meta.get("completion_tokens")
else:
else: # "/v1/chat/completions"
choice = data.get("choices", [{}])[0]
txt = choice.get("text", "").strip()
txt = choice.get("message", {}).get("content", "").strip()
fr = choice.get("finish_reason")
ctok = data.get("usage", {}).get("completion_tokens")
log(f"🟢 [{now()}] HTTP {r.status_code} tokens={ctok} finish={fr}\n"
f"🟢 resp800={r.text[:800]!r}")
if r.status_code != 200:
@ -122,7 +128,7 @@ with gr.Blocks(title="调试界面") as demo:
gr.Markdown(f"## 💬 调试界面 \n权重 **{MODEL_PATH.name}**")
with gr.Row():
api_choice = gr.Dropdown(choices=["/generate", "/v1/completion"],
api_choice = gr.Dropdown(choices=["/generate", "/v1/completions"],
value="/generate", label="选择推理接口")
# 采样参数控件
with gr.Row():
@ -145,13 +151,11 @@ with gr.Blocks(title="调试界面") as demo:
fn=chat,
additional_inputs=[max_new, temp, top_p, top_k,
rep_pen, pres_pen, stop_txt,
api_choice, log_state], # ✅ 加入 dropdown
additional_outputs=[log_state],
api_choice, log_state],
additional_outputs=[], # ✅ 移除 log_state 输出
type="messages"
)
# 日志刷新定时器
timer = gr.Timer(1.0, render=True)
timer.tick(