i have gpt-4o-mini deployed on azure. how do i con...
# ask-ai
w
i have gpt-4o-mini deployed on azure. how do i configure it as llm? give me the code snippet
t
Thanks for reaching out, Sunil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! To get GPT-4o-mini up and running on Azure as your LLM, just follow these simple steps: 1. First, install the LiveKit OpenAI Plugin:
pip install "livekit-agents[openai]~=1.0"
2. Next, set your environment variables: ◦ `AZURE_OPENAI_API_KEY`: Pop in your Azure OpenAI API key here. ◦ `AZURE_OPENAI_ENDPOINT`: This should look like
https://{your-resource-name}.<http://openai.azure.com|openai.azure.com>
. ◦ `OPENAI_API_VERSION`: Use the API version for Azure OpenAI, like
2024-05-01-preview
. 1. Then, initialize your LLM with the Azure settings:
Copy code
from livekit.plugins.openai import LLM

azure_llm = LLM.with_azure(
    model="gpt-4o-mini",
    azure_deployment="your-gpt-4o-mini-deployment-name",  # This should match your Azure deployment name
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),    # Optional if you’ve set the env variable
    api_version=os.getenv("OPENAI_API_VERSION"),          # Optional if you’ve set the env variable
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),            # Optional if you’ve set the env variable
    temperature=0.8,
)
2. Finally, plug it into your agent like this:
Copy code
session = AgentSession(
    llm=azure_llm,
    # ... and don’t forget your other parts like stt, tts, vad, etc.
)
Just double-check that the deployment name (
azure_deployment
) exactly matches what you named your
gpt-4o-mini
model in the Azure portal. If you hit any snags or want a hand with anything else, just give me a shout—I’m here to help! Sources: OpenAI LLM integration guide | LiveKit Docs | OpenAI compatible LLMs | LiveKit Docs | Azure integration guide | LiveKit Docs | Large language model (LLM) integrations | LiveKit Docs