From 900be3e02dc645528ad0086ac3e694d75d5c881f Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 27 Jul 2025 18:25:42 +0800 Subject: [PATCH] . --- meta_ui.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/meta_ui.py b/meta_ui.py index c7b5ea3..e4ea2b1 100644 --- a/meta_ui.py +++ b/meta_ui.py @@ -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(