From a45b4503eb083ad16ee346e0a3e2c399d3d83fd4 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 1 Aug 2026 17:32:23 +0800 Subject: [PATCH] debug: add _call_llm logging for api_key/base/model tracing --- wwwroot/api/cockpit_chat.dspy | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wwwroot/api/cockpit_chat.dspy b/wwwroot/api/cockpit_chat.dspy index 637ebeb..69f6033 100644 --- a/wwwroot/api/cockpit_chat.dspy +++ b/wwwroot/api/cockpit_chat.dspy @@ -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