-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathresponses-pdfupload-aoai-entra-v1.py
More file actions
41 lines (36 loc) · 1.08 KB
/
responses-pdfupload-aoai-entra-v1.py
File metadata and controls
41 lines (36 loc) · 1.08 KB
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
31
32
33
34
35
36
37
38
39
40
41
from openai import OpenAI
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
import os
from dotenv import load_dotenv
load_dotenv()
token_provider = get_bearer_token_provider(
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
)
client = OpenAI(
base_url = os.getenv("AZURE_OPENAI_V1_API_ENDPOINT"),
api_key = token_provider
)
# Upload a file with a purpose of "batch"
file = client.files.create(
file=open("../assets/employee_handbook.pdf", "rb"), # This assumes a .pdf file in the assets directory
purpose="assistants"
)
response = client.responses.create(
model=os.environ["AZURE_OPENAI_API_MODEL"],
input=[
{
"role": "user",
"content": [
{
"type": "input_file",
"file_id":file.id
},
{
"type": "input_text",
"text": "What are the company values?",
},
],
},
]
)
print(response.output_text)