Skip to content

Commit 7e1742b

Browse files
committed
[Add] Azure OpenAPI Python example
1 parent 3342d24 commit 7e1742b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

azure-openapi/basic-api/main.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
from openai import AzureOpenAI
3+
4+
endpoint = "<your-endpoint>"
5+
model_name = "o4-mini"
6+
deployment = "o4-mini"
7+
8+
subscription_key = os.getenv("AZURE_OPENAI_API_KEY")
9+
api_version = "2024-12-01-preview"
10+
11+
client = AzureOpenAI(
12+
api_version=api_version,
13+
azure_endpoint=endpoint,
14+
api_key=subscription_key,
15+
)
16+
17+
response = client.chat.completions.create(
18+
messages=[
19+
{
20+
"role": "system",
21+
"content": "You are a senior DevOps engineer helping beginners.",
22+
},
23+
{
24+
"role": "user",
25+
"content": "How do I set up CI/CD using GitHub Actions for a Node.js app?",
26+
}
27+
],
28+
max_completion_tokens=100000,
29+
model=deployment
30+
)
31+
32+
print(response.choices[0].message.content)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openai~=1.60.2

0 commit comments

Comments
 (0)