Skip to content

Add Gemini-backed /api/generate-cards endpoint and update AI panel to use it#10

Open
CoderBrianNguyen wants to merge 2 commits intoGeminiAPITestBranchfrom
codex/add-gemini-api-integration-for-flashcards-6unjk4
Open

Add Gemini-backed /api/generate-cards endpoint and update AI panel to use it#10
CoderBrianNguyen wants to merge 2 commits intoGeminiAPITestBranchfrom
codex/add-gemini-api-integration-for-flashcards-6unjk4

Conversation

@CoderBrianNguyen
Copy link
Copy Markdown
Owner

Motivation

  • Provide a server-side endpoint to generate flashcards from notes using Gemini models with robust parsing and retries.
  • Improve reliability by falling back to local mock card generation when the Gemini API is unavailable or returns invalid responses.
  • Surface clearer fallback/status messages to the client so users know when mock data is being shown.

Description

  • Add app/api/generate-cards/route.ts which implements Gemini generation including prompt construction, multi-model attempts (gemini-2.5-flash, gemini-2.0-flash, gemini-1.5-flash), retry/backoff logic, response wrapper parsing, JSON extraction, and conversion into Flashcard objects, plus a GeminiRequestError type and fallback to mockGenerateCards.
  • Implement robust JSON extraction with parseGeminiCards that can handle wrapped responses and malformed content and normalize difficulty values.
  • Add retry delay calculation via getRetryDelayMs, request throttling handling (429/503), and capped exponential backoff with sleep.
  • Update components/AIGenerationPanel.tsx to POST to POST /api/generate-cards instead of the old /api/gemini route and display server-provided fallback message when present.

Testing

  • No automated tests were run as part of this change.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant