From 68172a0130c6f9a07960685e276885c1a28c59f0 Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Mon, 27 Mar 2023 12:56:58 +0800 Subject: [PATCH] Add support for Azure OpenAI Service --- README.md | 2 ++ action.yaml | 3 +++ app/completion.py | 22 +++++++++++++++------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7a9926d..9f6521a 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + # OPENAI_API_BASE: ${{ secrets.OPENAI_API_BASE }} # Optional configurations: # with: # model: "gpt-3.5-turbo" @@ -38,6 +39,7 @@ jobs: |---------|-----------|--------|-------| |GITHUB_TOKEN|Github token used to send out review comments|true|""| |OPENAI_API_KEY|API key used to invoke OpenAI|true|""| +|OPENAI_API_BASE|API based used to access Azure OpenAI|false|""| |blocking|Blocking the pull requests on OpenAI failures|false|False| |model|OpenAI model name|false|gpt-3.5-turbo| |temperature|Temperature for the model|false|0.2| diff --git a/action.yaml b/action.yaml index 6cae853..ee2ad40 100644 --- a/action.yaml +++ b/action.yaml @@ -8,6 +8,9 @@ inputs: OPENAI_API_KEY: description: "API key used to invoke OpenAI" required: true + OPENAI_API_BASE: + description: "API based used to access [Azure] OpenAI API" + required: false model: description: "OpenAI model name" default: "gpt-3.5-turbo" diff --git a/app/completion.py b/app/completion.py index 8283ac5..4bb1266 100644 --- a/app/completion.py +++ b/app/completion.py @@ -7,13 +7,21 @@ import tiktoken openai.api_key = os.getenv("OPENAI_API_KEY") -system_prompt = '''As a tech reviewer, please provide an in-depth review of the following pull request and pay close attention to the following: -* Review the title, body, and changes made in the pull request. -* Identify any problems and provide clear descriptions and suggestions for how to address them. -* Offer constructive suggestions for optimizing the changes made in the pull request. -* Avoid providing unnecessary explanations or summaries that may delay the review process. -* Provide feedback in a concise and clear manner to help expedite the review process. -* No need for thanking in the review message. +if os.getenv("OPENAI_API_BASE"): + openai.api_base = os.getenv("OPENAI_API_BASE") + if "azure" in os.getenv("OPENAI_API_BASE"): + openai.api_type = "azure" + openai.api_version = "2023-03-15-preview" +system_prompt = '''As a tech reviewer, please provide an in-depth review of the +following pull request. Your task is to carefully analyze the title, body, and +changes made in the pull request and identify any problems that need addressing. +Please provide clear descriptions of each problem and offer constructive suggestions +for how to address them. Additionally, please consider ways to optimize the changes +made in the pull request. You should focus on providing feedback that will help +improve the quality of the codebase while also remaining concise and clear in your +explanations. Please note that unnecessary explanations or summaries should be avoided +as they may delay the review process. Your feedback should be provided in a timely +manner, using language that is easy to understand and follow. '''