Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated readme and workflow. #60

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bc62780
Forced JSON mode on all GPT-4 Turbo models newer than the 1106 preview.
lukehollenback Apr 2, 2024
fcc86cd
Forced JSON mode on newer GPT-3 Turbo models as well.
lukehollenback Apr 2, 2024
1eeb9e7
Future-proofed change by added regular GPT-4 Turbo model reference.
lukehollenback Apr 2, 2024
e1acda3
Made main-luke branch run against the fork version.
lukehollenback Apr 2, 2024
9d3b7b8
Added custom prompt support.
lukehollenback Apr 2, 2024
f578b5b
Merge pull request #1 from lukehollenback/custom-prompts
lukehollenback Apr 2, 2024
a91a2d4
Merge pull request #2 from lukehollenback/issue-56_json-mode-on-more-…
lukehollenback Apr 2, 2024
63c8341
Updated action workflow configuration.
lukehollenback Apr 2, 2024
b27b814
Built new version.
lukehollenback Apr 2, 2024
b3da1bd
Updated code_review.yml.
lukehollenback Apr 2, 2024
d46d49b
Changed custom prompt slightly.
lukehollenback Apr 2, 2024
429f5bd
Switched back to old model.
lukehollenback Apr 2, 2024
93befdd
Switched back to the GPT-4 Turbo alias.
lukehollenback Apr 2, 2024
7205b32
Updated the readme to be more accurate and to discuss new features.
lukehollenback Apr 2, 2024
cb26af3
Updated workflow config to make sure all features are being tested.
lukehollenback Apr 2, 2024
cc6ffd8
Added debug output.
lukehollenback Apr 2, 2024
b9c6b53
Merge pull request #5 from lukehollenback/output-model-response
lukehollenback Apr 2, 2024
573f498
Built new version.
lukehollenback Apr 2, 2024
3a5ed26
Got rid of useless debug message.
lukehollenback Apr 2, 2024
fdb86a5
Allowed max response tokens to be configured.
lukehollenback Apr 2, 2024
e31563c
Merge pull request #6 from lukehollenback/output-model-response
lukehollenback Apr 2, 2024
c3d3226
Built new version.
lukehollenback Apr 2, 2024
74d6b7b
Merge branch 'dev' into update-readme-and-workflow
lukehollenback Apr 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/code_review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ on:
types:
- opened
- synchronize
- ready_for_review
permissions: write-all
jobs:
if: '! github.event.pull_request.draft'
code_review:
if: '! github.event.pull_request.draft'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Code Review
uses: freeedcom/ai-codereviewer@main
uses: lukehollenback/ai-codereviewer@main-luke
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_MODEL: "gpt-4-1106-preview"
exclude: "yarn.lock,dist/**"
OPENAI_API_MODEL: "gpt-3.5-turbo"
exclude: "yarn.lock, dist/**, **/*.json, **/*.md, **/*.yaml, **/*.xml"
custom_prompts: |
Do not worry about the verbosity of variable names, as long as they are somewhat descriptive.
Be sure to call out concurrency issues and potential race conditions.
Do not worry about things a static analyzer would catch in real-time during development.
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# AI Code Reviewer

AI Code Reviewer is a GitHub Action that leverages OpenAI's GPT-4 API to provide intelligent feedback and suggestions on
your pull requests. This powerful tool helps improve code quality and saves developers time by automating the code
review process.
AI Code Reviewer is a GitHub Action that leverages OpenAI's large language models to provide intelligent feedback and
suggestions on your pull requests. This powerful tool helps improve code quality and saves developers time by
automating the code review process.

## Features

- Reviews pull requests using OpenAI's GPT-4 API.
- Reviews pull requests using OpenAI's large language models.
- Provides intelligent comments and suggestions for improving your code.
- Filters out files that match specified exclude patterns.
- Supports custom prompting to hone the analysis in on specific things, and avoid others.
- Easy to set up and integrate into your GitHub workflow.

