Skip to main content

AI-powered question generation library using Langgraph flows

Project description

quiz-me

AI-powered question generation library using Langgraph flows. Generate high-quality educational questions from content or topics with optional AI supervision.

Features

  • Single & Multi-Question Generation - Generate one or multiple questions from content or topics
  • Three Question Types - Multiple choice, open-ended (with grading rubric), and fill-in-the-blank
  • Optional AI Supervision - A second model reviews and validates generated questions
  • Question Improvement - Regenerate questions based on user feedback
  • Multi-Language Support - Generate questions in any language
  • Automatic Retry Logic - Retries on validation errors or supervision rejection
  • Domain-Specific Instructions - Customize generation and supervision for your domain
  • LangChain Compatible - Works with any LangChain-compatible model

Installation

pip install quiz-me

Or with uv:

uv add quiz-me

Quick Start

from quiz_me import generate_question, SingleQuestionConfig, QuestionType

# Use any LangChain-compatible model
from langchain_openai import ChatOpenAI
model = ChatOpenAI(model="gpt-4o-mini")

# Generate a multiple choice question
config = SingleQuestionConfig(
    content="Python is a high-level programming language...",
    question_type=QuestionType.MULTIPLE_CHOICE,
    generator_model=model,
)

result = await generate_question(config)
print(result.question.statement)
print(result.question.alternatives)
print(result.question.correct_answer)

Topic-Based Generation

Generate questions from a topic using the model's knowledge (no content required):

config = SingleQuestionConfig(
    topic="The French Revolution and its impact on European politics",
    question_type=QuestionType.MULTIPLE_CHOICE,
    generator_model=model,
)

result = await generate_question(config)

Multi-Question Generation

from quiz_me import generate_questions, MultiQuestionConfig, QuestionTypeMix

config = MultiQuestionConfig(
    content="Your educational content here...",
    num_questions=5,
    question_mix=[
        QuestionTypeMix(question_type=QuestionType.MULTIPLE_CHOICE, count=3),
        QuestionTypeMix(question_type=QuestionType.OPEN_ENDED, count=2),
    ],
    generator_model=model,
    planning_instructions="Focus on key concepts and practical applications",
)

result = await generate_questions(config)
for q in result.questions:
    print(q.statement)

With Supervision

config = SingleQuestionConfig(
    content="Medical terminology content...",
    question_type=QuestionType.MULTIPLE_CHOICE,
    generator_model=model,
    supervisor_model=model,  # Can be same or different model
    supervision_enabled=True,
    generator_instructions="Focus on pharmacology terms",
    supervisor_instructions="Verify medical accuracy",
)

result = await generate_question(config)
print(f"Approved: {result.question.approved}")

Multi-Language Support

Generate questions in any language by setting the language property:

config = SingleQuestionConfig(
    content="Python é uma linguagem de programação...",
    question_type=QuestionType.MULTIPLE_CHOICE,
    generator_model=model,
    language="Portuguese",  # All content generated in Portuguese
)

result = await generate_question(config)
# Question, alternatives, and explanation will be in Portuguese

Question Improvement

Improve an existing question based on feedback using the same pattern as supervision:

from quiz_me import improve_question

# Original question that needs improvement
original = result.question

# Create config matching the original question
config = SingleQuestionConfig(
    content="Original content...",
    question_type=original.question_type,
    generator_model=model,
)

# Improve based on feedback
improved = await improve_question(
    question=original,
    feedback="The distractors are too obvious. Make them more plausible.",
    config=config,
)
print(improved.question.statement)

Retry Configuration

Control retry behavior for generation failures:

config = SingleQuestionConfig(
    content="Your content...",
    question_type=QuestionType.MULTIPLE_CHOICE,
    generator_model=model,
    max_retries=5,                    # Default is 3
    retry_on_validation_error=True,   # Retry on Pydantic validation errors
)

Documentation

See docs/ for detailed documentation.

Development

# Install with dev dependencies
uv sync --all-extras

# Run tests
uv run pytest tests/ -v

Stack

  • Langgraph - Flow orchestration
  • Pydantic - Data validation
  • ai-prompter - Jinja-based prompt templates
  • LangChain - Model abstraction

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quiz_me-0.1.1.tar.gz (144.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quiz_me-0.1.1-py3-none-any.whl (30.2 kB view details)

Uploaded Python 3

File details

Details for the file quiz_me-0.1.1.tar.gz.

File metadata

  • Download URL: quiz_me-0.1.1.tar.gz
  • Upload date:
  • Size: 144.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for quiz_me-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d59aac7770012ae2ef7f1ab6bcc3ef91c9551cb814512f324d2bed496140a4f0
MD5 00528240e5434b79be64a210b25f3707
BLAKE2b-256 24da3913fe5e53cbaed241214066b947c91b0928c5347336ddd5388c99338d54

See more details on using hashes here.

File details

Details for the file quiz_me-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: quiz_me-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for quiz_me-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8777684d1ac475b87671cee6a110b0ed63184103b548bd177532694c37665b3d
MD5 696f4b05ef62fe65610a117e9b2aee55
BLAKE2b-256 697f7e4e117352916a480cd1c5cf27abffa1a7afd3b05e15fa45fb3f548849c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page