Skip to content

feat: add azure model provider #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 26, 2024
Merged

Conversation

thucpn
Copy link
Collaborator

@thucpn thucpn commented Jul 25, 2024

Summary by CodeRabbit

  • New Features

    • Integrated Azure OpenAI model support, allowing users to configure and utilize Azure models seamlessly.
    • Added user-friendly prompts for selecting Azure models and entering API keys during configuration.
    • Enhanced dependency management to include Azure-related packages for better functionality.
  • Bug Fixes

    • Improved the overall configuration structure for Azure settings, streamlining the setup process.
  • Documentation

    • Updated documentation to reflect the new Azure provider options and configurations.

@thucpn thucpn requested a review from marcusschiesser July 25, 2024 10:52
Copy link

changeset-bot bot commented Jul 25, 2024

🦋 Changeset detected

Latest commit: f9208d2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
create-llama Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Jul 25, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

This update introduces Azure OpenAI as a new model provider, significantly enhancing the system's capabilities for model management and deployment. Key changes include Azure-specific configuration settings, user interaction for model selection, and expanded dependency management. These enhancements improve flexibility and scalability, enabling users to effectively leverage Azure’s infrastructure for their machine learning applications.

Changes

Files Change Summary
.changeset/smooth-points-float.md Introduces "create-llama" patch for Azure model provider integration, enhancing model management and deployment capabilities.
helpers/env-variables.ts, helpers/providers/azure.ts, helpers/providers/index.ts Adds Azure-specific environment variable configurations and updates the model configuration functions to include Azure OpenAI support and dynamic selection processes.
helpers/python.ts Enhances getAdditionalDependencies to include Azure-specific dependencies for improved functionality.
helpers/types.ts Expands ModelProvider type to include "azure-openai", allowing for broader model integration options.
templates/components/settings/python/settings.py Modifies init_azure_openai function for streamlined Azure configuration management, merging settings into a centralized structure.
templates/types/streaming/express/src/controllers/engine/settings.ts, templates/types/streaming/nextjs/app/api/chat/engine/settings.ts Adds initAzureOpenAI function to configure Azure settings, integrating Azure initialization into existing setup processes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AzureConfig
    participant ModelAPI

    User->>AzureConfig: Request Azure model setup
    AzureConfig->>User: Prompt for API Key & Model selection
    User->>AzureConfig: Provide API Key & select model
    AzureConfig->>ModelAPI: Initialize Azure model with provided settings
    ModelAPI-->>AzureConfig: Confirm model setup
    AzureConfig-->>User: Azure model is ready for use
Loading

🐰 In the garden, where the data flows,
A new friend named Azure, everybody knows.
With models so bright, they leap and they play,
Enhancing our tools in a magical way!
So hop aboard, let the coding commence,
With Azure in hand, we'll leap over the fence! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@thucpn thucpn marked this pull request as ready for review July 26, 2024 05:56
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (2)
templates/types/streaming/nextjs/app/api/chat/engine/settings.ts (1)

73-96: Ensure all required environment variables are set and validated.

The function initAzureOpenAI relies on several environment variables. While these variables are used in the codebase, comprehensive validation for all required environment variables is not evident. Ensure that AZURE_OPENAI_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_VERSION, and AZURE_OPENAI_DEPLOYMENT are properly validated to avoid runtime errors.

  • helpers/providers/azure.ts contains a validation check for AZURE_OPENAI_KEY. Similar checks should be implemented for the other required environment variables.
Analysis chain

Ensure all required environment variables are set and validated.

The function initAzureOpenAI relies on several environment variables. Ensure that these variables are set and validated to avoid runtime errors.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all required environment variables for Azure OpenAI are set.

# Test: Check for the presence of required environment variables. Expect: All variables are set.
env | grep -E 'AZURE_OPENAI_KEY|AZURE_OPENAI_ENDPOINT|AZURE_OPENAI_API_VERSION|AZURE_OPENAI_DEPLOYMENT'

Length of output: 105


Script:

#!/bin/bash
# Description: Search for the usage and validation of required environment variables in the codebase.

# Search for the usage of AZURE_OPENAI_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_VERSION, and AZURE_OPENAI_DEPLOYMENT in the codebase.
rg 'process\.env\.(AZURE_OPENAI_KEY|AZURE_OPENAI_ENDPOINT|AZURE_OPENAI_API_VERSION|AZURE_OPENAI_DEPLOYMENT)' -A 3

Length of output: 2259

templates/types/streaming/express/src/controllers/engine/settings.ts (1)

73-96: Ensure all required environment variables are validated.

