This project is a FastAPI-based service that leverages advanced natural language models and GitHub integration to summarize and explain code repositories. The Agent
acts as a professional code reviewer capable of retrieving, analyzing, and providing insights into GitHub repositories based on user queries.
- GitHub Integration: Interacts with GitHub repositories using access tokens for secure and efficient data retrieval.
- Customizable Queries: Accepts repository names and optional URLs for targeted analysis.
- Postgres Storage: Utilizes PostgreSQL for storing session histories and user interactions.
- Code Analysis: Reads, summarizes, and explains the purpose of code files in a repository.
- Query Flexibility: Can work with or without a specific repository URL.
- API Endpoint: Provides a
/summarize_repo
endpoint to handle user queries and return concise summaries.
- FastAPI: For building and serving the REST API.
- Phi Framework: For creating a customizable and extendable agent.
- OpenAI GPT: A GPT model (
gpt-4o-mini
) for natural language understanding and generation. - GitHub Tools: For interacting with GitHub repositories and retrieving relevant information.
- PostgreSQL: For storing session histories and agent interactions.
- dotenv: For managing environment variables.
.
├── chat_with_code.py # Contains the API and agent logic
├── requirements.txt # Python dependencies
├── .env # Environment variables (e.g., GitHub access token)
-
Clone the repository:
-
Set up a Python virtual environment:
python3 -m venv venv source venv/bin/activate # For Linux/macOS venv\Scripts\activate # For Windows
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.env
file in the project root and add the following:GITHUB_ACCESS_TOKEN="your_github_access_token"
-
Set up PostgreSQL: Ensure a PostgreSQL database is running and accessible. Update the
db_url
in thePgAgentStorage
configuration with your database credentials. you can use this command to run Pgvector in Docker from the documentation of Phidata:docker run -d \ -e POSTGRES_DB=ai \ -e POSTGRES_USER=ai \ -e POSTGRES_PASSWORD=ai \ -e PGDATA=/var/lib/postgresql/data/pgdata \ -v pgvolume:/var/lib/postgresql/data \ -p 5532:5432 \ --name pgvector \ phidata/pgvector:16
-
Run the FastAPI server:
uvicorn main:app --host 0.0.0.0 --port 8000
Example response:
{ "response": "The repository 'phidatahq/phidata' contains tools for data workflows..." }
- GitHub Access Token: Ensure a valid GitHub personal access token is set in the
.env
file for repository interactions. - Postgres Configuration: Update the
db_url
in thePgAgentStorage
initialization to connect to your database. - Agent Session Settings:
- Modify
session_id
anduser_id
logic as required. - Adjust
num_history_responses
for the number of history records stored.
- Modify
fastapi
phi
langchain_openai
uvicorn
psycopg
python-dotenv
Install all dependencies with:
pip install -r requirements.txt