-
Notifications
You must be signed in to change notification settings - Fork 301
Added support for Azure bot #519
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis update introduces support for Azure bot using the Changes
Uplevel your code reviews with CodeRabbit ProCodeRabbit ProIf you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects. |
Warning CodeRabbit GitHub Action DetectedThe repository is using both CodeRabbit Pro and CodeRabbit Open Source (via GitHub Actions), which is not recommended as it may lead to duplicate comments and extra noise. Please remove the CodeRabbit GitHub Action. WalkthroughThe recent update introduces the Changes
TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files ignored due to path filters (8)
action.yml
is excluded by:!**/*.yml
dist/37.index.js
is excluded by:!dist/**
dist/73.index.js
is excluded by:!dist/**
dist/index.js
is excluded by:!dist/**
dist/licenses.txt
is excluded by:!dist/**
package-lock.json
is excluded by:!**/*.json
package.json
is excluded by:!**/*.json
tsconfig.json
is excluded by:!**/*.json
Files selected for processing (7)
- src/azure-bot.ts (1 hunks)
- src/bot-interface.ts (1 hunks)
- src/bot.ts (1 hunks)
- src/main.ts (3 hunks)
- src/options.ts (4 hunks)
- src/review-comment.ts (2 hunks)
- src/review.ts (2 hunks)
Additional comments: 6
src/bot-interface.ts (1)
- 1-10: LGTM!
src/bot.ts (1)
- 10-18: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [13-109]
LGTM!
src/main.ts (1)
- 48-86: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [8-109]
LGTM!
src/options.ts (1)
- 43-52: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [25-98]
LGTM!
src/review-comment.ts (1)
- 23-23: LGTM!
src/review.ts (1)
- 28-29: The change to use
BotProtocol
forlightBot
andheavyBot
parameters aligns with the objective to generalize bot handling. Ensure all instances wherelightBot
andheavyBot
are used are compatible with theBotProtocol
interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (11)
- action.yml (1)
- package-lock.json (93)
- package.json (1)
- src/azure-bot.ts (1)
- src/bot-interface.ts (1)
- src/bot.ts (1)
- src/main.ts (3)
- src/options.ts (4)
- src/review-comment.ts (2)
- src/review.ts (2)
- tsconfig.json (1)
Files ignored due to filter (4)
- dist/37.index.js
- dist/73.index.js
- dist/index.js
- dist/licenses.txt
Files not summarized due to errors (1)
- package-lock.json (diff tokens exceeds limit)
Files skipped from review due to trivial changes (2)
- src/bot-interface.ts
- tsconfig.json
Review comments generated (19)
- Review: 10
- LGTM: 9
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
"@langchain/openai": "^0.0.14", | ||
"@octokit/action": "^6.0.4", | ||
"@octokit/plugin-retry": "^4.1.3", | ||
"@octokit/plugin-throttling": "^6.1.0", | ||
"langchain": "^0.1.17", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", | ||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" | ||
}, | ||
"node_modules/@anthropic-ai/sdk/node_modules/whatwg-url": { | ||
"version": "5.0.0", | ||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", | ||
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", | ||
"dependencies": { | ||
"tr46": "~0.0.3", | ||
"webidl-conversions": "^3.0.0" | ||
} | ||
}, | ||
"node_modules/@babel/code-frame": { | ||
"version": "7.18.6", | ||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz", | ||
"integrity": "sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==", | ||
"version": "7.23.5", | ||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.23.5.tgz", | ||
"integrity": "sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==", | ||
"dev": true, | ||
"dependencies": { | ||
"@babel/highlight": "^7.18.6" | ||
"@babel/highlight": "^7.23.4", | ||
"chalk": "^2.4.2" | ||
}, | ||
"engines": { | ||
"node": ">=6.9.0" | ||
} | ||
}, | ||
"node_modules/@babel/code-frame/node_modules/ansi-styles": { | ||
"version": "3.2.1", | ||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", | ||
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", | ||
"dev": true, | ||
"dependencies": { | ||
"color-convert": "^1.9.0" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
} | ||
}, | ||
"node_modules/@babel/code-frame/node_modules/chalk": { | ||
"version": "2.4.2", | ||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", | ||
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", | ||
"dev": true, | ||
"dependencies": { | ||
"ansi-styles": "^3.2.1", | ||
"escape-string-regexp": "^1.0.5", | ||
"supports-color": "^5.3.0" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
} | ||
}, | ||
"node_modules/@babel/code-frame/node_modules/color-convert": { | ||
"version": "1.9.3", | ||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", | ||
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", | ||
"dev": true, | ||
"dependencies": { | ||
"color-name": "1.1.3" | ||
} | ||
}, | ||
"node_modules/@babel/code-frame/node_modules/color-name": { | ||
"version": "1.1.3", | ||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", | ||
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", | ||
"dev": true | ||
}, | ||
"node_modules/@babel/code-frame/node_modules/escape-string-regexp": { | ||
"version": "1.0.5", | ||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", | ||
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", | ||
"dev": true, | ||
"engines": { | ||
"node": ">=0.8.0" | ||
} | ||
}, | ||
"node_modules/@babel/code-frame/node_modules/has-flag": { | ||
"version": "3.0.0", | ||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", | ||
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", | ||
"dev": true, | ||
"engines": { | ||
"node": ">=4" | ||
} | ||
}, | ||
"node_modules/@babel/code-frame/node_modules/supports-color": { | ||
"version": "5.5.0", | ||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", | ||
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", | ||
"dev": true, | ||
"dependencies": { | ||
"has-flag": "^3.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @anthropic-ai/sdk
package and its dependencies have been added. As with the previous comment, ensure that this package is actively maintained, does not have any known security vulnerabilities, and is compatible with the other packages in your project.
+ "node_modules/@anthropic-ai/sdk": {
+ "version": "0.9.1",
+ "resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.9.1.tgz",
+ "integrity": "sha512-wa1meQ2WSfoY8Uor3EdrJq0jTiZJoKoSii2ZVWRY1oN4Tlr5s59pADg9T79FTbPe1/se5c3pBeZgJL63wmuoBA==",
+ "dependencies": {
+ "@types/node": "^18.11.18",
+ "@types/node-fetch": "^2.6.4",
+ "abort-controller": "^3.0.0",
+ "agentkeepalive": "^4.2.1",
+ "digest-fetch": "^1.3.0",
+ "form-data-encoder": "1.7.2",
+ "formdata-node": "^4.3.2",
+ "node-fetch": "^2.6.7",
+ "web-streams-polyfill": "^3.2.1"
+ }
+ },
"version": "6.3.1", | ||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", | ||
"integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", | ||
"dev": true, | ||
"bin": { | ||
"semver": "bin/semver.js" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"node_modules/@babel/generator": { | ||
"version": "7.21.3", | ||
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.21.3.tgz", | ||
"integrity": "sha512-QS3iR1GYC/YGUnW7IdggFeN5c1poPUurnGttOV/bZgPGV+izC/D8HnD6DLwod0fsatNyVn1G3EVWMYIF0nHbeA==", | ||
"version": "7.23.6", | ||
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.6.tgz", | ||
"integrity": "sha512-qrSfCYxYQB5owCmGLbl8XRpX1ytXlpueOb0N0UmQwA073KZxejgQTzAmJezxvpwQD9uGtK2shHdi55QT+MbjIw==", | ||
"dev": true, | ||
"dependencies": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version of @babel/generator
has been updated from 7.21.3
to 7.23.6
. This is a minor version update, so while it should not introduce any breaking changes, it may add new features. Make sure to check the changelog for this package and test your application thoroughly.
- "version": "7.21.3",
+ "version": "7.23.6",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
action.yml
is excluded by:!**/*.yml
dist/index.js
is excluded by:!dist/**
Files selected for processing (4)
- src/azure-bot.ts (1 hunks)
- src/main.ts (3 hunks)
- src/review-comment.ts (2 hunks)
- src/review.ts (2 hunks)
Files skipped from review as they are similar to previous changes (4)
- src/azure-bot.ts
- src/main.ts
- src/review-comment.ts
- src/review.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (5)
- action.yml (1)
- src/azure-bot.ts (1)
- src/main.ts (3)
- src/review-comment.ts (2)
- src/review.ts (2)
Files ignored due to filter (1)
- dist/index.js
Review comments generated (13)
- Review: 8
- LGTM: 5
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
lightBot: BotProtocol, | ||
heavyBot: BotProtocol, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/azure-bot.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/azure-bot.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (1)
- src/azure-bot.ts (1)
Review comments generated (2)
- Review: 2
- LGTM: 0
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
private readonly model: ChatOpenAI | null = null | ||
private readonly api: ConversationChain | null = null | ||
|
||
private readonly options: Options | ||
|
||
constructor(options: Options, openaiOptions: OpenAIOptions) { | ||
this.options = options | ||
if ( | ||
process.env.AZURE_OPENAI_API_KEY && | ||
options.azureApiDeployment && | ||
options.apiBaseUrl && | ||
options.azureApiInstance | ||
) { | ||
const currentDate = new Date().toISOString().split('T')[0] | ||
const systemMessage = `${options.systemMessage} | ||
Knowledge cutoff: ${openaiOptions.tokenLimits.knowledgeCutOff} | ||
Current date: ${currentDate} | ||
|
||
IMPORTANT: Entire response must be in the language with ISO code: ${options.language} | ||
` | ||
const chatPrompt = ChatPromptTemplate.fromMessages([ | ||
['system', systemMessage], | ||
new MessagesPlaceholder('history'), | ||
['human', '{input}'] | ||
]) | ||
|
||
this.model = new ChatOpenAI({ | ||
temperature: options.openaiModelTemperature, | ||
maxTokens: openaiOptions.tokenLimits.responseTokens, | ||
azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY, | ||
azureOpenAIApiVersion: options.azureApiVersion, | ||
azureOpenAIApiInstanceName: options.azureApiInstance, | ||
azureOpenAIApiDeploymentName: options.azureApiDeployment, | ||
timeout: this.options.openaiTimeoutMS, | ||
maxRetries: this.options.openaiRetries | ||
}) | ||
this.api = new ConversationChain({ | ||
memory: new BufferMemory({returnMessages: true, memoryKey: 'history'}), | ||
prompt: chatPrompt, | ||
llm: this.model | ||
}) | ||
} else { | ||
const err = | ||
"Unable to initialize the OpenAI API, ensure 'AZURE_OPENAI_API_KEY', 'azureApiDeployment', 'apiBaseUrl', and 'azureApiInstance' are properly set" | ||
throw new Error(err) | ||
} | ||
} | ||
|
||
chat = async (message: string, ids: Ids): Promise<[string, Ids]> => { | ||
let res: [string, Ids] = ['', ids] | ||
try { | ||
res = await this.chat_(message) | ||
return res | ||
} catch (e: unknown) { | ||
warning(`Failed to chat: ${e}`) | ||
return res | ||
} | ||
} | ||
|
||
private readonly chat_ = async (message: string): Promise<[string, Ids]> => { | ||
// record timing | ||
const start = Date.now() | ||
if (!message) { | ||
return ['', {}] | ||
} | ||
|
||
let response: ChainValues | undefined | ||
|
||
if (this.api != null) { | ||
try { | ||
response = await this.api.call({input: message}) | ||
} catch (e: unknown) { | ||
info(`response: ${response}, failed to send message to openai: ${e}`) | ||
} | ||
const end = Date.now() | ||
info(`response: ${JSON.stringify(response)}`) | ||
info( | ||
`openai sendMessage (including retries) response time: ${ | ||
end - start | ||
} ms` | ||
) | ||
} else { | ||
setFailed('The OpenAI API is not initialized') | ||
} | ||
let responseText = '' | ||
if (response != null) { | ||
responseText = response.response | ||
} else { | ||
warning('openai response is null') | ||
} | ||
// remove the prefix "with " in the response | ||
if (responseText.startsWith('with ')) { | ||
responseText = responseText.substring(5) | ||
} | ||
if (this.options.debug) { | ||
info(`openai responses: ${responseText}`) | ||
} | ||
return [responseText, {}] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AzureBot
class seems to be well implemented. It checks for the necessary environment variables and options before initializing the OpenAI API and throws an error if they are not set. The chat
method is designed to handle errors gracefully, logging a warning instead of throwing an exception when a chat fails. However, there's a potential issue with the error handling in the chat_
method.
private readonly chat_ = async (message: string): Promise<[string, Ids]> => { | ||
// record timing | ||
const start = Date.now() | ||
if (!message) { | ||
return ['', {}] | ||
} | ||
|
||
let response: ChainValues | undefined | ||
|
||
if (this.api != null) { | ||
try { | ||
response = await this.api.call({input: message}) | ||
} catch (e: unknown) { | ||
info(`response: ${response}, failed to send message to openai: ${e}`) | ||
} | ||
const end = Date.now() | ||
info(`response: ${JSON.stringify(response)}`) | ||
info( | ||
`openai sendMessage (including retries) response time: ${ | ||
end - start | ||
} ms` | ||
) | ||
} else { | ||
setFailed('The OpenAI API is not initialized') | ||
} | ||
let responseText = '' | ||
if (response != null) { | ||
responseText = response.response | ||
} else { | ||
warning('openai response is null') | ||
} | ||
// remove the prefix "with " in the response | ||
if (responseText.startsWith('with ')) { | ||
responseText = responseText.substring(5) | ||
} | ||
if (this.options.debug) { | ||
info(`openai responses: ${responseText}`) | ||
} | ||
return [responseText, {}] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the chat_
method, you're catching any exceptions that occur when calling the OpenAI API, but you're not rethrowing them or handling them in any other way. This means that if an error occurs, the function will continue executing as if nothing happened, which could lead to unexpected behavior.
Consider rethrowing the exception after logging it, or handling it in some other appropriate way. Here's an example of how you might modify the code:
if (this.api != null) {
try {
response = await this.api.call({input: message})
} catch (e: unknown) {
info(`response: ${response}, failed to send message to openai: ${e}`)
+ throw e
}
const end = Date.now()
info(`response: ${JSON.stringify(response)}`)
info(
`openai sendMessage (including retries) response time: ${
end - start
} ms`
)
} else {
setFailed('The OpenAI API is not initialized')
}
This way, if an error occurs when calling the OpenAI API, the error will be logged and then rethrown, causing the chat
method to catch it and log a warning.
What:
Added
langchain
package that is used inAzureBot
for communicating with Azure API. Based on provided configurationAzureBot
will be used as Bot.Why:
This fixes issue #382. Enable to use coderabbitai with Azure API.
Summary by CodeRabbit
New Features
AzureBot
class for integrating with Azure services and OpenAI chat model.Refactor
Bot
class to implement the newBotProtocol
interface.BotProtocol
in place of directBot
references, improving flexibility and maintainability.Summary by CodeRabbit
BotProtocol
interface to improve flexibility and maintainability. The code can now handle different types of bots, not just the originalBot
.package.json
file and added theskipLibCheck
option to the TypeScript configuration file for better development experience.