feat(v2): Web 界面(对话/协作过程/人工检验/指标)+ worker 优雅降级
This commit is contained in:
+14
-9
@@ -190,14 +190,19 @@ def _make_llama_generate(cfg: Dict[str, Any]) -> Callable[[str], Awaitable[str]]
|
||||
timeout_s = float(cfg.get("per_step_timeout_s", 300))
|
||||
|
||||
async def _gen(prompt: str) -> str:
|
||||
import httpx
|
||||
async with httpx.AsyncClient(timeout=timeout_s) as client:
|
||||
resp = await client.post(
|
||||
f"{base_url}/chat/completions",
|
||||
json={"model": model, "messages": [{"role": "user", "content": prompt}],
|
||||
"temperature": temperature, "max_tokens": 4096},
|
||||
)
|
||||
resp.raise_for_status()
|
||||
return resp.json()["choices"][0]["message"]["content"]
|
||||
try:
|
||||
import httpx
|
||||
async with httpx.AsyncClient(timeout=timeout_s) as client:
|
||||
resp = await client.post(
|
||||
f"{base_url}/chat/completions",
|
||||
json={"model": model, "messages": [{"role": "user", "content": prompt}],
|
||||
"temperature": temperature, "max_tokens": 4096},
|
||||
)
|
||||
resp.raise_for_status()
|
||||
return resp.json()["choices"][0]["message"]["content"]
|
||||
except Exception as e: # noqa: BLE001
|
||||
# 连不上本地模型 -> 优雅降级(不抛 500),提示用户准备运行时
|
||||
return ("(本地降级)无法连接本地 llama-server,未能生成该步骤内容。"
|
||||
f"请先运行 scripts/setup_runtime.py 并启动模型。错误:{type(e).__name__}")
|
||||
|
||||
return _gen
|
||||
|
||||
Reference in New Issue
Block a user