AzureOpenAIClient client

This notebook demonstrates how to instantiate the AzureOpenAIClient object. AzureOpenAIClient is a subclass of the BaseLLMClient Abstract class.

For more thorough look at AzureOpenAIClient’s structure, look to the AzureOpenAIClient or BaseLLMClient API reference.

Setting up the Client

To set up the Azure OpenAI Client there are 4 required parameters:

  • your project Azure OpenAI API Key

  • a valid OpenAI model

  • the api version of your project

  • the endpoint to your project

All of this can be set up and found at the Azure AI Foundry

[ ]:
from ai_sentinel import AzureOpenAIClient

# Initialize an Azure OpenAI LLM Client
client = AzureOpenAIClient(
    api_key="YOUR_API_KEY",
    model="gpt-4o-mini",
    api_version="2024-02-01",
    azure_endpoint="https://your-resource.openai.azure.com/"
)

Once the Client is set up, all further usage in the code will be with the ToxicityGuard

Environment variable names

The following is the recommended format to follow for key naming convention when working with Azure OpenAI

[ ]:
AZURE_API_KEY='YOUR_API_KEY'
AZURE_API_BASE='https://your-resource.openai.azure.com/'
AZURE_API_VERSION='2024-12-01-preview'