more reliability in processing malformed content, but exeption introduced
This commit is contained in:
@@ -331,6 +331,13 @@ class JournalPromptGenerator:
|
||||
}
|
||||
new_prompts.append(prompt_obj)
|
||||
|
||||
# If no prompts were found in the JSON, provide debug info
|
||||
if not new_prompts:
|
||||
self.console.print("\n[yellow]Warning: JSON parsed successfully but no prompts found with expected keys[/yellow]")
|
||||
self.console.print(f"[yellow]Expected keys: newprompt0 to newprompt{self.settings['num_prompts']-1}[/yellow]")
|
||||
self.console.print(f"[yellow]Keys found in JSON: {list(data.keys())}[/yellow]")
|
||||
self.console.print(f"[yellow]Full JSON data: {json.dumps(data, indent=2)}[/yellow]")
|
||||
|
||||
return new_prompts
|
||||
|
||||
except json.JSONDecodeError:
|
||||
@@ -352,11 +359,43 @@ class JournalPromptGenerator:
|
||||
}
|
||||
new_prompts.append(prompt_obj)
|
||||
|
||||
# If still no prompts could be parsed, dump the full payload for debugging
|
||||
# If still no prompts could be parsed, provide detailed debug information
|
||||
if not new_prompts:
|
||||
self.console.print("[red]Error: Could not extract any prompts from AI response[/red]")
|
||||
self.console.print("[red]Full payload dump for debugging:[/red]")
|
||||
self.console.print("\n[red]ERROR: Could not extract any prompts from AI response[/red]")
|
||||
self.console.print("[red]="*60 + "[/red]")
|
||||
self.console.print("[bold red]DEBUG INFORMATION:[/bold red]")
|
||||
self.console.print("[red]="*60 + "[/red]")
|
||||
|
||||
# Show response metadata
|
||||
self.console.print(f"[yellow]Response length: {len(response_content)} characters[/yellow]")
|
||||
self.console.print(f"[yellow]Expected number of prompts: {self.settings['num_prompts']}[/yellow]")
|
||||
|
||||
# Show first 500 characters of response
|
||||
preview = response_content[:500]
|
||||
if len(response_content) > 500:
|
||||
preview += "..."
|
||||
self.console.print(f"[yellow]Response preview (first 500 chars):[/yellow]")
|
||||
self.console.print(f"[yellow]{preview}[/yellow]")
|
||||
|
||||
# Show cleaned content analysis
|
||||
self.console.print(f"[yellow]Cleaned content length: {len(cleaned_content)} characters[/yellow]")
|
||||
self.console.print(f"[yellow]Cleaned content preview: {cleaned_content[:200]}...[/yellow]")
|
||||
|
||||
# Show line analysis
|
||||
self.console.print(f"[yellow]Number of lines in response: {len(lines)}[/yellow]")
|
||||
self.console.print(f"[yellow]First 5 lines:[/yellow]")
|
||||
for i, line in enumerate(lines[:5]):
|
||||
self.console.print(f"[yellow] Line {i+1}: {line[:100]}{'...' if len(line) > 100 else ''}[/yellow]")
|
||||
|
||||
# Show JSON parsing attempt details
|
||||
self.console.print(f"[yellow]JSON parsing attempted on cleaned content:[/yellow]")
|
||||
self.console.print(f"[yellow] Cleaned content starts with: {cleaned_content[:50]}...[/yellow]")
|
||||
|
||||
# Show full payload for debugging
|
||||
self.console.print("\n[bold red]FULL PAYLOAD DUMP:[/bold red]")
|
||||
self.console.print("[red]" + "="*60 + "[/red]")
|
||||
self.console.print(f"[red]{response_content}[/red]")
|
||||
self.console.print("[red]" + "="*60 + "[/red]")
|
||||
|
||||
return new_prompts
|
||||
|
||||
@@ -432,9 +471,8 @@ class JournalPromptGenerator:
|
||||
|
||||
except Exception as e:
|
||||
self.console.print(f"[red]Error calling AI API: {e}[/red]")
|
||||
self.console.print(f"[yellow]Full response content for debugging:[/yellow]")
|
||||
self.console.print(f"[yellow]{response_content}[/yellow]")
|
||||
|
||||
self.console.print(f"[yellow]Full prompt sent to API (first 500 chars):[/yellow]")
|
||||
self.console.print(f"[yellow]{full_prompt[:500]}...[/yellow]")
|
||||
return []
|
||||
|
||||
# Parse the response
|
||||
|
||||
Reference in New Issue
Block a user