-
Notifications
You must be signed in to change notification settings - Fork 6
Update route.ts #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update route.ts #102
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,45 @@ | |
| import { SUPPORTED_LANGUAGES } from "@/constants/languages"; | ||
|
|
||
| export const dynamic = "force-dynamic"; | ||
| // STEP 1: Generate structure | ||
| async function generateStructure(repoData: any) { | ||
|
Check failure on line 8 in src/app/api/generate/route.ts
|
||
| const prompt = ` | ||
| Create a list of README sections for this repository. | ||
| Return ONLY array of section names. | ||
|
|
||
| Repo: | ||
| ${JSON.stringify(repoData)} | ||
| `; | ||
|
|
||
| const res = await callAI(prompt); | ||
| return JSON.parse(res); // ["Introduction", "Features", ...] | ||
| } | ||
|
|
||
| // STEP 2: Generate each section | ||
| async function generateSection(section: string, repoData: any) { | ||
|
Check failure on line 22 in src/app/api/generate/route.ts
|
||
| const prompt = ` | ||
| Generate ONLY the "${section}" section of a README. | ||
|
|
||
| Repo: | ||
| ${JSON.stringify(repoData)} | ||
| `; | ||
|
|
||
| return await callAI(prompt); | ||
| } | ||
|
Comment on lines
+21
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same undefined This function also calls 🤖 Prompt for AI Agents |
||
|
|
||
| // STEP 3: Combine | ||
| export async function generateReadme(repoData: any) { | ||
|
Check failure on line 34 in src/app/api/generate/route.ts
|
||
| const sections = await generateStructure(repoData); | ||
|
|
||
| let finalReadme = ""; | ||
|
|
||
| for (const section of sections) { | ||
| const content = await generateSection(section, repoData); | ||
| finalReadme += `\n## ${section}\n${content}\n`; | ||
| } | ||
|
|
||
| return finalReadme; | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * AI README Generation Endpoint | ||
| * Optimized for data accuracy, clean prompt interpolation, and multi-language support. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callAIis undefined — code will fail at runtime.The function
callAIis called on line 17 but is never defined or imported in this file. This will throw aReferenceErrorwhen executed.Additionally,
JSON.parse(res)on line 18 lacks error handling. If the AI returns malformed JSON or includes preamble text, this will throw an unhandled exception.🐛 Proposed fix
Either define
callAIor use the existinggetGeminiModel()pattern:🤖 Prompt for AI Agents