Skip to content

Commit ce8d023

Browse files
authored
Add files via upload
1 parent 4c20879 commit ce8d023

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from openai import AzureOpenAI
2+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
3+
import os
4+
from dotenv import load_dotenv
5+
load_dotenv()
6+
7+
token_provider = get_bearer_token_provider(
8+
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
9+
)
10+
11+
client = AzureOpenAI(
12+
base_url = os.getenv("AZURE_OPENAI_V1_API_ENDPOINT"),
13+
azure_ad_token_provider=token_provider,
14+
api_version="preview"
15+
)
16+
17+
# Upload a file with a purpose of "batch"
18+
file = client.files.create(
19+
file=open("employee_handbook.pdf", "rb"), # This assumes a .pdf file in the same directory as the executing script
20+
purpose="assistants"
21+
)
22+
23+
response = client.responses.create(
24+
model=os.environ["AZURE_OPENAI_API_MODEL"],
25+
input=[
26+
{
27+
"role": "user",
28+
"content": [
29+
{
30+
"type": "input_file",
31+
"file_id":file.id
32+
},
33+
{
34+
"type": "input_text",
35+
"text": "What are the company values?",
36+
},
37+
],
38+
},
39+
]
40+
)
41+
42+
print(response.output_text)

0 commit comments

Comments
 (0)