Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Change to Vertex AI from Open AI #506

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 18 additions & 16 deletions .github/workflows/openai-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ name: OpenAI Reviewer
permissions:
contents: read
pull-requests: write
id-token: 'write'

on:
pull_request_target:
pull_request:
types: [opened, synchronize, reopened]
pull_request_review_comment:
types: [created]
Expand All @@ -21,19 +22,20 @@ jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: ${{github.event.pull_request.head.repo.full_name}}
ref: ${{github.event.pull_request.head.ref}}
submodules: false
- uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- uses: actions/checkout@v4

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
debug: true
review_comment_lgtm: false
openai_heavy_model: gpt-4
path_filters: |
!dist/**
!**/*.lock
# workload_identity_provider: projects/636924443032/locations/global/workloadIdentityPools/github-pool/providers/github-provider
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }}
project_id: sandbox-toga4-vertexai

# - uses: ./
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# debug: true
# language: ja-JP
# vertexai_project_id: sandbox-toga4-vertexai
# vertexai_location: asia-northeast1
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ The MIT License (MIT)

Copyright (c) 2023 FluxNinja, Inc.
Copyright (c) 2023 Tao He
Copyright (c) 2023 toga4

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
66 changes: 41 additions & 25 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: 'AI-based PR Reviewer & Summarizer with Chat Capabilities'
branding:
icon: 'git-merge'
color: 'orange'
author: 'CodeRabbit LLC'
author: 'toga4'
inputs:
debug:
required: false
Expand Down Expand Up @@ -144,46 +144,57 @@ inputs:
required: false
description: 'Disable release notes'
default: 'false'
openai_base_url:
# vertexai_base_url:
# required: false
# description: 'The url of the Vertex AI api interface.'
# default: 'https://us-central1-aiplatform.googleapis.com'
vertexai_project_id:
required: true
description: 'Project ID for Vertex AI'
vertexai_location:
required: false
description: 'The url of the openai api interface.'
default: 'https://api.openai.com/v1'
openai_light_model:
description: 'Location for Vertex AI'
default: 'us-central1'
vertexai_light_model:
required: false
description:
'Model to use for simple tasks like summarizing diff on a file.'
default: 'gpt-3.5-turbo'
openai_heavy_model:
default: 'codechat-bison'
vertexai_heavy_model:
required: false
description: 'Model to use for complex tasks such as code reviews.'
default: 'gpt-4'
openai_model_temperature:
default: 'codechat-bison-32k'
vertexai_model_temperature:
required: false
description: 'Temperature for GPT model'
default: '0.05'
openai_retries:
description: 'Temperature for Vertex AI model'
default: '0.9'
vertexai_model_top_k:
required: false
description: 'Top K for Vertex AI model'
default: '32'
vertexai_model_top_p:
required: false
description: 'Top P for Vertex AI model'
default: '1.0'
vertexai_retries:
required: false
description:
'How many times to retry OpenAI API in case of timeouts or errors?'
'How many times to retry Vertex AI API in case of timeouts or errors?'
default: '5'
openai_timeout_ms:
required: false
description: 'Timeout for OpenAI API call in millis'
default: '360000'
openai_concurrency_limit:
vertexai_concurrency_limit:
required: false
description: 'How many concurrent API calls to make to OpenAI servers?'
default: '6'
description: 'How many concurrent API calls to make to Vertex AI servers?'
default: '1'
github_concurrency_limit:
required: false
description: 'How many concurrent API calls to make to GitHub?'
default: '6'
system_message:
required: false
description: 'System message to be sent to OpenAI'
description: 'System message to be sent to Vertex AI'
default: |
You are `@coderabbitai` (aka `github-actions[bot]`), a language model
trained by OpenAI. Your purpose is to act as a highly experienced
You are `/aireviewer` (aka `github-actions[bot]`), a language model
trained by Vertex AI. Your purpose is to act as a highly experienced
software engineer and provide a thorough review of the code hunks
and suggest code snippets to improve key areas such as:
- Logic
Expand All @@ -202,6 +213,11 @@ inputs:
comments/documentation. Identify and resolve significant
concerns to improve overall code quality while deliberately
disregarding minor issues.
reply_for_system_message:
required: false
description: 'The first reply for system message from Vertex AI'
default: |
Got it. I'll review the code and provide a summary. Let's get started.
summarize:
required: false
description: 'The prompt for final summarization response'
Expand Down Expand Up @@ -237,7 +253,7 @@ inputs:
bot_icon:
required: false
description: 'The icon for the bot'
default: '<img src="https://avatars.githubusercontent.com/in/347564?s=41" alt="Image description" width="20" height="20">'
default: 🤖
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
56 changes: 56 additions & 0 deletions docs/oidc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
set -euo pipefail

