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

Commit 009189b

Browse files
committed
Code rabbit remarks fixes
1 parent 9857827 commit 009189b

File tree

6 files changed

+46
-60
lines changed

6 files changed

+46
-60
lines changed

action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ inputs:
146146
default: 'false'
147147
azure_api_instance_name:
148148
required: false
149-
description: 'For example, if your Azure instance is hosted under https://{INSTANCE_NAME}.openai.azure.com/openai/deployments/{DEPLOYMENT_NAME} use INSTANCE_NAME'
149+
description: 'Instance name of your Azure API. For example, if your Azure instance is hosted under https://{INSTANCE_NAME}.openai.azure.com/openai/deployments/{DEPLOYMENT_NAME}, use INSTANCE_NAME'
150150
azure_api_deployment_name:
151151
required: false
152-
description: 'For example, if your Azure instance is hosted under https://{INSTANCE_NAME}.openai.azure.com/openai/deployments/{DEPLOYMENT_NAME} use DEPLOYMENT_NAME'
152+
description: 'Deployment name of your Azure API. For example, if your Azure instance is hosted under https://{INSTANCE_NAME}.openai.azure.com/openai/deployments/{DEPLOYMENT_NAME}, use DEPLOYMENT_NAME'
153153
azure_api_version:
154154
required: false
155155
description: 'Api version like "2023-07-01-preview"'

dist/index.js

+16-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/azure-bot.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class AzureBot implements BotProtocol {
5252
})
5353
} else {
5454
const err =
55-
"Unable to initialize the OpenAI API, both 'AZURE_OPENAI_API_KEY' environment variable are not available"
55+
"Unable to initialize the OpenAI API, ensure 'AZURE_OPENAI_API_KEY', 'azureApiDeployment', 'apiBaseUrl', and 'azureApiInstance' are properly set"
5656
throw new Error(err)
5757
}
5858
}
@@ -63,6 +63,7 @@ export class AzureBot implements BotProtocol {
6363
res = await this.chat_(message)
6464
return res
6565
} catch (e: unknown) {
66+
warning(`Failed to chat: ${e}`)
6667
return res
6768
}
6869
}

src/main.ts

+24-33
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {OpenAIOptions, Options} from './options'
1313
import {Prompts} from './prompts'
1414
import {codeReview} from './review'
1515
import {handleReviewComment} from './review-comment'
16+
import {TokenLimits} from './limits'
1617

1718
async function run(): Promise<void> {
1819
const options: Options = new Options(
@@ -48,43 +49,33 @@ async function run(): Promise<void> {
4849

4950
// Create two bots, one for summary and one for review
5051

51-
let lightBot: BotProtocol | null = null
52-
try {
53-
if (options.azureApiDeployment.length > 0) {
54-
lightBot = new AzureBot(
55-
options,
56-
new OpenAIOptions(options.openaiLightModel, options.lightTokenLimits)
57-
)
58-
} else {
59-
lightBot = new Bot(
60-
options,
61-
new OpenAIOptions(options.openaiLightModel, options.lightTokenLimits)
52+
function createBot(
53+
model: string,
54+
tokenLimits: TokenLimits
55+
): BotProtocol | null {
56+
try {
57+
if (options.azureApiDeployment.length > 0) {
58+
return new AzureBot(options, new OpenAIOptions(model, tokenLimits))
59+
} else {
60+
return new Bot(options, new OpenAIOptions(model, tokenLimits))
61+
}
62+
} catch (e: any) {
63+
warning(
64+
`Skipped: failed to create bot, please check your openai_api_key: ${e}, backtrace: ${e.stack}`
6265
)
66+
return null
6367
}
64-
} catch (e: any) {
65-
warning(
66-
`Skipped: failed to create summary bot, please check your openai_api_key: ${e}, backtrace: ${e.stack}`
67-
)
68-
return
6968
}
7069

71-
let heavyBot: BotProtocol | null = null
72-
try {
73-
if (options.azureApiDeployment.length > 0) {
74-
heavyBot = new AzureBot(
75-
options,
76-
new OpenAIOptions(options.openaiHeavyModel, options.heavyTokenLimits)
77-
)
78-
} else {
79-
heavyBot = new Bot(
80-
options,
81-
new OpenAIOptions(options.openaiHeavyModel, options.heavyTokenLimits)
82-
)
83-
}
84-
} catch (e: any) {
85-
warning(
86-
`Skipped: failed to create review bot, please check your openai_api_key: ${e}, backtrace: ${e.stack}`
87-
)
70+
const lightBot: BotProtocol | null = createBot(
71+
options.openaiLightModel,
72+
options.lightTokenLimits
73+
)
74+
const heavyBot: BotProtocol | null = createBot(
75+
options.openaiHeavyModel,
76+
options.heavyTokenLimits
77+
)
78+
if (lightBot == null || heavyBot == null) {
8879
return
8980
}
9081

src/review-comment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {info, warning} from '@actions/core'
22
// eslint-disable-next-line camelcase
33
import {context as github_context} from '@actions/github'
4-
import {type BotProtocol} from './bot-interface'
4+
import {BotProtocol} from './bot-interface'
55
import {
66
Commenter,
77
COMMENT_REPLY_TAG,

src/review.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {error, info, warning} from '@actions/core'
22
// eslint-disable-next-line camelcase
33
import {context as github_context} from '@actions/github'
44
import pLimit from 'p-limit'
5-
import {type BotProtocol} from './bot-interface'
5+
import {BotProtocol} from './bot-interface'
66
import {
77
Commenter,
88
COMMENT_REPLY_TAG,

0 commit comments

Comments
 (0)