fix(translate): add detailed LLM response logging for empty content debug
Preview + executor now log finish_reason, message_keys, and raw response structure when LLM returns empty content, enabling diagnosis of DeepSeek API issues (empty content with finish_reason=length)
This commit is contained in:
@@ -971,10 +971,15 @@ class TranslationExecutor:
|
||||
|
||||
choices = data.get("choices", [])
|
||||
if not choices:
|
||||
logger.explore("LLM returned no choices", extra={"src": "executor", "response_keys": list(data.keys()), "response_preview": str(data)[:2000]})
|
||||
raise ValueError("LLM returned no choices")
|
||||
|
||||
content = choices[0].get("message", {}).get("content", "")
|
||||
finish_reason = choices[0].get("finish_reason", "none")
|
||||
msg = choices[0].get("message", {})
|
||||
content = msg.get("content", "")
|
||||
logger.reason(f"LLM response finish_reason={finish_reason} content_len={len(content)} msg_keys={list(msg.keys())}")
|
||||
if not content:
|
||||
logger.explore("LLM returned empty content", extra={"src": "executor", "finish_reason": finish_reason, "msg_keys": list(msg.keys()), "response_preview": str(data)[:2000]})
|
||||
raise ValueError("LLM returned empty content")
|
||||
|
||||
return content
|
||||
|
||||
@@ -977,10 +977,15 @@ class TranslationPreview:
|
||||
|
||||
choices = data.get("choices", [])
|
||||
if not choices:
|
||||
logger.explore("LLM returned no choices", extra={"src": "preview", "response_keys": list(data.keys()), "response_preview": str(data)[:2000]})
|
||||
raise ValueError("LLM returned no choices")
|
||||
|
||||
content = choices[0].get("message", {}).get("content", "")
|
||||
finish_reason = choices[0].get("finish_reason", "none")
|
||||
msg = choices[0].get("message", {})
|
||||
content = msg.get("content", "")
|
||||
logger.reason(f"LLM response finish_reason={finish_reason} content_len={len(content)} msg_keys={list(msg.keys())}")
|
||||
if not content:
|
||||
logger.explore("LLM returned empty content", extra={"src": "preview", "finish_reason": finish_reason, "msg_keys": list(msg.keys()), "response_preview": str(data)[:2000]})
|
||||
raise ValueError("LLM returned empty content")
|
||||
|
||||
return content
|
||||
|
||||
Reference in New Issue
Block a user