-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
chore: update docs and examples for Azure OpenAI v1 #761
chore: update docs and examples for Azure OpenAI v1 #761
Conversation
It looks like you've provided a detailed summary of changes and instructions for generating specific sections. I'll proceed to generate the requested sections based on the provided information. WalkthroughThe updates across various files reflect a shift in the configuration and instantiation of the Azure OpenAI API client. The primary changes involve renaming environment variables and parameters to align with Azure's naming conventions, adjusting the instantiation logic based on the OpenAI API version, and setting the model type. These modifications suggest an effort to streamline the integration with Azure's services and possibly an API version upgrade. Changes
TipsChat with CodeRabbit Bot (
|
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: 4
Configuration used: CodeRabbit UI
Files selected for processing (5)
- docs/LLMs/llms.md (1 hunks)
- examples/with_azure.py (2 hunks)
- pandasai/llm/azure_openai.py (5 hunks)
- pandasai/llm/base.py (2 hunks)
- pandasai/llm/openai.py (2 hunks)
Files skipped from review due to trivial changes (2)
- examples/with_azure.py
- pandasai/llm/base.py
Additional comments: 5
docs/LLMs/llms.md (1)
- 153-160: The documentation correctly reflects the changes in the instantiation of the
AzureOpenAI
object, with theapi_base
parameter being renamed toazure_endpoint
. It's important to ensure that all example code and documentation throughout the project are updated to use the new parameter and environment variable names to avoid confusion.pandasai/llm/openai.py (1)
- 76-92: The logic for setting
self.client
based on the model type is sound, but it's important to ensure that theis_openai_v1()
function correctly identifies the API version and that theopenai.OpenAI
andopenai.ChatCompletion
classes, as well as theopenai.Completion
class, are correctly implemented and imported. If these classes or methods do not exist or are not imported, this will raise anAttributeError
.pandasai/llm/azure_openai.py (3)
48-61: The
__init__
method has been updated to include new parameters and environment variable handling. The renaming ofapi_base
toazure_endpoint
and the introduction ofazure_ad_token
andazure_ad_token_provider
are consistent with Azure-specific naming conventions. The addition ofis_chat_model
parameter allows for specifying the type of model being used, which is important for the conditional assignment of theclient
attribute later in the code.135-143: The conditional assignment of the
client
attribute based on the OpenAI API version and the model type is a good approach to maintain compatibility with different versions and model types. However, ensure that theopenai.AzureOpenAI
andopenai.ChatCompletion
classes exist and are correctly imported from theopenai
library.151-160: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [146-157]
The
_default_params
property has been updated to include theengine
attribute for OpenAI versions prior to v1. This ensures backward compatibility with earlier versions of the API that required anengine
parameter. The use of a conditional expression to determine the correct key (model
orengine
) is a good practice.
pandasai/llm/azure_openai.py
Outdated
self.api_token = ( | ||
api_token | ||
or os.getenv("OPENAI_API_KEY") | ||
or os.getenv("AZURE_OPENAI_API_KEY") | ||
api_token | ||
or os.getenv("OPENAI_API_KEY") | ||
or os.getenv("AZURE_OPENAI_API_KEY") | ||
) | ||
self.azure_endpoint = azure_endpoint or os.getenv("AZURE_OPENAI_ENDPOINT") | ||
self.api_base = api_base or os.getenv("OPENAI_API_BASE") |
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 environment variable fallbacks have been updated to reflect the new Azure-specific names. However, the fallback for api_token
still checks for OPENAI_API_KEY
before AZURE_OPENAI_API_KEY
. This should be reversed to prioritize the Azure-specific environment variable, as the context suggests a move towards Azure-specific naming conventions.
85 self.api_token = (
86 api_token
- or os.getenv("OPENAI_API_KEY")
+ or os.getenv("AZURE_OPENAI_API_KEY")
+ or os.getenv("OPENAI_API_KEY")
88 )
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
self.api_token = ( | |
api_token | |
or os.getenv("OPENAI_API_KEY") | |
or os.getenv("AZURE_OPENAI_API_KEY") | |
api_token | |
or os.getenv("OPENAI_API_KEY") | |
or os.getenv("AZURE_OPENAI_API_KEY") | |
) | |
self.azure_endpoint = azure_endpoint or os.getenv("AZURE_OPENAI_ENDPOINT") | |
self.api_base = api_base or os.getenv("OPENAI_API_BASE") | |
self.api_token = ( | |
api_token | |
or os.getenv("AZURE_OPENAI_API_KEY") | |
or os.getenv("OPENAI_API_KEY") | |
) | |
self.azure_endpoint = azure_endpoint or os.getenv("AZURE_OPENAI_ENDPOINT") | |
self.api_base = api_base or os.getenv("OPENAI_API_BASE") |
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #761 +/- ##
==========================================
+ Coverage 85.36% 85.42% +0.05%
==========================================
Files 74 74
Lines 3656 3650 -6
==========================================
- Hits 3121 3118 -3
+ Misses 535 532 -3 ☔ View full report in Codecov by Sentry. |
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 selected for processing (1)
- pandasai/llm/azure_openai.py (5 hunks)
Additional comments: 3
pandasai/llm/azure_openai.py (3)
48-61: The
__init__
method has been updated to include new parameters and to reflect the changes in the Azure OpenAI API. The inclusion ofazure_endpoint
,azure_ad_token
,azure_ad_token_provider
, and the renaming ofapi_base
toazure_endpoint
are consistent with the Azure branding and API updates. The default value foris_chat_model
has been changed toTrue
, which should be verified if it aligns with the intended default behavior for the class instances.135-143: The logic for setting the
client
attribute based on theis_openai_v1()
function's result is a good approach to handle different versions of the OpenAI API. However, ensure that theopenai.AzureOpenAI
andopenai.ChatCompletion
classes exist and are correctly imported from theopenai
module, as this code assumes their presence.151-157: The
_default_params
property has been updated to use a conditional key based on theis_openai_v1()
function's result. This is a good use of Python's conditional expressions to maintain compatibility with different API versions. Ensure that themodel
andengine
keys are correctly used in the respective API versions.
This change prioritizes AZURE_OPENAI_API_KEY over OPENAI_API_KEY, so one can use 2 backend (OpenAI, AzureOpenAI) setting 2 different vars without conflicts
ecbc278
to
abdb46f
Compare
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 selected for processing (1)
- pandasai/llm/azure_openai.py (5 hunks)
Additional comments: 3
pandasai/llm/azure_openai.py (3)
135-143: The conditional logic for setting the
client
attribute based on the API version is correct. However, ensure that theopenai.AzureOpenAI
class and its methodschat.completions
andcompletions
are available in the OpenAI library for Azure as of version 1.0.0. If the library or methods have changed, this code will need to be updated.151-157: The
_default_params
property is correctly overridden to provide default parameters specific to the Azure OpenAI implementation. The use ofis_openai_v1()
to conditionally set the key to either "model" or "engine" is a good approach to maintain compatibility with different API versions.160-160: The
_invocation_params
property is correctly overridden to provide additional parameters when not using OpenAI version 1. The inclusion ofapi_type
andapi_version
is consistent with the need to specify these when invoking the Azure OpenAI API.
Thanks a lot @mspronesti!! |
This short PR updates the docs and the examples related to
AzureOpenAI
(plus some ruff formatting).Summary by CodeRabbit
Documentation
Refactor
api_base
parameter toazure_endpoint
in theAzureOpenAI
object instantiation.is_chat_model
parameter fromTrue
toFalse
to reflect the model type usage in Azure OpenAI API.AzureOpenAI
andOpenAI
classes to accommodate API updates and versioning.Style