## Setup
Expand All @@ -29,35 +30,55 @@ on:
types:
- opened
- synchronize
- ready_for_review
permissions: write-all
jobs:
review:
if: '! github.event.pull_request.draft' # Only run on non-draft pull requests. Must be coupled with the ready_for_review event above.
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: AI Code Reviewer
uses: your-username/ai-code-reviewer@main
uses: your-username/ai-codereviewer@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # The GITHUB_TOKEN is there by default so you just need to keep it like it is and not necessarily need to add it as secret as it will throw an error. [More Details](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret)
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_MODEL: "gpt-4" # Optional: defaults to "gpt-4"
exclude: "**/*.json, **/*.md" # Optional: exclude patterns separated by commas
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Keep this line verbatim. GitHub sets secrets.GITHUB_TOKEN automatically, it just needs to be plumbed into the action. See https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret for more information.
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} # Your OpenAI key. Create one at https://platform.openai.com/api-keys. Set it in your repository under Settings -> Secrets and variables -> Actions -> Repository Secrets.
OPENAI_API_MODEL: "gpt-4" # Optional: The OpenAI model (https://platform.openai.com/docs/models) to use. Defaults to "gpt-4". Prefer models with JSON Mode (https://platform.openai.com/docs/guides/text-generation/json-mode) support.
exclude: "yarn.lock, dist/**, **/*.json, **/*.md, **/*.yaml, **/*.xml" # Optional: File patterns, separated by commas, to exclude from analysis.
custom_prompts: | # Optional: Custom commands to add to the prompt used to analyze code. This is a multiline string, where each line is an individual command.
Do not worry about the verbosity of variable names, as long as they are somewhat descriptive.
Be sure to call out potential null pointer exceptions.
Be sure to call out concurrency issues and potential race conditions.
```

4. Replace `your-username` with your GitHub username or organization name where the AI Code Reviewer repository is
located.
located. If using the [original](https://github.com/freeedcom/ai-codereviewer), replace it with `freeedcom`.

5. Customize the `exclude` input if you want to ignore certain file patterns from being reviewed.

6. Commit the changes to your repository, and AI Code Reviewer will start working on your future pull requests.
6. Customize or remove the `custom_prompts` input.

7. Commit the changes to your repository, and AI Code Reviewer will start working on your future pull requests.

## How It Works

The AI Code Reviewer GitHub Action retrieves the pull request diff, filters out excluded files, and sends code chunks to
the OpenAI API. It then generates review comments based on the AI's response and adds them to the pull request.

## Tips & Tricks

* The `gpt-4` model is powerful, but [relatively expensive](https://openai.com/pricing) and does not support
[JSON Mode](https://platform.openai.com/docs/guides/text-generation/json-mode) at the time of writing. Consider using
one of the turbo models — such as `gpt-4-turbo-preview` or `gpt-3.5-turbo` — to find the right balance between price
and performance.
* Use `custom_prompts` to hone the action's analysis in on things you care about, and to avoid things you don't. There
is no point, for example, in having the action repeat what your static analysis tooling does for you in real-time
while coding.
* Use an `if: '! github.event.pull_request.draft'` job conditional and `ready_for_review` trigger to control costs and
ensure that you are only running the action on pull requests that are truly ready to be reviewed.

## Contributing

Contributions are welcome! Please feel free to submit issues or pull requests to improve the AI Code Reviewer GitHub
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ inputs:
description: "OpenAI API model."
required: false
default: "gpt-4"
max_tokens:
description: "Maximum number of tokens that can be generated per analysis."
required: false
default: "700"
exclude:
description: "Glob patterns to exclude files from the diff analysis"
required: false
default: ""
custom_prompts:
description: "Custom commands to augment the agent's prompts with. Each line is an individual command."
required: false
default: ""
runs:
using: "node16"
main: "dist/index.js"
Expand Down
Loading