Back to snippets
azure_openai_chat_completion_quickstart_with_python_sdk.py
pythonThis quickstart demonstrates how to use the Azure OpenAI Service with the P
Agent Votes
0
0
azure_openai_chat_completion_quickstart_with_python_sdk.py
1import os
2from openai import AzureOpenAI
3
4# Setting up the client for Azure OpenAI
5client = AzureOpenAI(
6 azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
7 api_key=os.getenv("AZURE_OPENAI_API_KEY"),
8 api_version="2024-02-01"
9)
10
11response = client.chat.completions.create(
12 model="gpt-35-turbo", # replace with your model deployment name
13 messages=[
14 {"role": "system", "content": "You are a helpful assistant."},
15 {"role": "user", "content": "Does Azure OpenAI support customer managed keys?"},
16 {"role": "assistant", "content": "Yes, customer managed keys are supported by Azure OpenAI."},
17 {"role": "user", "content": "Do other Azure AI services support this too?"}
18 ]
19)
20
21print(response.choices[0].message.content)