Replace GPTR content generation with custom flow#141
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Looks good. Worth considering though. View full project report here.
| logger.warning( | ||
| "[Generate Content Custom Flow] Generated content failed validation", | ||
| title_suggestion_id=self.id, | ||
| project_id=self.project.id, | ||
| generation_attempt_number=generation_attempt_number, | ||
| maximum_generation_attempts=maximum_generation_attempts, | ||
| validation_error=validation_error, | ||
| ) |
There was a problem hiding this comment.
| logger.warning( | |
| "[Generate Content Custom Flow] Generated content failed validation", | |
| title_suggestion_id=self.id, | |
| project_id=self.project.id, | |
| generation_attempt_number=generation_attempt_number, | |
| maximum_generation_attempts=maximum_generation_attempts, | |
| validation_error=validation_error, | |
| ) | |
| logger.warning( | |
| "[Generate Content Custom Flow] Generated content failed validation", | |
| title_suggestion_id=self.id, | |
| project_id=self.project_id, | |
| generation_attempt_number=generation_attempt_number, | |
| maximum_generation_attempts=maximum_generation_attempts, | |
| validation_error=validation_error, | |
| ) |
| logger.warning( | ||
| "[Generate Content Custom Flow] Generated content failed validation", | ||
| title_suggestion_id=self.id, | ||
| project_id=self.project.id, |
There was a problem hiding this comment.
self.project.id performs a database read when id is evaluated. You could take advantage of Django's caching of related fields by using self.project_id, which does not do a database read. Explained here.
Greptile SummaryReplaced GPTR-based blog generation with custom PydanticAI agent flow, adding validation and retry logic to prevent placeholder language and incomplete content. Major changes:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Start: generate_content] --> B[Create PydanticAI Agent]
B --> C[Build Generation Context]
C --> D{Attempt Loop<br/>Max 3 attempts}
D --> E[Build Prompt with<br/>Previous Error]
E --> F[Run Agent Synchronously]
F --> G[Get Generated Schema]
G --> H{Validate Content}
H -->|Empty| I[Set Error: Empty]
H -->|Has Placeholders| J[Set Error: Placeholders]
H -->|Incomplete Ending| K[Set Error: Incomplete]
H -->|Valid| L[Return Schema]
I --> M{More Attempts?}
J --> M
K --> M
M -->|Yes| D
M -->|No| N[Raise ValueError]
L --> O[Create Blog Post]
O --> P[Insert Links]
P --> Q[Process Content]
Q --> R[Update Title & Slug]
R --> S[Save Blog Post]
Last reviewed commit: 52c4968 |
|
|
||
| last_line = non_empty_lines[-1] | ||
|
|
||
| if re.search(r"[:;,\-(\[]$", last_line) or last_line.endswith("..."): |
There was a problem hiding this comment.
regex pattern escapes hyphen - unnecessarily
| if re.search(r"[:;,\-(\[]$", last_line) or last_line.endswith("..."): | |
| if re.search(r"[:;,\-\([]$", last_line) or last_line.endswith("..."): |
| generated_content = (generated_blog_post_schema.content or "").strip() | ||
| if not generated_content: | ||
| raise ValueError("Generated blog post content is empty.") |
There was a problem hiding this comment.
redundant empty content check after validation
The validate_generated_blog_post_content method already checks for empty content on line 881-882, so this check is redundant and will never be reached.
Summary
BlogPostTitleSuggestion.generate_contentwith the existing PydanticAI content generation agentNotes
uv run python -m py_compile core/models.py core/prompts.py