The function initAzureOpenAI relies on several environment variables. While AZURE_OPENAI_KEY has a validation check, the environment variables AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_VERSION, and AZURE_OPENAI_DEPLOYMENT do not have any validation checks in the codebase. To avoid potential runtime errors, please add validation checks for these variables.

  • AZURE_OPENAI_ENDPOINT
  • AZURE_OPENAI_API_VERSION
  • AZURE_OPENAI_DEPLOYMENT
Analysis chain

Ensure all required environment variables are set and validated.

The function initAzureOpenAI relies on several environment variables. Ensure that these variables are set and validated to avoid runtime errors.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all required environment variables for Azure OpenAI are set.

# Test: Check for the presence of required environment variables. Expect: All variables are set.
env | grep -E 'AZURE_OPENAI_KEY|AZURE_OPENAI_ENDPOINT|AZURE_OPENAI_API_VERSION|AZURE_OPENAI_DEPLOYMENT'

Length of output: 105


Script:

#!/bin/bash
# Description: Search for the initialization and usage of required environment variables in the codebase.

# Search for AZURE_OPENAI_KEY
rg 'AZURE_OPENAI_KEY'

# Search for AZURE_OPENAI_ENDPOINT
rg 'AZURE_OPENAI_ENDPOINT'

# Search for AZURE_OPENAI_API_VERSION
rg 'AZURE_OPENAI_API_VERSION'

# Search for AZURE_OPENAI_DEPLOYMENT
rg 'AZURE_OPENAI_DEPLOYMENT'

Length of output: 2167


Script:

#!/bin/bash
# Description: Search for validation and fallback mechanisms for required environment variables in the codebase.

# Search for validation of AZURE_OPENAI_KEY
rg 'if.*process.env.AZURE_OPENAI_KEY'

# Search for validation of AZURE_OPENAI_ENDPOINT
rg 'if.*process.env.AZURE_OPENAI_ENDPOINT'

# Search for validation of AZURE_OPENAI_API_VERSION
rg 'if.*process.env.AZURE_OPENAI_API_VERSION'

# Search for validation of AZURE_OPENAI_DEPLOYMENT
rg 'if.*process.env.AZURE_OPENAI_DEPLOYMENT'

Length of output: 254

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a553d50 and 47ecb27.

Files selected for processing (9)
  • .changeset/smooth-points-float.md (1 hunks)
  • helpers/env-variables.ts (1 hunks)
  • helpers/providers/azure.ts (1 hunks)
  • helpers/providers/index.ts (3 hunks)
  • helpers/python.ts (1 hunks)
  • helpers/types.ts (1 hunks)
  • templates/components/settings/python/settings.py (3 hunks)
  • templates/types/streaming/express/src/controllers/engine/settings.ts (3 hunks)
  • templates/types/streaming/nextjs/app/api/chat/engine/settings.ts (2 hunks)
Additional context used
Biome
templates/types/streaming/nextjs/app/api/chat/engine/settings.ts

[error] 48-49: This case is falling through to the next case.

Add a break or return statement to the end of this case to prevent fallthrough.

(lint/suspicious/noFallthroughSwitchClause)

templates/types/streaming/express/src/controllers/engine/settings.ts

[error] 48-49: This case is falling through to the next case.

Add a break or return statement to the end of this case to prevent fallthrough.

(lint/suspicious/noFallthroughSwitchClause)

Additional comments not posted (16)
.changeset/smooth-points-float.md (1)

1-5: LGTM!

The changeset metadata is accurate and follows the expected format.

helpers/types.ts (1)

11-11: LGTM!

The new option "azure" is correctly added to the ModelProvider type.

helpers/providers/index.ts (3)

6-6: LGTM!

The new import statement for askAzureQuestions is correctly added.


38-38: LGTM!

The new entry for Azure OpenAI is correctly added to the choices array.


74-76: LGTM!

The new case for Azure OpenAI is correctly added to the switch statement.

templates/types/streaming/express/src/controllers/engine/settings.ts (1)

60-60: LGTM!

The default model in the initOpenAI function has been correctly updated to "gpt-3.5-turbo".

helpers/providers/azure.ts (3)

6-29: LGTM!

The ALL_AZURE_OPENAI_CHAT_MODELS object correctly maps Azure model names to their corresponding OpenAI model names.


31-50: LGTM!

The ALL_AZURE_OPENAI_EMBEDDING_MODELS object correctly maps Azure embedding model names to their corresponding OpenAI model names and dimensions.


55-128: LGTM! But verify user input handling.

The askAzureQuestions function is correctly implemented. However, ensure that the prompts handle user input and validation correctly.

Verification successful

LGTM! But verify user input handling.

The askAzureQuestions function is correctly implemented. The validation logic for user input is present. However, ensure that it correctly handles the scenario where askModels is true and the AZURE_OPENAI_KEY environment variable is not set.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the user input handling in `askAzureQuestions`.

