Use the best in class GPT models using Azure’s OpenAI API.

Authentication

Set your environment variables.

export AZURE_OPENAI_API_KEY=***
export AZURE_OPENAI_ENDPOINT=***
export AZURE_OPENAI_MODEL_NAME=***
export AZURE_OPENAI_DEPLOYMENT=***
# Optional:
# export AZURE_OPENAI_API_VERSION=***

Example

Use AzureOpenAIChat with your Agent:

import os
from typing import Iterator

from phi.agent import Agent, RunResponse
from phi.model.azure import AzureOpenAIChat

azure_model = AzureOpenAIChat(
    id=os.getenv("AZURE_OPENAI_MODEL_NAME"),
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
    azure_deployment=os.getenv("AZURE_OPENAI_DEPLOYMENT"),
)

agent = Agent(
    model=azure_model,
    markdown=True
)

# Get the response in a variable
# run: RunResponse = agent.run("Share a 2 sentence horror story.")
# print(run.content)

# Print the response on the terminal
agent.print_response("Share a 2 sentence horror story.")

Params

ParameterTypeDefaultDescription
idstr-The specific model ID used for generating responses. This field is required.
namestr"AzureOpenAIChat"The name identifier for the agent.
providerstr"Azure"The provider of the model.
api_keyOptional[str]-The API key for authenticating requests to the Azure OpenAI service.
api_versionstr"2024-02-01"The version of the Azure OpenAI API to use.
azure_endpointOptional[str]-The endpoint URL for the Azure OpenAI service.
azure_deploymentOptional[str]-The deployment name or ID in Azure.
base_urlOptional[str]-The base URL for making API requests to the Azure OpenAI service.
azure_ad_tokenOptional[str]-The Azure Active Directory token for authenticating requests.
azure_ad_token_providerOptional[Any]-The provider for obtaining Azure Active Directory tokens.
organizationOptional[str]-The organization associated with the API requests.
openai_clientOptional[AzureOpenAIClient]-An instance of AzureOpenAIClient provided for making API requests.

Azure also supports the params of OpenAI.