Azure OpenAI#

pydantic model llama_index.llms.azure_openai.AzureOpenAI#

Azure OpenAI.

To use this, you must first deploy a model on Azure OpenAI. Unlike OpenAI, you need to specify a engine parameter to identify your deployment (called “model deployment name” in Azure portal).

  • model: Name of the model (e.g. text-davinci-003)

    This in only used to decide completion vs. chat endpoint.

  • engine: This will correspond to the custom name you chose

    for your deployment when you deployed a model.

You must have the following environment variables set: - OPENAI_API_VERSION: set this to 2023-05-15

This may change in the future.

More information can be found here:

https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quickstart?tabs=command-line&pivots=programming-language-python

Show JSON schema
{
   "title": "AzureOpenAI",
   "description": "Azure OpenAI.\n\nTo use this, you must first deploy a model on Azure OpenAI.\nUnlike OpenAI, you need to specify a `engine` parameter to identify\nyour deployment (called \"model deployment name\" in Azure portal).\n\n- model: Name of the model (e.g. `text-davinci-003`)\n    This in only used to decide completion vs. chat endpoint.\n- engine: This will correspond to the custom name you chose\n    for your deployment when you deployed a model.\n\nYou must have the following environment variables set:\n- `OPENAI_API_VERSION`: set this to `2023-05-15`\n    This may change in the future.\n- `AZURE_OPENAI_ENDPOINT`: your endpoint should look like the following\n    https://YOUR_RESOURCE_NAME.openai.azure.com/\n- `AZURE_OPENAI_API_KEY`: your API key if the api type is `azure`\n\nMore information can be found here:\n    https://learn.microsoft.com/en-us/azure/cognitive-services/openai/quickstart?tabs=command-line&pivots=programming-language-python",
   "type": "object",
   "properties": {
      "callback_manager": {
         "title": "Callback Manager"
      },
      "system_prompt": {
         "title": "System Prompt",
         "description": "System prompt for LLM calls.",
         "type": "string"
      },
      "messages_to_prompt": {
         "title": "Messages To Prompt"
      },
      "completion_to_prompt": {
         "title": "Completion To Prompt"
      },
      "output_parser": {
         "title": "Output Parser"
      },
      "pydantic_program_mode": {
         "default": "default",
         "allOf": [
            {
               "$ref": "#/definitions/PydanticProgramMode"
            }
         ]
      },
      "query_wrapper_prompt": {
         "title": "Query Wrapper Prompt"
      },
      "model": {
         "title": "Model",
         "description": "The OpenAI model to use.",
         "default": "gpt-3.5-turbo",
         "type": "string"
      },
      "temperature": {
         "title": "Temperature",
         "description": "The temperature to use during generation.",
         "default": 0.1,
         "gte": 0.0,
         "lte": 1.0,
         "type": "number"
      },
      "max_tokens": {
         "title": "Max Tokens",
         "description": "The maximum number of tokens to generate.",
         "exclusiveMinimum": 0,
         "type": "integer"
      },
      "additional_kwargs": {
         "title": "Additional Kwargs",
         "description": "Additional kwargs for the OpenAI API.",
         "type": "object"
      },
      "max_retries": {
         "title": "Max Retries",
         "description": "The maximum number of API retries.",
         "default": 3,
         "gte": 0,
         "type": "integer"
      },
      "timeout": {
         "title": "Timeout",
         "description": "The timeout, in seconds, for API requests.",
         "default": 60.0,
         "gte": 0,
         "type": "number"
      },
      "default_headers": {
         "title": "Default Headers",
         "description": "The default headers for API requests.",
         "type": "object",
         "additionalProperties": {
            "type": "string"
         }
      },
      "reuse_client": {
         "title": "Reuse Client",
         "description": "Reuse the OpenAI client between requests. When doing anything with large volumes of async API calls, setting this to false can improve stability.",
         "default": true,
         "type": "boolean"
      },
      "api_key": {
         "title": "Api Key",
         "description": "The OpenAI API key.",
         "type": "string"
      },
      "api_base": {
         "title": "Api Base",
         "description": "The base URL for OpenAI API.",
         "type": "string"
      },
      "api_version": {
         "title": "Api Version",
         "description": "The API version for OpenAI API.",
         "type": "string"
      },
      "engine": {
         "title": "Engine",
         "description": "The name of the deployed azure engine.",
         "type": "string"
      },
      "azure_endpoint": {
         "title": "Azure Endpoint",
         "description": "The Azure endpoint to use.",
         "type": "string"
      },
      "azure_deployment": {
         "title": "Azure Deployment",
         "description": "The Azure deployment to use.",
         "type": "string"
      },
      "use_azure_ad": {
         "title": "Use Azure Ad",
         "description": "Indicates if Microsoft Entra ID (former Azure AD) is used for token authentication",
         "type": "boolean"
      },
      "class_name": {
         "title": "Class Name",
         "type": "string",
         "default": "azure_openai_llm"
      }
   },
   "required": [
      "api_base",
      "api_version",
      "engine",
      "use_azure_ad"
   ],
   "definitions": {
      "PydanticProgramMode": {
         "title": "PydanticProgramMode",
         "description": "Pydantic program mode.",
         "enum": [
            "default",
            "openai",
            "llm",
            "guidance",
            "lm-format-enforcer"
         ],
         "type": "string"
      }
   }
}

Config
  • arbitrary_types_allowed: bool = True

Fields
Validators
  • _validate_callback_manager » callback_manager

  • set_completion_to_prompt » completion_to_prompt

  • set_messages_to_prompt » messages_to_prompt

  • validate_env » all fields

field azure_deployment: Optional[str] = None#

The Azure deployment to use.

Validated by
field azure_endpoint: Optional[str] = None#

The Azure endpoint to use.

Validated by
field engine: str [Required]#

The name of the deployed azure engine.

Validated by
field use_azure_ad: bool [Required]#

Indicates if Microsoft Entra ID (former Azure AD) is used for token authentication

Validated by
classmethod class_name() str#

Get the class name, used as a unique ID in serialization.

This provides a key that makes serialization robust against actual class name changes.

validator validate_env  »  all fields#

Validate necessary credentials are set.