diff --git a/backend/src/plugins/translate/executor.py b/backend/src/plugins/translate/executor.py index 4cd434dc..252ca9be 100644 --- a/backend/src/plugins/translate/executor.py +++ b/backend/src/plugins/translate/executor.py @@ -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 diff --git a/backend/src/plugins/translate/preview.py b/backend/src/plugins/translate/preview.py index 21205ddf..1ecc37e7 100644 --- a/backend/src/plugins/translate/preview.py +++ b/backend/src/plugins/translate/preview.py @@ -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