An AI-powered system for generating research reports using FastAPI, LangChain, and Perplexity AI.
- Automated research on any topic using Perplexity AI
- Multiple report templates (standard, academic, business)
- Rich text formatting with tables and images
- Citation tracking and credibility scoring
- Asynchronous report generation
- Progress tracking and status updates
- Microsoft Word (DOCX) output
The AI Document Generator uses a multi-agent system architecture for generating comprehensive research reports. Each agent specializes in a specific task and communicates with the others through a well-defined flow.
-
Orchestrator Agent
- Central coordinator that manages the entire document generation workflow
- Initiates and sequences the actions of other specialized agents
- Maintains task status and handles the overall process from start to completion
-
Web Research Agent
- Conducts research on given topics using the Perplexity API
- Processes queries and evaluates the credibility of sources
- Formats research results into structured data for other agents to use
-
Document Structure Agent
- Organizes research into a comprehensive, detailed document structure
- Creates section hierarchies with multiple subsections
- Uses the OpenAI API (specifically o3-mini model) for structure generation
-
Content Writer Agent
- Generates detailed content for each section based on the document structure
- Converts markdown to DOCX format for the final document
- Requests images based on section content and integrates them into the document
-
Image Generation Agent
- Specialized agent responsible for generating high-quality images
- Handles different image styles (abstract, realistic, diagram, infographic, artistic)
- Processes both single image requests and batch generation
- Interfaces with the DALL-E API for image creation
-
Perplexity API
- Used by the Web Research Agent for up-to-date information
- Provides source citations and evaluation of source credibility
-
OpenAI GPT API
- Used by all agents with different models for specific needs
- Base agent defaults to "gpt-4o-mini" with temperature 0.3
- Document Structure Agent uses "o3-mini" for extensive structure generation
-
DALL-E API
- Used by the Image Generation Agent for creating visual elements
- Generates images based on detailed descriptions with customizable styles
- The Orchestrator Agent creates a research plan and delegates tasks
- The Web Research Agent gathers and analyzes information
- The Document Structure Agent organizes research into a coherent structure
- The Content Writer Agent generates detailed content and requests images
- The Image Generation Agent creates visual elements for the document
- The final document flows back to the Orchestrator for delivery via the API
- Python 3.10 or higher
- Docker (optional)
- API Keys:
- Perplexity AI API key
- OpenAI API key
-
Clone the repository:
git clone https://github.com/yourusername/ai-doc-generator.git cd ai-doc-generator
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # Linux/macOS # or venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Create
.env.local
file:cp .env.example .env.local # Edit .env.local with your API keys
-
Run the application:
python main.py
The application uses SQLite by default, storing data in aidocgen.db
in the project root directory. No additional database setup is required for local development.
- Build and run with Docker Compose:
docker-compose up --build
The Docker setup uses SQLite as well, with the database file stored in the project root directory and mapped as a volume. This ensures your database persists between container restarts.
The API will be available at http://localhost:8000
-
POST /generate-report
{ "topic": "Your research topic", "template_type": "standard", "max_pages": 10, "include_images": true }
-
GET /report-status/{task_id}
- Check the status of a report generation task
-
GET /download-report/{task_id}
- Download the generated report (DOCX format)
-
GET /health
- Health check endpoint
import requests
# Start report generation
response = requests.post(
"http://localhost:8000/generate-report",
json={
"topic": "Sustainable Finance in Indonesia",
"template_type": "business",
"max_pages": 15,
"include_images": True
}
)
task_id = response.json()["task_id"]
# Check status
status = requests.get(f"http://localhost:8000/report-status/{task_id}")
# Download report when completed
if status.json()["status"] == "completed":
report = requests.get(f"http://localhost:8000/download-report/{task_id}")
Run tests with pytest:
pytest
The application includes GitHub Actions workflows for CI/CD:
- Automated testing on pull requests
- Docker image building and pushing to Docker Hub
- Deployment to your chosen cloud platform
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a pull request
This project is licensed under the MIT License - see the LICENSE file for details.