PROJECT_ID=$(gcloud config get-value project)
SERVICE_ACCOUNT_NAME="github-action"
SERVICE_ACCOUNT="${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"
WORKLOAD_IDENTITY_POOL="github-pool"
WORKLOAD_IDENTITY_PROVIDER="github-provider"
GIT_USER=$(git config user.name)
REPO=$(git remote get-url origin | perl -pe 's/.git$//' | perl -pe 's;.+/([^/]+/[^/]);$1;')

echo "PROJECT_ID=${PROJECT_ID}
SERVICE_ACCOUNT_NAME=${SERVICE_ACCOUNT_NAME}
SERVICE_ACCOUNT=${SERVICE_ACCOUNT}
WORKLOAD_IDENTITY_POOL=${WORKLOAD_IDENTITY_POOL}
WORKLOAD_IDENTITY_PROVIDER=${WORKLOAD_IDENTITY_PROVIDER}
GIT_USER=${GIT_USER}
REPO=${REPO}"

gcloud iam service-accounts create "${SERVICE_ACCOUNT_NAME}" \
--project "${PROJECT_ID}"

gcloud projects add-iam-policy-binding "${PROJECT_ID}" \
--role="roles/aiplatform.user" \
--member="serviceAccount:${SERVICE_ACCOUNT}"

gcloud iam workload-identity-pools create "${WORKLOAD_IDENTITY_POOL}" \
--project="${PROJECT_ID}" \
--location="global" \
--display-name="GitHub Actions Pool"

WORKLOAD_IDENTITY_POOL_ID=$(gcloud iam workload-identity-pools describe "${WORKLOAD_IDENTITY_POOL}" \
--project="${PROJECT_ID}" \
--location="global" \
--format="value(name)")

echo "WORKLOAD_IDENTITY_POOL_ID=${WORKLOAD_IDENTITY_POOL_ID}"

gcloud iam workload-identity-pools providers create-oidc "${WORKLOAD_IDENTITY_PROVIDER}" \
--project="${PROJECT_ID}" \
--location="global" \
--workload-identity-pool="${WORKLOAD_IDENTITY_POOL}" \
--display-name="My GitHub repo Provider" \
--attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository,attribute.repository_owner=assertion.repository_owner" \
--attribute-condition="attribute.repository_owner=='${GIT_USER}'" \
--issuer-uri="https://token.actions.githubusercontent.com"

gcloud iam workload-identity-pools providers describe "${WORKLOAD_IDENTITY_PROVIDER}" \
--project="${PROJECT_ID}" \
--location="global" \
--workload-identity-pool="${WORKLOAD_IDENTITY_POOL}" \
--format="value(name)"

gcloud iam service-accounts add-iam-policy-binding "${SERVICE_ACCOUNT}" \
--project="${PROJECT_ID}" \
--role="roles/iam.workloadIdentityUser" \
--member="principalSet://iam.googleapis.com/${WORKLOAD_IDENTITY_POOL_ID}/attribute.repository/${REPO}"
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "openai-pr-reviewer",
"name": "vertexai-pr-reviewer",
"version": "0.0.0",
"private": true,
"description": "OpenAI-based PR Reviewer and Summarizer.",
"description": "Vertex AI based PR Reviewer and Summarizer.",
"main": "lib/main.js",
"scripts": {
"build": "cp node_modules/@dqbd/tiktoken/tiktoken_bg.wasm dist/tiktoken_bg.wasm && tsc",
Expand All @@ -16,7 +16,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/fluxninja/openai-pr-reviewer.git"
"url": "git+https://github.com/toga4/vertexai-pr-reviewer.git"
},
"keywords": [
"actions",
Expand Down
Loading
Loading