Skip to content

Commit

Permalink
Update OpenAI API key and model in llm-code-review-action
Browse files Browse the repository at this point in the history
  • Loading branch information
koganei committed Mar 8, 2024
1 parent a79475f commit 9e08469
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# llm-code-review-action
A container GitHub Action to review a pull request by HuggingFace's LLM Model.
A container GitHub Action to review a pull request by OpenAI's LLM Model.

If the size of a pull request is over the maximum chunk size of the HuggingFace API, the Action will split the pull request into multiple chunks and generate review comments for each chunk.
And then the Action summarizes the review comments and posts a review comment to the pull request.

## Pre-requisites
We have to set a GitHub Actions secret `HUGGING_FACE_API_KEY` to use the HuggingFace API so that we securely pass it to the Action.
We have to set a GitHub Actions secret `OPENAI_API_KEY` to use the OpenAI API so that we securely pass it to the Action.

## Inputs

- `apiKey`: The HuggingFace API key to access the API.
- `apiKey`: The OpenAI API key to access the API.
- `githubToken`: The GitHub token to access the GitHub API.
- `githubRepository`: The GitHub repository to post a review comment.
- `githubPullRequestNumber`: The GitHub pull request number to post a review comment.
Expand All @@ -23,7 +23,7 @@ We have to set a GitHub Actions secret `HUGGING_FACE_API_KEY` to use the Hugging
- `maxNewTokens`: The max_tokens to generate a review comment.
- `logLevel`: The log level to print logs.

As you might know, a model of HuggingFace has limitation of the maximum number of input tokens.
As you might know, a model of OpenAI has limitation of the maximum number of input tokens.
So we have to split the diff of a pull request into multiple chunks, if the size of the diff is over the limitation.
We can tune the chunk size based on the model we use.

Expand Down Expand Up @@ -69,7 +69,6 @@ jobs:
githubRepository: ${{ github.repository }}
githubPullRequestNumber: ${{ github.event.pull_request.number }}
gitCommitHash: ${{ github.event.pull_request.head.sha }}
repoId: "meta-llama/Llama-2-7b-chat-hf"
temperature: "0.2"
maxNewTokens: "250"
topK: "50"
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: 'LLM Code Review'
description: 'Let LLM model review your code'
author: 'Louis Le (luiyen)'
author: 'Marc Khoury -- Forked from Louis Le (luiyen)'
inputs:
githubToken:
description: 'Github token to access the repo'
required: true
apiKey:
description: 'Huggingface access token from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)'
description: 'OPEN AI API KEY'
required: true
githubRepository:
description: "The GitHub repository to use for the action"
Expand All @@ -23,7 +23,7 @@ inputs:
repoId:
description: "LLM model"
required: true
default: "meta-llama/Llama-2-7b-chat-hf"
default: "gpt-3.5-turbo"
maxNewTokens:
description: "The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated."
required: false
Expand Down
18 changes: 9 additions & 9 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import click
import requests
from langchain import HuggingFaceHub, LLMChain, PromptTemplate
from langchain import OpenAI, LLMChain, PromptTemplate
from loguru import logger


Expand Down Expand Up @@ -76,14 +76,14 @@ def get_review(
chunked_diff_list = chunk_string(input_string=diff, chunk_size=prompt_chunk_size)
# Get summary by chunk
chunked_reviews = []
llm = HuggingFaceHub(
repo_id=repo_id,
model_kwargs={"temperature": temperature,
"max_new_tokens": max_new_tokens,
"top_p": top_p,
"top_k": top_k},
huggingfacehub_api_token=os.getenv("API_KEY")
)
llm = OpenAI(
openai_api_key=os.getenv("API_KEY"),
model="gpt-3.5-turbo",
temperature=temperature,
max_new_tokens=max_new_tokens,
top_p=top_p,
top_k=top_k
)
for chunked_diff in chunked_diff_list:
question=chunked_diff
template = """Provide a concise summary of the bug found in the code, describing its characteristics,
Expand Down

0 comments on commit 9e08469

Please sign in to comment.