Command line tool to code review GitHub pull requests with LLMs.
Project description
LLM Code Review
Overview
llm-code-review is a command-line tool for automated code reviews of GitHub pull requests using OpenAI's GPT models or local models via Ollama. It fetches modified files, extracts diffs, retrieves full file contents for context, and generates concise, constructive code reviews.
Features
- Supports OpenAI API (
gpt-4o-mini, etc.) - Supports local models via Ollama
- Fetches diffs from GitHub pull requests
- Retrieves full file contents for context
- Provides AI-generated feedback with before/after code snippets
- Filters reviews to focus only on Python files
Installation
Install the package from PyPI:
pip install llm-code-review
Prerequisites
Before using the tool, you must set up the required API keys as environment variables:
- GitHub Token: To authenticate API requests, create a GitHub personal access token (with
reposcope for private repositories) and set it as an environment variable. - OpenAI API Key: Obtain an API key from OpenAI and set it as an environment variable.
Setting Up Environment Variables
Add the following lines to your shell profile (e.g., ~/.bashrc, ~/.zshrc):
export GITHUB_TOKEN="your_github_token"
export OPENAI_API_KEY="your_openai_api_key"
Then, reload your shell profile:
source ~/.bashrc # or source ~/.zshrc
Alternatively, you can store them in a .env file and use python-dotenv to load them.
Usage
Basic Command
To review a GitHub pull request:
llm-code-review owner/repository PR_NUMBER
Example:
llm-code-review octocat/hello-world 42
Using a Specific Model
OpenAI
llm-code-review octocat/hello-world 42 --model openai:gpt-4o-mini
Ollama (local model)
llm-code-review octocat/Hello-World 42 --model ollama:deepseek-r1:8b
This command fetches the pull request #42 from the octocat/Hello-World repository, retrieves modified Python files, and reviews the changes using OpenAI.
How It Works
- Fetches pull request details from GitHub.
- Retrieves the full content of modified Python files.
- Sends the diff and full file content to OpenAI for review.
- Displays feedback, focusing on potential improvements and critical issues.
Notes
- Only Python (
.py) files are reviewed. - The review focuses on changes in the PR while using the full file context.
- If a file has more than three issues, only the most important one is highlighted unless critical issues are found.
License
MIT License
Contributions
Feel free to open issues or submit pull requests!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_code_review-0.1.1.tar.gz.
File metadata
- Download URL: llm_code_review-0.1.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8571f3e4703dba5af13a04aa46224fa251c2835f893ed9cc3c860a5ec0d57406
|
|
| MD5 |
d3b6221423023530b71f28bb16bbdf18
|
|
| BLAKE2b-256 |
806672977bed53cc26602a5d0c4084e932ca4c192fcfdbcfc198d7eb07a832a1
|
File details
Details for the file llm_code_review-0.1.1-py3-none-any.whl.
File metadata
- Download URL: llm_code_review-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5a6f01a5ca82038f577acfe4bbd1091b4b8a8433e90c685364d7d6867733548
|
|
| MD5 |
bf378074cf3c80c3da5c686f6374b5d7
|
|
| BLAKE2b-256 |
643fd738336fddc2d38500803939fabe19977856d372f26615b70a4e5ee1f53c
|