From 63b2012e1f8800fff41d56e7fb8e18610a0b600e Mon Sep 17 00:00:00 2001 From: Josh Elster Date: Fri, 26 Jan 2024 10:55:43 -0600 Subject: [PATCH] Added optional model name parameter. Defaults to gpt-3.5-turbo-16k. Added docs' --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ action.yml | 4 ++++ src/action.js | 4 ++-- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b72d0e7 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# GitHub Pull Request Reviewer Action + +This repository contains a GitHub Action that automates the process of reviewing pull requests using OpenAI's GPT model. + +## Features + +- Fetches the diff of the changes when a pull request is opened or updated. +- Submits the diff to the GPT model for review. +- Posts the model's response as a comment on the pull request. + +## Usage + +To use this action in your GitHub workflows, add a step to your workflow file that references this repository: + +```yaml +- name: Run PR Reviewer + uses: hdvinsurance/gpt-code-review-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + openai_api_key: ${{ secrets.OPENAI_API_KEY }} +``` + +## Inputs + +The action accepts the following inputs: + +- `github_token` (**required**): The GitHub token used to post comments on the pull request. This is a required input. + +- `openai_api_key`: The OpenAI API key. This is required if the `OPENAI_API_KEY` environment variable is not set. This input is optional. + +- `pr_review_prompt_template`: Provide a PR review prompt template to optionally override the default prompt template with your own. This input is optional and defaults to an empty string. + +- `model_name`: Optional. Defaults to `gpt-3.5-turbo-16k`. + +## Outputs + +The action produces the following output: + +- `pr_review`: The PR review text. Note: this is the raw output from the GPT model and may contain newlines and other formatting characters. + +## Considerations and Limitations + +Code Reviews performed by a generative AI process may not always be correct. Exercise caution when evaluating the suggestions of the model. diff --git a/action.yml b/action.yml index b2115a7..d3ccaaa 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,10 @@ inputs: description: 'Provide a PR review prompt template to optionally override the default prompt template with your own.' required: false default: '' + model_name: + description: 'Provide a model name to optionally override the default model name with your own. Defaults to gpt-3.5-turbo-16k.' + required: false + default: 'gpt-3.5-turbo-16k' outputs: pr_review: description: 'The PR review text.' diff --git a/src/action.js b/src/action.js index 5fe9d09..077acf0 100644 --- a/src/action.js +++ b/src/action.js @@ -21,8 +21,8 @@ async function run() { try { const githubToken = core.getInput('github_token') || process.env.GITHUB_TOKEN; const openaiApiKey = core.getInput('openai_api_key') || process.env.OPENAI_API_KEY; - const prReviewPromptTemplate = core.getInput('pr_review_prompt_template'); - const prReviewModel = process.env.PR_REVIEW_MODEL || 'gpt-3.5-turbo-16k'; + const prReviewPromptTemplate = core.getInput('pr_review_prompt_template') || process.env.PR_REVIEW_PROMPT_TEMPLATE || DEFAULT_PR_REVIEW_PROMPT_TEMPLATE; + const prReviewModel = core.getInput('model_name') || process.env.PR_REVIEW_MODEL || 'gpt-3.5-turbo-16k'; // Set environment variables process.env.GH_TOKEN = githubToken;