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