Simplified the logic for log streaming by consolidating into a single async generator (`log_stream`). Removed redundant tasks and streamlined report generation to improve code readability and maintainability. |
||
---|---|---|
src | ||
Dockerfile | ||
README.md | ||
requirements.txt |
README for FastAPI-Based Report GPT Generation Service
Overview
This repository contains the implementation of a FastAPI-based service designed to generate research reports. The service processes user-provided queries and report types, performing advanced research powered by GPTResearcher
and responding with comprehensive results, including details, cost, context, images, and other associated metadata.
Features
- RESTful API to handle user queries and generate reports.
- Streaming responses to deliver research output in chunks.
- Secure API access with API Key authentication.
- Completely containerized setup with Docker.
- Built with modular design for easier scalability and maintenance.
System Architecture
Core Components
-
FastAPI App (
main.py
):- Hosts the API endpoints.
- Handles API Key authentication for secure use.
- Accepts user inputs (query and report type) and generates a chunked streaming response.
-
Research Logic (
deepresearch.py
):- Encapsulates research and report generation.
- Utilizes
GPTResearcher
to conduct research, generate reports, and retrieve extended data like images, contexts, or costs.
-
Docker Integration:
- The application is containerized with a well-defined
Dockerfile
. - Includes dependency installation, environment setup, and FastAPI server configuration for rapid deployment.
- The application is containerized with a well-defined
Prerequisites
Before running the application, ensure the following are installed on your system:
- Docker: Version 24.0+
- Python: Version 3.13+
- pip: Pre-installed Python package manager.
Running the Application Locally
Cloning the Repository
Clone the repository to a directory of your choice:
git clone https://git.kvant.cloud/phoenix/gpt-researcher.git
cd gpt-researcher
Environment Variable Configuration
Create a .env
file in the root of the project and define:
API_KEY=your_api_key # Replace "your_api_key" with your desired key
OPENAI_BASE_URL=
OPENAI_API_KEY=
EMBEDDING=
FAST_LLM=
SMART_LLM=
STRATEGIC_LLM=
OPENAI_API_VERSION=
SERPER_API_KEY=
RETRIEVER=serper
Installing Dependencies
Install the required Python modules based on the generated requirements.txt
.
pip install --no-cache-dir -r requirements.txt
Running the App
Run the FastAPI app locally:
uvicorn main:app --host 0.0.0.0 --port 8000
After running, your app will be available at http://127.0.0.1:8000
.
Using Docker for Deployment
Building the Docker Image
Build the Docker image using the Dockerfile provided:
docker build -t fastapi-report-service .
Running the Docker Container
Spin up a container and map FastAPI's default port, 8000
:
docker run --env-file .env -p 8000:8000 fastapi-report-service
API Usage
1. /get_report
- Method:
POST
- Description: Generates a report based on user input.
- Headers:
X-API-KEY
: API Key for authentication.
- Request Body (
JSON
):
{
"query": "Research on AI in healthcare",
"report_type": "research_report|resource_report|outline_report|custom_report|detailed_report|subtopic_report|deep"
}
- Streaming Response: Research and report are provided in chunks.
Code Structure
├── Dockerfile # Configuration for Dockerizing the application
├── requirements.txt # Python dependencies list
├── main.py # FastAPI server entry point
├── deepresearch.py # Research-related logic and GPTResearcher integration
└── src/ # Other project files and assets
Features Under the Hood
-
Authentication:
- An API key mechanism ensures that only authorized users can access endpoints.
-
Streaming Response:
- Large research reports are sent incrementally using
StreamingResponse
for better experience and efficiency.
- Large research reports are sent incrementally using
-
Modular Research Logic:
- Research and generation tasks are handled by a dedicated class (
ReportGenerator
), making the application extensible.
- Research and generation tasks are handled by a dedicated class (
Future Enhancements
-
Asynchronous Enhancements:
- Improve async handling for long-running queries.
-
Database Integration:
- Save request history for auditing and reference purposes.
-
Web Interface:
- A user-friendly web application for interacting with the API.
Contributing
Contributions are welcome! Feel free to fork the repository, make updates, and submit a pull request.