debug: improve AI analysis JSON parsing error logging
Show more context in error messages to diagnose parse failures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
72efed481f
commit
1bac0b90a6
|
|
@ -254,7 +254,9 @@ async def _call_openai(system: str, user_prompt: str) -> str:
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
result = response.json()
|
result = response.json()
|
||||||
return result["choices"][0]["message"]["content"]
|
content = result["choices"][0]["message"]["content"]
|
||||||
|
logger.info(f"OpenAI API response ({len(content)} chars): {content[:300]}")
|
||||||
|
return content
|
||||||
|
|
||||||
|
|
||||||
def _parse_clips(content: str, video_duration: float) -> list[dict]:
|
def _parse_clips(content: str, video_duration: float) -> list[dict]:
|
||||||
|
|
@ -268,17 +270,21 @@ def _parse_clips(content: str, video_duration: float) -> list[dict]:
|
||||||
logger.error(f"No JSON found in LLM response: {content[:200]}")
|
logger.error(f"No JSON found in LLM response: {content[:200]}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
raw_json = json_match.group()
|
||||||
|
logger.debug(f"Extracted JSON ({len(raw_json)} chars): {raw_json[:500]}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = json.loads(json_match.group())
|
data = json.loads(raw_json)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError as e:
|
||||||
|
logger.warning(f"JSON parse attempt 1 failed: {e}")
|
||||||
# Try to fix common JSON issues
|
# Try to fix common JSON issues
|
||||||
fixed = json_match.group()
|
fixed = raw_json
|
||||||
fixed = re.sub(r",\s*}", "}", fixed)
|
fixed = re.sub(r",\s*}", "}", fixed)
|
||||||
fixed = re.sub(r",\s*]", "]", fixed)
|
fixed = re.sub(r",\s*]", "]", fixed)
|
||||||
try:
|
try:
|
||||||
data = json.loads(fixed)
|
data = json.loads(fixed)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError as e2:
|
||||||
logger.error(f"Failed to parse LLM JSON: {content[:200]}")
|
logger.error(f"Failed to parse LLM JSON ({e2}): {content[:500]}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
raw_clips = data.get("clips", [])
|
raw_clips = data.get("clips", [])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue