CodeReviewAI is a FastAPI-based web application that allows users to submit a GitHub repository URL and receive an automated code review generated by OpenAI's GPT API. The application fetches the repository content, processes it, and uses GPT to generate downsides/comments, a rating, and a conclusion about the code.
- GitHub Integration: Fetches repository contents directly from GitHub.
- Automated Code Review: Utilizes OpenAI's GPT API to analyze code and generate a detailed review.
- Candidate Levels: Adjusts the review based on the specified candidate level (Junior, Middle, or Senior).
- Rate Limiting: Implements rate limiting for both GitHub and OpenAI APIs to comply with usage policies.
- Requirements
- Installation
- Usage
- Environment Variables
- Testing
- Project Structure
- Notes
- License
- Contributing
- Python: 3.12
- OpenAI API Key: Required for accessing the OpenAI GPT API.
- GitHub Access Token: Optional, but recommended for higher rate limits when accessing the GitHub API.
- Docker
- Docker Compose
-
Clone the Repository
git clone https://github.com/your_username/your_repository.git cd your_repository -
Set Environment Variables
Create a
.envfile in the project root or export the variables directly in your shell.export OPENAI_API_KEY=your_openai_api_key export GITHUB_ACCESS_TOKEN=your_github_access_token # Optional
-
Build and Run the Docker Container
docker-compose up --build
The application will be available at
http://localhost:8000.
- Python: 3.12
- Poetry: Dependency management tool.
-
Clone the Repository
git clone https://github.com/your_username/your_repository.git cd your_repository -
Install Poetry
pip install poetry
-
Install Dependencies
poetry install
-
Set Environment Variables
export OPENAI_API_KEY=your_openai_api_key export GITHUB_ACCESS_TOKEN=your_github_access_token # Optional
-
Run the Application
poetry run start
The application will be available at
http://localhost:8000.
-
URL:
POST /review -
Description: Generates a code review for the provided GitHub repository URL.
-
Request Body:
{ "assignment_description": "string", "github_repo_url": "string", "candidate_level": "Junior" | "Middle" | "Senior" } -
Response:
{ "Found files": ["list", "of", "files"], "Downsides/Comments": "string", "Rating": "string", "Conclusion": "string" }
curl -X POST "http://localhost:8000/review" \
-H "Content-Type: application/json" \
-d '{
"assignment_description": "Implement a REST API in Python",
"github_repo_url": "https://github.com/example/repo",
"candidate_level": "Middle"
}'{
"Found files": [
"app/main.py",
"app/utils.py",
"tests/test_main.py"
],
"Downsides/Comments": "The code lacks proper error handling in the API endpoints...",
"Rating": "Rating: 75/100",
"Conclusion": "Overall, the candidate shows a good understanding of REST principles but needs to improve..."
}OPENAI_API_KEY(required): Your OpenAI API key.GITHUB_ACCESS_TOKEN(optional): Your GitHub personal access token for increased rate limits.
To run the test suite, execute:
pytestEnsure you have all development dependencies installed:
poetry install --with devapp/: Main application code.main.py: FastAPI application and endpoint definitions.github_fetcher.py: Logic for fetching repository data from GitHub.openAI_reviewer.py: Logic for generating code reviews using OpenAI's GPT API.utils.py: Utility functions.
tests/: Test suite for the application.Dockerfile: Dockerfile for containerizing the application.docker-compose.yaml: Docker Compose configuration.pyproject.toml: Project configuration for Poetry.
- The application enforces rate limits for both GitHub and OpenAI APIs to comply with their usage policies.
- Ensure that you comply with OpenAI's Usage Policies when using this application.
- The application uses asynchronous programming to improve performance when making API calls.
This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request for any bugs, improvements, or features.
This README was generated to provide comprehensive documentation for the CodeReviewAI application.