From 66b11eb836f66b35fd1709f0281ade8fc91ad853 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 1 Aug 2025 13:33:54 +0800 Subject: [PATCH] . --- meta_ui.py | 80 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 78 deletions(-) diff --git a/meta_ui.py b/meta_ui.py index af9bd99..ea97f71 100644 --- a/meta_ui.py +++ b/meta_ui.py @@ -91,9 +91,9 @@ def backend(text, sampling, api_suffix): fr = choice.get("finish_reason") # 如果后续需要 finish reason log(f"🟢 [{now()}] HTTP {r.status_code} tokens={ctok} finish={fr}\n" - f"🟢 resp800={r.text[:800]!r}") + f"🟢 resp={r.text!r}") if r.status_code != 200: - return f"[HTTP {r.status_code}] {r.text[:300]}" + return f"[HTTP {r.status_code}] {r.text}" return txt or "[⚠ 空]" except Exception as e: log(f"[❌ 请求异常] {e}") @@ -173,82 +173,6 @@ def chat( yield result["text"], log_state return - - -# # ────────────────── Chat 回调 ────────────────── -# def chat( -# user_msg, history, -# max_new, temp, top_p, top_k, -# rep_pen, pres_pen, stop_raw, -# api_suffix, log_state -# ): -# from queue import Queue, Empty - -# # 解析传入的 ChatInput 格式 -# user = user_msg["text"] if isinstance(user_msg, dict) and "text" in user_msg else user_msg - -# # 构造 OpenAI 风格 messages,仅用于 /v1/chat/completions -# if api_suffix == "/v1/chat/completions": -# messages = [] -# messages = history[:] # 正确使用 OpenAI 格式 -# messages.append({"role": "user", "content": user}) -# prompt_input = messages - -# else: -# prompt_input = user # 原来的单轮文本 prompt - -# stop = [s.strip() for s in stop_raw.split(",") if s.strip()] or None -# samp = { -# ("max_tokens" if api_suffix == "/v1/completions" else "max_new_tokens"): int(max_new), -# "temperature": temp, -# "top_p": top_p, -# "top_k": int(top_k), -# "repetition_penalty": rep_pen, -# "presence_penalty": pres_pen, -# **({"stop": stop} if stop else {}) -# } - -# result_q = Queue() - -# def worker(): -# out = backend(prompt_input, samp, api_suffix) -# result_q.put(out) - -# thread = threading.Thread(target=worker, daemon=True) -# thread.start() - -# if api_suffix == "/v1/chat/completions": -# while True: -# if not thread.is_alive() and result_q.empty(): -# break -# try: -# result = result_q.get(timeout=0.1) -# except Empty: -# continue - -# if isinstance(result, str): -# result = {"text": result} -# elif not isinstance(result, dict) or "text" not in result: -# result = {"text": str(result)} - -# history.append({"role": "assistant", "content": result["text"]}) -# yield result["text"], None # ✅ 显示模型输出,同时更新 history -# return -# else: -# while thread.is_alive(): -# try: -# result = result_q.get(timeout=0.1) -# break -# 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["text"], log_state # ✅ 其它接口只输出文本,不更新 history -# return # ────────────────── Gradio UI ────────────────── with gr.Blocks(title="调试界面") as demo: