← All @molecule/* packages · App templates
@molecule/api-ai-quiz-generationUtility · ai-quiz-generation · API (Node) · v1.0.1 · Apache-2.0
Generate quizzes + AI grade responses
npm install @molecule/api-ai-quiz-generation@molecule/api-ai-quiz-generation is a utility package for the API (Node) side (ai-quiz-generation).
import { generateQuiz, gradeResponses } from '@molecule/api-ai-quiz-generation'
const quiz = await generateQuiz({
source: chapterText,
questionCount: 10,
types: ['multiple_choice', 'short_answer'],
difficulty: 'medium',
})
const result = await gradeResponses({
quiz,
responses: studentAnswers,
})Works with: @molecule/api-ai, @molecule/api-bonds-default-express, @molecule/api-database, @molecule/api-i18n, @molecule/api-middleware-validation
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
@molecule/api-ai-quiz-generation — generate quizzes from source
material + auto-grade student responses via the bonded AI provider.
Extracted from ai-study-buddy flagship. For pure rule-based grading
(multiple-choice → exact match), use @molecule/api-utilities-quiz-grading.
This package adds AI-assisted generation + free-response grading.
import { generateQuiz, gradeResponses } from '@molecule/api-ai-quiz-generation'
const quiz = await generateQuiz({
source: chapterText,
questionCount: 10,
types: ['multiple_choice', 'short_answer'],
difficulty: 'medium',
})
const result = await gradeResponses({
quiz,
responses: studentAnswers,
})
utility
npm install @molecule/api-ai-quiz-generation @molecule/api-ai @molecule/api-bonds-default-express @molecule/api-database @molecule/api-i18n @molecule/api-middleware-validation
GradedResponseAI-graded result for a single student response, including correctness, score, and feedback.
interface GradedResponse {
question_id: string
submitted: string
correct: boolean
score: number
feedback?: string
}
GradeResultAggregated grading outcome for a full set of student responses.
interface GradeResult {
responses: GradedResponse[]
total: number
earned: number
percentage: number
}
QuestionA single quiz question with prompt, answer, and optional metadata.
interface Question {
id: string
type: QuestionType
prompt: string
/** For multiple_choice / true_false. */
options?: string[]
/** The correct answer (or one of the accepted forms). */
answer: string
/** Why this is the right answer — surfaced after submission. */
explanation?: string
difficulty?: Difficulty
}
QuizA generated quiz containing an ordered list of questions and an optional source summary.
interface Quiz {
questions: Question[]
source_summary?: string
}
DifficultyRelative difficulty level for a question or generated quiz.
type Difficulty = 'easy' | 'medium' | 'hard'
QuestionTypeUnion of supported quiz question formats.
type QuestionType = 'multiple_choice' | 'true_false' | 'short_answer' | 'fill_in_the_blank'
generateQuiz(opts)Generates a quiz from source material using the bonded AI provider, returning structured questions.
function generateQuiz(opts: {
source: string
questionCount?: number
types?: QuestionType[]
difficulty?: Difficulty
model?: string
}): Promise<Quiz>
gradeResponses(opts)Grades a set of student responses against the quiz answer key using the bonded AI provider.
function gradeResponses(opts: {
quiz: Quiz
responses: Array<{ question_id: string; submitted: string }>
model?: string
}): Promise<GradeResult>
Peer dependencies:
@molecule/api-bonds-default-express ^1.0.1@molecule/api-database ^1.0.1@molecule/api-i18n ^1.0.1@molecule/api-middleware-validation ^1.0.1@molecule/api-ai ^1.0.1@molecule/api-ai@molecule/api-bonds-default-express@molecule/api-database@molecule/api-i18n@molecule/api-middleware-validationRequires a bonded ai chat provider (@molecule/api-ai) — both functions
throw if none is bonded.
Failure shapes (no rejection): malformed model output — or a provider API
failure, which arrives as an in-band error event this package does not
treat as fatal — makes generateQuiz() resolve { questions: [] } and
gradeResponses() resolve { responses: [], earned: 0, percentage: 0 }.
An empty questions array means the model output failed to parse, not
"the source had nothing to ask" — surface a retry instead of rendering an
empty quiz, and don't record a 0% grade whose responses array is empty.
total/percentage are computed from the quiz's own question count, so a
partially-parsed grading under-reports earned, never over-reports.