3
3
from typing import cast
4
4
5
5
import openai
6
- from openai import api_requestor , util , error
6
+ from openai import api_requestor , util
7
7
from openai .api_resources .abstract import DeletableAPIResource , ListableAPIResource
8
- from openai .util import ApiType
9
8
10
9
11
10
class File (ListableAPIResource , DeletableAPIResource ):
@@ -19,7 +18,6 @@ def create(
19
18
model = None ,
20
19
api_key = None ,
21
20
api_base = None ,
22
- api_type = None ,
23
21
api_version = None ,
24
22
organization = None ,
25
23
user_provided_filename = None ,
@@ -29,61 +27,35 @@ def create(
29
27
requestor = api_requestor .APIRequestor (
30
28
api_key ,
31
29
api_base = api_base or openai .api_base ,
32
- api_type = api_type ,
33
30
api_version = api_version ,
34
31
organization = organization ,
35
32
)
36
- typed_api_type , api_version = cls ._get_api_type_and_version (api_type , api_version )
37
-
38
- if typed_api_type == ApiType .AZURE :
39
- base = cls .class_url ()
40
- url = "/%s%s?api-version=%s" % (cls .azure_api_prefix , base , api_version )
41
- elif typed_api_type == ApiType .OPEN_AI :
42
- url = cls .class_url ()
43
- else :
44
- raise error .InvalidAPIType ('Unsupported API type %s' % api_type )
45
-
33
+ url = cls .class_url ()
46
34
# Set the filename on 'purpose' and 'model' to None so they are
47
35
# interpreted as form data.
48
36
files = [("purpose" , (None , purpose ))]
49
37
if model is not None :
50
38
files .append (("model" , (None , model )))
51
39
if user_provided_filename is not None :
52
- files .append (("file" , (user_provided_filename , file , 'application/octet-stream' )))
40
+ files .append (("file" , (user_provided_filename , file )))
53
41
else :
54
- files .append (("file" , file , 'application/octet-stream' ))
42
+ files .append (("file" , file ))
55
43
response , _ , api_key = requestor .request ("post" , url , files = files )
56
44
return util .convert_to_openai_object (
57
45
response , api_key , api_version , organization
58
46
)
59
47
60
48
@classmethod
61
49
def download (
62
- cls ,
63
- id ,
64
- api_key = None ,
65
- api_base = None ,
66
- api_type = None ,
67
- api_version = None ,
68
- organization = None
50
+ cls , id , api_key = None , api_base = None , api_version = None , organization = None
69
51
):
70
52
requestor = api_requestor .APIRequestor (
71
53
api_key ,
72
54
api_base = api_base or openai .api_base ,
73
- api_type = api_type ,
74
55
api_version = api_version ,
75
56
organization = organization ,
76
57
)
77
- typed_api_type , api_version = cls ._get_api_type_and_version (api_type , api_version )
78
-
79
- if typed_api_type == ApiType .AZURE :
80
- base = cls .class_url ()
81
- url = "/%s%s/%s/content?api-version=%s" % (cls .azure_api_prefix , base , id , api_version )
82
- elif typed_api_type == ApiType .OPEN_AI :
83
- url = f"{ cls .class_url ()} /{ id } /content"
84
- else :
85
- raise error .InvalidAPIType ('Unsupported API type %s' % api_type )
86
-
58
+ url = f"{ cls .class_url ()} /{ id } /content"
87
59
result = requestor .request_raw ("get" , url )
88
60
if not 200 <= result .status_code < 300 :
89
61
raise requestor .handle_error_response (
@@ -103,15 +75,13 @@ def find_matching_files(
103
75
purpose ,
104
76
api_key = None ,
105
77
api_base = None ,
106
- api_type = None ,
107
78
api_version = None ,
108
79
organization = None ,
109
80
):
110
81
"""Find already uploaded files with the same name, size, and purpose."""
111
82
all_files = cls .list (
112
83
api_key = api_key ,
113
84
api_base = api_base or openai .api_base ,
114
- api_type = api_type ,
115
85
api_version = api_version ,
116
86
organization = organization ,
117
87
).get ("data" , [])
@@ -123,9 +93,7 @@ def find_matching_files(
123
93
file_basename = os .path .basename (f ["filename" ])
124
94
if file_basename != basename :
125
95
continue
126
- if "bytes" in f and f ["bytes" ] != bytes :
127
- continue
128
- if "size" in f and int (f ["size" ]) != bytes :
96
+ if f ["bytes" ] != bytes :
129
97
continue
130
98
matching_files .append (f )
131
99
return matching_files
0 commit comments