fix(llm_bridge): 网关 200 但无 choices 的响应自动重试,避免 KeyError 打崩角色agent
llmage 网关偶发返回 200 但内容无 choices(错误JSON),llm_call_msgs_native 的 data[choices] 直接 KeyError,导致 role_agent 任务失败并报人工介入。_post_chat_completion 对无 choices 的 200 响应视为可重试异常,重试后仍失败则 raise 带网关原始内容的 ValueError。
This commit is contained in:
parent
8cfae215e0
commit
7ed0ed9b80
@ -110,7 +110,17 @@ async def _post_chat_completion(url: str, headers: dict, payload: dict) -> dict:
|
||||
await asyncio.sleep(2 * (attempt + 1))
|
||||
continue
|
||||
raise err
|
||||
return await resp.json()
|
||||
data = await resp.json()
|
||||
# 网关偶发返回 200 但内容无 choices(错误 JSON),视为可重试的瞬时异常;
|
||||
# 不处理会导致上层 llm_call_msgs_native 的 data["choices"] 抛 KeyError。
|
||||
if not isinstance(data, dict) or "choices" not in data:
|
||||
err = ValueError("LLM 响应缺 choices: %s" % json.dumps(data, ensure_ascii=False)[:300])
|
||||
if attempt < _LLM_MAX_ATTEMPTS - 1:
|
||||
last_exc = err
|
||||
await asyncio.sleep(2 * (attempt + 1))
|
||||
continue
|
||||
raise err
|
||||
return data
|
||||
except (asyncio.TimeoutError, aiohttp.ClientError) as e:
|
||||
last_exc = e
|
||||
if attempt < _LLM_MAX_ATTEMPTS - 1:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user