AzureOpenAISettings Class
AzureOpenAI model settings.
The settings are first loaded from environment variables with the prefix '>>AZURE_OPENAI_<<'. If the environment variables are not found, the settings can be loaded from a .env file with the encoding 'utf-8'. If the settings are not found in the .env file, the settings are ignored; however, validation will fail alerting that the settings are missing.
Optional settings for prefix '>>AZURE_OPENAI_<<' are:
chat_deployment_name: str - The name of the Azure Chat deployment. This value
will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under Resource Management > Deployments in the Azure portal or, alternatively, under Management > Deployments in Azure OpenAI Studio. (Env var AZURE_OPENAI_CHAT_DEPLOYMENT_NAME)
text_deployment_name: str - The name of the Azure Text deployment. This value
will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under Resource Management > Deployments in the Azure portal or, alternatively, under Management > Deployments in Azure OpenAI Studio. (Env var AZURE_OPENAI_TEXT_DEPLOYMENT_NAME)
embedding_deployment_name: str - The name of the Azure Embedding deployment. This value
will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under Resource Management > Deployments in the Azure portal or, alternatively, under Management > Deployments in Azure OpenAI Studio. (Env var AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME)
text_to_image_deployment_name: str - The name of the Azure Text to Image deployment. This
value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under Resource Management > Deployments in the Azure portal or, alternatively, under Management > Deployments in Azure OpenAI Studio. (Env var AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME)
audio_to_text_deployment_name: str - The name of the Azure Audio to Text deployment. This
value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under Resource Management > Deployments in the Azure portal or, alternatively, under Management > Deployments in Azure OpenAI Studio. (Env var AZURE_OPENAI_AUDIO_TO_TEXT_DEPLOYMENT_NAME)
text_to_audio_deployment_name: str - The name of the Azure Text to Audio deployment. This
value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under Resource Management > Deployments in the Azure portal or, alternatively, under Management > Deployments in Azure OpenAI Studio. (Env var AZURE_OPENAI_TEXT_TO_AUDIO_DEPLOYMENT_NAME)
api_key: SecretStr - The API key for the Azure deployment. This value can be
found in the Keys & Endpoint section when examining your resource in the Azure portal. You can use either KEY1 or KEY2. (Env var AZURE_OPENAI_API_KEY)
base_url: HttpsUrl | None - base_url: The url of the Azure deployment. This value
can be found in the Keys & Endpoint section when examining your resource from the Azure portal, the base_url consists of the endpoint, followed by /openai/deployments/{deployment_name}/, use endpoint if you only want to supply the endpoint. (Env var AZURE_OPENAI_BASE_URL)
endpoint: HttpsUrl - The endpoint of the Azure deployment. This value
can be found in the Keys & Endpoint section when examining your resource from the Azure portal, the endpoint should end in openai.azure.com. If both base_url and endpoint are supplied, base_url will be used. (Env var AZURE_OPENAI_ENDPOINT)
api_version: str | None - The API version to use. The default value is "2024-02-01".
(Env var AZURE_OPENAI_API_VERSION)
token_endpoint: str - The token endpoint to use to retrieve the authentication token.
The default value is "https://cognitiveservices.azure.com/.default". (Env var AZURE_OPENAI_TOKEN_ENDPOINT)
Constructor
AzureOpenAISettings(_case_sensitive: bool | None = None, _nested_model_default_partial_update: bool | None = None, _env_prefix: str | None = None, _env_file: DotenvType | None = PosixPath('.'), _env_file_encoding: str | None = None, _env_ignore_empty: bool | None = None, _env_nested_delimiter: str | None = None, _env_parse_none_str: str | None = None, _env_parse_enums: bool | None = None, _cli_prog_name: str | None = None, _cli_parse_args: bool | list[str] | tuple[str, ...] | None = None, _cli_settings_source: CliSettingsSource[Any] | None = None, _cli_parse_none_str: str | None = None, _cli_hide_none_type: bool | None = None, _cli_avoid_json: bool | None = None, _cli_enforce_required: bool | None = None, _cli_use_class_docs_for_groups: bool | None = None, _cli_exit_on_error: bool | None = None, _cli_prefix: str | None = None, _cli_implicit_flags: bool | None = None, _secrets_dir: PathType | None = None, *, env_file_path: str | None = None, env_file_encoding: str = 'utf-8', chat_deployment_name: str | None = None, text_deployment_name: str | None = None, embedding_deployment_name: str | None = None, text_to_image_deployment_name: str | None = None, audio_to_text_deployment_name: str | None = None, text_to_audio_deployment_name: str | None = None, endpoint: Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=['https'], host_required=None, default_host=None, default_port=None, default_path=None)] | None = None, base_url: Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=['https'], host_required=None, default_host=None, default_port=None, default_path=None)] | None = None, api_key: SecretStr | None = None, api_version: str = '2024-10-21', token_endpoint: str = 'https://cognitiveservices.azure.com/.default')
Parameters
Name | Description |
---|---|
_case_sensitive
|
Default value: None
|
_nested_model_default_partial_update
|
Default value: None
|
_env_prefix
|
Default value: None
|
_env_file
|
Default value: .
|
_env_file_encoding
|
Default value: None
|
_env_ignore_empty
|
Default value: None
|
_env_nested_delimiter
|
Default value: None
|
_env_parse_none_str
|
Default value: None
|
_env_parse_enums
|
Default value: None
|
_cli_prog_name
|
Default value: None
|
_cli_parse_args
|
Default value: None
|
_cli_settings_source
|
Default value: None
|
_cli_parse_none_str
|
Default value: None
|
_cli_hide_none_type
|
Default value: None
|
_cli_avoid_json
|
Default value: None
|
_cli_enforce_required
|
Default value: None
|
_cli_use_class_docs_for_groups
|
Default value: None
|
_cli_exit_on_error
|
Default value: None
|
_cli_prefix
|
Default value: None
|
_cli_implicit_flags
|
Default value: None
|
_secrets_dir
|
Default value: None
|
Keyword-Only Parameters
Name | Description |
---|---|
env_file_path
Required
|
|
env_file_encoding
|
Default value: utf-8
|
chat_deployment_name
Required
|
|
text_deployment_name
Required
|
|
embedding_deployment_name
Required
|
|
text_to_image_deployment_name
Required
|
|
audio_to_text_deployment_name
Required
|
|
text_to_audio_deployment_name
Required
|
|
endpoint
Required
|
|
base_url
Required
|
|
api_key
Required
|
|
api_version
|
Default value: 2024-10-21
|
token_endpoint
|
Default value: https://cognitiveservices.azure.com/.default
|
Methods
get_azure_openai_auth_token |
Retrieve a Microsoft Entra Auth Token for a given token endpoint for the use with Azure OpenAI. The required role for the token is Cognitive Services OpenAI Contributor. The token endpoint may be specified as an environment variable, via the .env file or as an argument. If the token endpoint is not provided, the default is None. The token_endpoint argument takes precedence over the token_endpoint attribute. |
get_azure_openai_auth_token
Retrieve a Microsoft Entra Auth Token for a given token endpoint for the use with Azure OpenAI.
The required role for the token is Cognitive Services OpenAI Contributor. The token endpoint may be specified as an environment variable, via the .env file or as an argument. If the token endpoint is not provided, the default is None. The token_endpoint argument takes precedence over the token_endpoint attribute.
get_azure_openai_auth_token(token_endpoint: str | None = None) -> str | None
Parameters
Name | Description |
---|---|
token_endpoint
|
The token endpoint to use. Defaults to https://cognitiveservices.azure.com/.default. Default value: None
|
Returns
Type | Description |
---|---|
The Azure token or None if the token could not be retrieved. |
Exceptions
Type | Description |
---|---|
If the token endpoint is not provided. |
Attributes
api_key
api_key: SecretStr | None
api_version
api_version: str
audio_to_text_deployment_name
audio_to_text_deployment_name: str | None
base_url
base_url: Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=['https'], host_required=None, default_host=None, default_port=None, default_path=None)] | None
chat_deployment_name
chat_deployment_name: str | None
embedding_deployment_name
embedding_deployment_name: str | None
endpoint
endpoint: Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=['https'], host_required=None, default_host=None, default_port=None, default_path=None)] | None
env_prefix
env_prefix: ClassVar[str] = 'AZURE_OPENAI_'
text_deployment_name
text_deployment_name: str | None
text_to_audio_deployment_name
text_to_audio_deployment_name: str | None
text_to_image_deployment_name
text_to_image_deployment_name: str | None
token_endpoint
token_endpoint: str