# Test: Check for the presence of input validation logic. Expect: Input validation logic is present.
rg --type ts 'validate' helpers/providers/azure.ts

Length of output: 89

templates/components/settings/python/settings.py (5)

78-78: Ensure environment variable MODEL is set.

The variable model is directly assigned from the environment variable without a default value. Ensure that MODEL is set in the environment to avoid potential issues.


80-83: Ensure environment variable AZURE_OPENAI_API_VERSION or OPENAI_API_VERSION is set.

The api_version variable is assigned from two possible environment variables. Ensure that at least one of these is set to avoid potential issues.


86-92: LGTM! Generalized configuration structure improves flexibility.

The introduction of the azure_config dictionary encapsulates Azure-specific settings, improving the modularity and readability of the code.


94-99: LGTM! Centralized configuration approach for LLM settings.

The llm_config dictionary now includes Azure-specific settings along with max_tokens and temperature, enhancing the clarity and maintainability of the code.


105-108: LGTM! Centralized configuration approach for embedding settings.

The embedding_config dictionary now includes Azure-specific settings along with dimensions, enhancing the clarity and maintainability of the code.

helpers/python.ts (1)

196-205: LGTM! Azure-specific dependencies added correctly.

The new case for handling "azure" appends the necessary dependencies to the dependencies array, ensuring that the Azure provider is supported.

helpers/env-variables.ts (1)

277-297: LGTM! Azure-specific environment variables added correctly.

The new conditional block for handling "azure" appends the necessary environment variables to the existing configuration, ensuring that the Azure provider is supported.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 47ecb27 and 0bf4479.

Files selected for processing (5)
  • helpers/env-variables.ts (1 hunks)
  • helpers/providers/index.ts (3 hunks)
  • helpers/python.ts (1 hunks)
  • helpers/types.ts (1 hunks)
  • templates/components/settings/python/settings.py (3 hunks)
Files skipped from review as they are similar to previous changes (4)
  • helpers/providers/index.ts
  • helpers/python.ts
  • helpers/types.ts
  • templates/components/settings/python/settings.py
Additional comments not posted (1)
helpers/env-variables.ts (1)

277-301: LGTM! Ensure Azure OpenAI environment variables are correctly utilized.

The code changes are approved.

However, ensure that all the newly added Azure OpenAI environment variables are correctly utilized in the codebase.

Verification successful

Azure OpenAI environment variables are correctly utilized.

The environment variables AZURE_OPENAI_KEY, AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_VERSION, AZURE_OPENAI_LLM_DEPLOYMENT, and AZURE_OPENAI_EMBEDDING_DEPLOYMENT are appropriately used throughout the codebase.

  • Files with usage:
    • templates/components/settings/python/settings.py
    • templates/types/streaming/express/src/controllers/engine/settings.ts
    • templates/types/streaming/nextjs/app/api/chat/engine/settings.ts
    • helpers/providers/azure.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of Azure OpenAI environment variables in the codebase.

# Test: Search for the usage of Azure OpenAI environment variables. Expect: Correct utilization in the codebase.
rg --type python -A 5 $'AZURE_OPENAI_KEY|AZURE_OPENAI_ENDPOINT|AZURE_OPENAI_API_VERSION|AZURE_OPENAI_LLM_DEPLOYMENT|AZURE_OPENAI_EMBEDDING_DEPLOYMENT'

Length of output: 182


Script:

#!/bin/bash
# Description: Verify the usage of Azure OpenAI environment variables in the codebase.

# Test: Search for the usage of Azure OpenAI environment variables. Expect: Correct utilization in the codebase.
rg -A 5 'AZURE_OPENAI_KEY|AZURE_OPENAI_ENDPOINT|AZURE_OPENAI_API_VERSION|AZURE_OPENAI_LLM_DEPLOYMENT|AZURE_OPENAI_EMBEDDING_DEPLOYMENT'

Length of output: 6210

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0bf4479 and 7fa8ce8.

Files selected for processing (2)
  • templates/types/streaming/express/src/controllers/engine/settings.ts (3 hunks)
  • templates/types/streaming/nextjs/app/api/chat/engine/settings.ts (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • templates/types/streaming/express/src/controllers/engine/settings.ts
  • templates/types/streaming/nextjs/app/api/chat/engine/settings.ts

@thucpn thucpn requested a review from marcusschiesser July 26, 2024 09:31
@thucpn thucpn force-pushed the feat/add-azure-model-provider branch from 98feb92 to 9050e19 Compare July 26, 2024 09:32
@thucpn thucpn requested a review from marcusschiesser July 26, 2024 10:28
@marcusschiesser marcusschiesser merged commit fd9fb42 into main Jul 26, 2024
7 checks passed
@marcusschiesser marcusschiesser deleted the feat/add-azure-model-provider branch July 26, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants