A RESTful API for a chatbot built with FastAPI, providing structured endpoints for chat interactions and content summarization.
.
├── app/
│ ├── api/
│ │ ├── __init__.py
│ │ ├── dependencies.py
│ │ ├── errors.py
│ │ └── routes/
│ │ ├── __init__.py
│ │ ├── chat.py
│ │ └── summarizer.py
│ ├── core/
│ │ ├── __init__.py
│ │ ├── config.py
│ │ ├── logger.py
│ │ └── errors.py
│ ├── models/
│ │ ├── __init__.py
│ │ └── schema.py
│ ├── services/
│ │ ├── __init__.py
│ │ ├── chatbot.py
│ │ └── summarizer.py
│ └── __init__.py
├── logs/
├── tests/
│ ├── __init__.py
│ └── test_api.py
├── .env
├── .gitignore
├── main.py
├── requirements.txt
└── README.md
- Python 3.8+
- pip (Python package installer)
- Ollama (for LLM functionality)
Ollama is required to run the local LLM used by the chatbot and summarization features.
# Download and install Ollama from the official website
# https://ollama.com/download/windows
# After installation, pull the required model
ollama pull llama3:latest# Install Ollama using Homebrew
brew install ollama
# Or download from the official website
# https://ollama.com/download/mac
# Pull the required model
ollama pull llama3:latest# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh
# Pull the required model
ollama pull llama3:latestAfter installing, make sure the Ollama service is running:
# Start Ollama service
ollama serveThe Ollama API should be available at http://localhost:11434
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
venv\Scripts\activate
# If you're using PowerShell instead of Command Prompt
# venv\Scripts\Activate.ps1# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
source venv/bin/activateOnce your virtual environment is activated, install the required packages:
pip install -r requirements.txt
# Download SpaCy language model
python -m spacy download en_core_web_smuvicorn main:app --reloadThe API will be available at http://127.0.0.1:8000
FastAPI automatically generates API documentation using Swagger UI and ReDoc:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
Create a .env file in the root directory with the following variables:
APP_ENV=development
DEBUG=true
LOG_LEVEL=INFO
| Endpoint | Method | Description |
|---|---|---|
/api/v1/chat/message |
POST | Send a message to the chatbot |
/api/v1/health |
GET | Check API health status |
| Endpoint | Method | Description |
|---|---|---|
/api/v1/summarize/youtube |
POST | Summarize a YouTube video from its URL |
/api/v1/summarize/pdf |
POST | Summarize a PDF document from an uploaded file |
/api/v1/summarize/text |
POST | Summarize plain text content |
The chatbot uses cookies to automatically track user sessions:
- No login or user accounts required
- Sessions are created and managed automatically via browser cookies
- Cookies expire after 90 days
- When a user visits for the first time, a unique session ID is generated
- All subsequent requests from the same browser reuse the same session
- No need to manually provide or track session IDs
This approach simplifies the user experience while maintaining conversation context across visits.
The API provides content summarization with the following options:
- Short: 1-2 paragraphs
- Medium: 3-5 paragraphs
- Long: 5-7 paragraphs
- Narrative: Flowing text format
- Bullet Points: Bullet point format
- Academic: Formal, structured format
- Simplified: Easy to understand, non-technical language
Extracts and summarizes transcripts from YouTube videos, with options to include timestamped sections. Features:
- Automatic transcript extraction and translation if needed
- Video metadata extraction
- Key points identification
- Timestamped section detection
Extracts and summarizes text from PDF documents, with options to specify page ranges.
Summarizes plain text content with various style and length options.
All endpoints use form-based input with the following benefits:
- Easy to test directly in the Swagger UI
- Dropdown selectors for summary length and style
- File upload for PDF documents
- Optional fields with clear documentation
- Text processing and summarization use SpaCy for natural language processing
- YouTube transcripts are extracted using the YouTube Transcript API
- PDF text extraction uses pdfplumber
- No authentication required - completely open API
- Cookie-based session tracking
This project includes comprehensive error handling with:
- Custom exception classes
- Proper HTTP status codes
- Structured error responses
- Request validation
Logs are stored in the logs/ directory with different levels (INFO, WARNING, ERROR) and automatic rotation.