Azure OpenAI GPT 4.1

Add the following code to your Python file

1from kern.agent import Agent
2from kern.models.azure.openai_chat import AzureOpenAI
3
4agent = Agent(
5 model=AzureOpenAI(id="gpt-5.2"),
6 reasoning_model=AzureOpenAI(id="gpt-5.2")
7)
8agent.print_response(
9 "Solve the trolley problem. Evaluate multiple ethical frameworks. "
10 "Include an ASCII diagram of your solution.",
11 stream=True,
12)

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Install dependencies

1uv pip install -U openai kern-ai

Set your Azure OpenAI credentials

1export AZURE_OPENAI_API_KEY="xxx"
2 export AZURE_OPENAI_ENDPOINT="xxx"
3 export AZURE_DEPLOYMENT="xxx"
1$Env:AZURE_OPENAI_API_KEY="xxx"
2$Env:AZURE_OPENAI_ENDPOINT="xxx"
3$Env:AZURE_DEPLOYMENT="xxx"

Run Agent

1python azure_openai.py