debug: add _call_llm logging for api_key/base/model tracing

This commit is contained in:
yumoqing 2026-08-01 17:32:23 +08:00
parent ac2ff432ed
commit a45b4503eb

View File

@ -145,6 +145,7 @@ async def _call_llm(model_info, messages, temperature):
api_base = model_info.api_base.rstrip('/')
api_key = model_info.api_key or ''
model_id = model_info.model_id
debug(f'_call_llm: base={api_base} model={model_id} key_len={len(api_key)} key_prefix={api_key[:10]}')
headers = {
"Authorization": f"Bearer {api_key}",
@ -158,13 +159,16 @@ async def _call_llm(model_info, messages, temperature):
timeout = aiohttp.ClientTimeout(total=120)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.post(f"{api_base}/chat/completions", headers=headers, json=payload) as resp:
url = f"{api_base}/chat/completions"
debug(f'_call_llm: POST {url}')
async with session.post(url, headers=headers, json=payload) as resp:
if resp.status != 200:
text = await resp.text()
debug(f'_call_llm: FAIL status={resp.status} body={text[:200]}')
raise ValueError(f"LLM API error {resp.status}: {text[:300]}")
data = await resp.json()
content = data["choices"][0]["message"]["content"]
# Truncate overly long responses
debug(f'_call_llm: OK reply_len={len(content)}')
if len(content) > 8000:
content = content[:8000] + "\n\n...(内容过长已截断)"
return content