-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathuploads.py
46 lines (33 loc) · 886 Bytes
/
uploads.py
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
42
43
44
45
46
import sys
from pathlib import Path
import rich
from openai import OpenAI
# generate this file using `./generate_file.sh`
file = Path("/tmp/big_test_file.txt")
client = OpenAI()
def from_disk() -> None:
print("uploading file from disk")
upload = client.uploads.upload_file_chunked(
file=file,
mime_type="txt",
purpose="batch",
)
rich.print(upload)
def from_in_memory() -> None:
print("uploading file from memory")
# read the data into memory ourselves to simulate
# it coming from somewhere else
data = file.read_bytes()
filename = "my_file.txt"
upload = client.uploads.upload_file_chunked(
file=data,
filename=filename,
bytes=len(data),
mime_type="txt",
purpose="batch",
)
rich.print(upload)
if "memory" in sys.argv:
from_in_memory()
else:
from_disk()