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