Test your knowledge with trivia questions generated from any article-based website! TriviaToday supports Wikipedia, news sites, blogs, documentation, and more. Built using the Atomic Agents framework and creates an interactive quiz experience with 5 questions of increasing difficulty.
- Interactive Quiz Game: Simple A-D answer format with immediate feedback
- Universal Content Extraction: Works with Wikipedia, news sites, blogs, documentation, forums, and more
- Smart Content Processing: Uses Trafilatura library for intelligent content extraction
- Increasing Difficulty: Generates questions from Easy to Master level
- Rich Console Interface: Beautiful terminal UI with progress indicators
- Score Tracking: See your performance at the end of each quiz
- Play Again: Easy restart for multiple rounds
- Modular Design: Built with atomic agents for extensibility
- Type Safety: Full type hints and Pydantic validation
- Clone the repository:
git clone <your-repo-url>
cd triviatoday- Install dependencies using uv (recommended) or pip:
# Using uv (recommended)
uv sync
# Or using pip
pip install -e .- Set up your configuration:
# Copy the example configuration file
cp env.example .env
# Edit the .env file with your settings
# At minimum, you need to set your Anthropic API keyRequired Configuration:
ANTHROPIC_API_KEY: Your Anthropic API key for Claude access
Optional Configuration:
MODEL_NAME: AI model to use (default: claude-3-5-sonnet-20240620)MODEL_MAX_TOKENS: Maximum tokens to generate (default: 4000)MODEL_TEMPERATURE: Response temperature 0.0-1.0 (default: 0.7)MODEL_TOP_P: Top-p sampling parameter 0.0-1.0 (default: 0.9)NUM_QUESTIONS: Number of trivia questions to generate (default: 5)
TriviaToday uses Pydantic Settings for centralized configuration management. This provides:
- Type-safe configuration with automatic validation
- Environment variable support with
.envfile loading (UTF-8 encoded) - Default values for all optional settings
- Centralized configuration instead of scattered
os.getenv()calls - Case-insensitive environment variable matching
- Proper error handling for missing required configuration
ModelConfig: AI model settings (name, tokens, temperature, etc.) withMODEL_prefixAPIConfig: External API keys and credentials (no prefix for API keys)AppConfig: Application-specific settings (content length, question count) with no prefix
MODEL_*: Model configuration (e.g.,MODEL_NAME,MODEL_MAX_TOKENS)- No prefix: API keys and application settings (e.g.,
ANTHROPIC_API_KEY,MAX_CONTENT_LENGTH,NUM_QUESTIONS)
Run the interactive quiz game:
python -m triviatoday
# or
uv run python -m src.triviatoday.appThe app will:
- Ask for an article URL (Wikipedia, news, blog, documentation, etc.)
- Show a loading timer while generating questions
- Present questions one by one with A-D answer options
- Show your score and ask if you want to play again
Run the FastAPI server for API access:
# Start the server
uv run triviatoday-server
# or
uv run python -m src.triviatoday.api_serverThe server will start on http://localhost:8000 with:
- API Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
- Generate Trivia: POST http://localhost:8000/generate-trivia
# Generate trivia from an article
curl -X POST "http://localhost:8000/generate-trivia" \
-H "Content-Type: application/json" \
-d '{"article_url": "https://en.wikipedia.org/wiki/Chess"}'from triviatoday.agent import create_trivia_agent
from triviatoday.schemas import UniversalTriviaInputSchema
import anthropic
import instructor
import os
# Set up the agent (uses universal scraper by default)
client = instructor.from_anthropic(anthropic.Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY")))
agent = create_trivia_agent(client)
# Alternative: Use Wikipedia-specific agent for Wikipedia-only use cases
# from triviatoday.agent import create_wikipedia_trivia_agent
# agent = create_wikipedia_trivia_agent(client)
# Generate questions from any article
input_data = UniversalTriviaInputSchema(
article_url="https://en.wikipedia.org/wiki/Artificial_intelligence"
)
result = agent.run(input_data)
print(f"Generated {len(result.questions)} questions about {result.title}")
print(f"Author: {result.author}")
print(f"Date: {result.date}")TriviaToday is built using the Atomic Agents framework and consists of:
- UniversalScraper: Tool for extracting content from any article-based website using Trafilatura
- WikipediaScraper: Specialized tool for Wikipedia content extraction (legacy support)
- UniversalTriviaAgent: Main agent that orchestrates scraping and question generation
- Structured Schemas: Pydantic models for type-safe input/output
- Rich CLI: Beautiful command-line interface
src/triviatoday/
โโโ agent.py # Main trivia agents
โโโ app.py # CLI application
โโโ schemas.py # Input/output schemas
โโโ tools/
โโโ __init__.py
โโโ base_scraper.py # Shared schemas and utilities
โโโ universal_scraper.py # Universal content extraction
โโโ wikipedia_scraper.py # Wikipedia-specific extraction
TriviaToday works with any article-based website, including:
- Wikipedia (all languages)
- News sites (BBC, CNN, Reuters, The Guardian, etc.)
- Blogs (Medium, WordPress, custom blogs)
- Documentation (MDN Web Docs, GitHub docs, etc.)
- Educational sites (Khan Academy, university sites)
- Forums (Reddit, Stack Overflow, etc.)
- Any site with readable article content
๐ง TriviaToday - Universal Article Trivia Quiz
Test your knowledge with trivia questions from any article-based website!
Enter an article URL: https://en.wikipedia.org/wiki/Chess
โ
Successfully generated 5 trivia questions!
๐ Article: Chess
๐ URL: https://en.wikipedia.org/wiki/Chess
๐ Summary: Chess is a strategic board game played between two players...
๐ค Author: Not available
๐
Date: Not available
๐ฏ Generated Trivia Questions:
โโ Difficulty: Easy โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Question 1: How many players participate in a โ
โ standard game of chess? โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
A. 1
B. 2 โ
C. 3
D. 4
โ Correct Answer: 2
Explanation: Chess is played between exactly two players...
The project uses modern Python practices:
- Python 3.13+: Latest Python features
- Type Hints: Full type safety
- Pydantic: Data validation
- Rich: Beautiful console output
- Atomic Agents: Modular AI agent framework
- Trafilatura: Universal content extraction
- Install development dependencies:
uv sync --dev- Run tests (if available):
uv run pytest- Format code:
uv run ruff format- Lint code:
uv run ruff check- API Key Error: Make sure
ANTHROPIC_API_KEYis set in your environment or.envfile - Invalid URL: Ensure you're providing a valid article URL (Wikipedia, news sites, blogs, etc.)
- Network Issues: Check your internet connection and try again
- Rate Limits: If you hit API rate limits, wait a moment before trying again
- Content Extraction Issues: Some sites may block automated access or have complex layouts
Error fetching article page: The URL might be invalid or the page might not existNo content could be extracted: The page might not contain readable article contentError initializing Anthropic client: Check your API key configurationInput data is required: This shouldn't happen in normal usage
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if needed
- Submit a pull request
This project is licensed under the GPL-3.0-or-later License.
- Built with Atomic Agents
- Powered by Anthropic's Claude
- Content extraction powered by Trafilatura
- Inspired by the wealth of knowledge available on the web