FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openai-python/examples/azure_ad.py at main · yaohwang/openai-python · GitHub
yaohwang
/
openai-python
Public
forked from
openai/openai-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openai-python
/
examples
/
azure_ad.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
30 lines (23 loc) · 967 Bytes
Breadcrumbs
openai-python
/
examples
/
azure_ad.py
Copy path
File metadata and controls
executable file
·
30 lines (23 loc) · 967 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from
azure
.
identity
import
DefaultAzureCredential
,
get_bearer_token_provider
from
openai
import
AzureOpenAI
token_provider
=
get_bearer_token_provider
(
DefaultAzureCredential
(),
"https://cognitiveservices.azure.com/.default"
)
# may change in the future
# https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning
api_version
=
"2023-07-01-preview"
# https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource
endpoint
=
"https://my-resource.openai.azure.com"
client
=
AzureOpenAI
(
api_version
=
api_version
,
azure_endpoint
=
endpoint
,
azure_ad_token_provider
=
token_provider
,
)
completion
=
client
.
chat
.
completions
.
create
(
model
=
"deployment-name"
,
# e.g. gpt-35-instant
messages
=
[
{
"role"
:
"user"
,
"content"
:
"How do I output all files in a directory using Python?"
,
},
],
)
print
(
completion
.
to_json
())
Back
|
FazBrowse Home
|
New Git URL