Azure OpenAI
AzureOpenAITools provides access to Azure OpenAI services including DALL-E image generation.
Prerequisites
The following examples require the requests library:
1uv pip install -U requestsSet the following environment variables:
1export AZURE_OPENAI_API_KEY="your-azure-openai-api-key"2export AZURE_OPENAI_ENDPOINT="https://your-resource.openai.azure.com"3export AZURE_OPENAI_API_VERSION="2023-12-01-preview"4export AZURE_OPENAI_IMAGE_DEPLOYMENT="your-dalle-deployment-name"Example
The following agent can generate images using Azure OpenAI's DALL-E:
1from kern.agent import Agent2from kern.tools.models.azure_openai import AzureOpenAITools34agent = Agent(5 instructions=[6 "You are an AI image generation assistant using Azure OpenAI",7 "Generate high-quality images based on user descriptions",8 "Provide detailed descriptions of the generated images",9 ],10 tools=[AzureOpenAITools()],11)1213agent.print_response("Generate an image of a sunset over mountains", stream=True)Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Optional[str] | None | Azure OpenAI API key. Uses AZURE_OPENAI_API_KEY if not set. |
azure_endpoint | Optional[str] | None | Azure OpenAI endpoint. Uses AZURE_OPENAI_ENDPOINT if not set. |
api_version | Optional[str] | "2023-12-01-preview" | Azure OpenAI API version. |
image_deployment | Optional[str] | None | DALL-E deployment name. Uses AZURE_OPENAI_IMAGE_DEPLOYMENT. |
image_model | str | "dall-e-3" | DALL-E model to use (dall-e-2, dall-e-3). |
image_quality | Literal | "standard" | Image quality: "standard" or "hd" (hd only for dall-e-3). |
enable_generate_image | bool | True | Enable the generate image functionality |
all | bool | False | Enable all functionality when set to True |
Toolkit Functions
| Function | Description |
|---|---|
generate_image | Generate images using Azure OpenAI DALL-E models. |
You can use include_tools or exclude_tools to modify the list of tools the agent has access to. Learn more about selecting tools.