Documentation
¶
Overview ¶
Package qa generates multiple-choice questionnaires from parsed book sources chapter by chapter, using a caller-supplied model, and persists them as a JSON question bank.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SaveBank ¶
func SaveBank(path string, bank *QuestionBank) error
SaveBank writes a question bank to path as indented JSON.
Types ¶
type Config ¶
type Config struct {
// Sources limits generation to these source names. Empty means all.
Sources []string `json:"sources,omitempty"`
// PerChapter is the number of questions to request from each chapter.
PerChapter int `json:"per_chapter,omitempty"`
// Total, when PerChapter is zero, is distributed across the selected
// chapters.
Total int `json:"total,omitempty"`
// MaxChapters caps how many chapters are sampled (spread evenly across the
// whole book). Zero means all.
MaxChapters int `json:"max_chapters,omitempty"`
// Options is the number of answer choices per question. Default 4.
Options int `json:"options,omitempty"`
// Difficulty is the requested difficulty: easy, medium, hard, or mixed.
// Default "hard".
Difficulty string `json:"difficulty,omitempty"`
// Style customizes the flavor of questions. Defaults to deep, subjective,
// reasoning-heavy questions that avoid trivia.
Style string `json:"style,omitempty"`
// IncludeExplanation asks the model for a rationale for the correct answer.
IncludeExplanation bool `json:"include_explanation,omitempty"`
// MaxChapterChars bounds how much chapter text is sent per generation call;
// longer chapters are summarized into key points first. Default 24000.
MaxChapterChars int `json:"max_chapter_chars,omitempty"`
// Language is the language of the generated questions. Default "English".
Language string `json:"language,omitempty"`
// Seed is an optional value included in prompts to nudge variety.
Seed int64 `json:"seed,omitempty"`
}
Config controls questionnaire generation.
type Generator ¶
type Generator struct {
// Model authors the questions.
Model model.BaseModel[*schema.Message]
// Logger receives progress output. Optional.
Logger *slog.Logger
// MaxRetries is the number of corrective re-prompts on unparseable output.
// Default 2.
MaxRetries int
// System overrides the built-in system prompt.
System string
}
Generator produces question banks from parsed sources using a model.
func NewGenerator ¶
NewGenerator returns a Generator for the given model.
type Question ¶
type Question struct {
ID string `json:"id"`
Source string `json:"source"`
Chapter int `json:"chapter"`
ChapterTitle string `json:"chapter_title"`
Question string `json:"question"`
Options []string `json:"options"`
Answer int `json:"answer"` // 0-based index of the correct option
Explanation string `json:"explanation,omitempty"`
Difficulty string `json:"difficulty,omitempty"`
Tags []string `json:"tags,omitempty"`
}
Question is a single generated multiple-choice question with its ground truth.
func (Question) AnswerLabel ¶
AnswerLabel returns the label of the correct option.
type QuestionBank ¶
type QuestionBank struct {
CreatedAt time.Time `json:"created_at"`
Sources []string `json:"sources"`
Config Config `json:"config"`
Questions []Question `json:"questions"`
}
QuestionBank is a persisted set of generated questions together with the configuration and sources used to produce them.
func LoadBank ¶
func LoadBank(path string) (*QuestionBank, error)
LoadBank reads a question bank written by SaveBank.