Skip to content

feat(quizzes): integrate chainlearn-ai service for quiz generation (closes #3)#20

Merged
DeFiVC merged 1 commit into
ChainLearnOfficial:mainfrom
Labi-Joy:feat/ai-quiz-generation
Jun 20, 2026
Merged

feat(quizzes): integrate chainlearn-ai service for quiz generation (closes #3)#20
DeFiVC merged 1 commit into
ChainLearnOfficial:mainfrom
Labi-Joy:feat/ai-quiz-generation

Conversation

@Labi-Joy

Copy link
Copy Markdown

closes #3

generateQuiz now calls the chainlearn-ai service (POST /generate-quiz) instead of returning the hardcoded Stellar questions. If the AI service is unreachable, it falls back to the existing placeholder set so the dashboard doesn't break on a transient outage.

what changed:

  • AI_SERVICE_URL env var added to the zod schema, defaults to http://localhost:8000
  • new src/modules/quizzes/ai-client.ts wrapping the AI service call
  • generateQuizSchema accepts optional difficulty and numQuestions (defaulted to beginner / 5 in the service)
  • placeholder generator is kept as the fallback path

testing:

  • npm run typecheck clean
  • npm run lint clean on touched files (existing warnings on other files untouched)
  • npm test passes (36/36)
  • manual: start chainlearn-ai locally, hit POST /api/quizzes/generate, confirm questions come from the AI service; stop the AI service and confirm the fallback kicks in with a warn log

closes ChainLearnOfficial#3

* add AI_SERVICE_URL env var (defaults to http://localhost:8000)
* new ai-client.ts wrapping POST /generate-quiz on the AI service
* generateQuiz calls the AI service and falls back to the existing
  placeholder questions if the service is unreachable
* generateQuizSchema now accepts optional difficulty and numQuestions

@DeFiVC DeFiVC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean implementation that fully addresses issue #3. The AI service integration with graceful fallback is well-structured.

What's Good

  • Proper separation: ai-client.ts encapsulates the AI service call cleanly, keeping quiz.service.ts focused on business logic.
  • Graceful fallback: If the AI service is unreachable, placeholder questions are returned with a warn log — the dashboard never breaks.
  • Type safety: AiDifficulty enum and GenerateQuizFromAIParams interface exported from the client for consumers.
  • Schema updates: difficulty and numQuestions added as optional fields with proper Zod validation.
  • Field mapping: AI response (prompttext, minorcorrectIndex) mapped correctly to the existing QuizQuestion format.

Minor Observations (non-blocking)

  • config.AI_SERVICE_URL uses uppercase with underscores (env var convention) — good choice over the camelCase suggested in the issue.
  • The AiQuizResponse.quiz_id field from the AI service isn't stored locally — this is fine since the API generates its own quiz ID.

CI green, no conflicts, linked issue matched. Approving.

@DeFiVC DeFiVC merged commit 778c1f5 into ChainLearnOfficial:main Jun 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace placeholder quiz generation with AI service integration

2 participants