openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.30.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/azure.py

43lines · modeblame

08b8179aDavid Schnurr2 years ago1from openai import AzureOpenAI
2
3# may change in the future
4# https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning
5api_version = "2023-07-01-preview"
6
7# gets the API Key from environment variable AZURE_OPENAI_API_KEY
8client = AzureOpenAI(
9api_version=api_version,
10# https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource
11azure_endpoint="https://example-endpoint.openai.azure.com",
12)
13
14completion = client.chat.completions.create(
15model="deployment-name", # e.g. gpt-35-instant
16messages=[
17{
18"role": "user",
19"content": "How do I output all files in a directory using Python?",
20},
21],
22)
47656567Stainless Bot2 years ago23print(completion.to_json())
08b8179aDavid Schnurr2 years ago24
25
26deployment_client = AzureOpenAI(
27api_version=api_version,
28# https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource
29azure_endpoint="https://example-resource.azure.openai.com/",
30# Navigate to the Azure OpenAI Studio to deploy a model.
31azure_deployment="deployment-name", # e.g. gpt-35-instant
32)
33
34completion = deployment_client.chat.completions.create(
35model="<ignored>",
36messages=[
37{
38"role": "user",
39"content": "How do I output all files in a directory using Python?",
40},
41],
42)
47656567Stainless Bot2 years ago43print(completion.to_json())