Skip to content

Commit

Permalink
feat(azureai): Add support for azure open Ai (#377)
Browse files Browse the repository at this point in the history
* feat(azureai): add azure AI to supported models.

* feat(azureai): add in test PR review process.

* add in break

* feat(azureai): add demo workflow.

* feat(azureai): add check for either open ai, or azure open ai key.

* docs(azureai): add documentation for Azure Open Ai

* chore: delete test workflow.
  • Loading branch information
Phiph authored Jan 20, 2025
1 parent e7cb470 commit 989c26a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
39 changes: 39 additions & 0 deletions docs/ai-provider-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Provider Configuration

## Using the Azure OpenAI Provider

This section will guide you through configuring and using the Azure OpenAI provider in your Code Review project, which leverages Large Language Models (LLMs) to enhance your code quality and prevent bugs before they reach production.

### Prerequisites

Before you begin, make sure you have the following:

- Azure OpenAI service with a model that supports [Structured Outputs](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/structured-outputs)
- Necessary secrets stored in your repository/environment settings.

To set up the code review script with the Azure OpenAI provider on GitHub CI, add the following configuration in your GitHub Actions workflow file (e.g., .github/workflows/review.yml):

```yaml
- name: Run code review script
run: bun run start review --ci=github --provider=azureai
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
GITHUB_SHA: ${{ github.sha }}
AZURE_OPENAI_API_INSTANCE_NAME: "my-azure-open-ai-instance"
AZURE_OPENAI_API_DEPLOYMENT_NAME: "gpt-40"
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_API_VERSION: "2024-08-01-preview"
```
Key Environment Variables
AZURE_OPENAI_API_INSTANCE_NAME: The unique name of your Azure OpenAI instance.
AZURE_OPENAI_API_DEPLOYMENT_NAME: The deployment name of the model instance you are utilizing in Azure.
AZURE_OPENAI_API_KEY: Your Azure OpenAI API key; should be stored securely as a secret.
AZURE_OPENAI_API_VERSION: Specifies the API version you're using, supporting future and preview versions.
### Troubleshooting
- Invalid API Keys: Double-check your secrets to ensure that they are accurate and up-to-date.
- Deployment Issues: Verify that the deployment names and instance names are correctly stated and match those in your Azure set up.
- `400 Invalid parameter: 'response_format' of type 'json_schema' is not supported with this model` ensure that you're using a model that supports [Structured Outputs](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/structured-outputs)
2 changes: 1 addition & 1 deletion src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const getYargs = async (): Promise<ReviewArgs> => {
})
.option('provider', {
description: 'Provider to use for AI',
choices: ['openai', 'bedrock'],
choices: ['openai', 'azureai', 'bedrock'],
type: 'string',
default: 'openai',
})
Expand Down
7 changes: 6 additions & 1 deletion src/common/model/AIModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChatOpenAI } from '@langchain/openai';
import { ChatOpenAI, AzureChatOpenAI } from '@langchain/openai';

import type { ZodType } from 'zod';
import type { IFeedback } from '../types';
Expand Down Expand Up @@ -26,6 +26,11 @@ export class AIModel {
modelName: options.modelName,
});
break;
case "azureai":
this.model = new AzureChatOpenAI({
temperature: options.temperature,
});
break;
case 'bedrock':
throw new Error('Bedrock provider not implemented');
default:
Expand Down
9 changes: 6 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ In CI:
import { logger } from './common/utils/logger';

export const getOpenAIApiKey = (): string => {
if (!process.env.OPENAI_API_KEY) {
logger.error('OPENAI_API_KEY is not set');
const openAiApiKey = process.env.OPENAI_API_KEY;
const azureOpenAiApiKey = process.env.AZURE_OPENAI_API_KEY;

if (!openAiApiKey && !azureOpenAiApiKey) {
logger.error('Neither OPENAI_API_KEY nor AZURE_OPENAI_API_KEY is set');
}

return process.env.OPENAI_API_KEY ?? '';
return openAiApiKey ?? azureOpenAiApiKey ?? '';
};

export const githubToken = (): string => {
Expand Down

0 comments on commit 989c26a

Please sign in to comment.