FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openai-python/examples/uploads.py at main · baballev/openai-python · GitHub
baballev
/
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
/
uploads.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
46 lines (33 loc) · 886 Bytes
Breadcrumbs
openai-python
/
examples
/
uploads.py
Copy path
File metadata and controls
46 lines (33 loc) · 886 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
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
()
Back
|
FazBrowse Home
|
New Git URL