Examples
- Introduction
- Agents
- Models
- Integrations
- Agent Teams
- Use Cases
How To
Models
Azure
Example
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,
)
# 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.")
Usage
1
Create a virtual environment
Open the Terminal
and create a python virtual environment.
python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
2
Install libraries
pip install -U openai phidata
3
Export 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=***
4
Run azure Agent
python cookbook/providers/azure_openai/basic.py
Information
- View on Github
Was this page helpful?
On this page