File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 19
19
ChatCompletionToolMessageParam ,
20
20
ChatCompletionUserMessageParam ,
21
21
)
22
+ from openai .types .chat .chat_completion_content_part_param import File , FileFile
22
23
from openai .types .chat .chat_completion_tool_param import ChatCompletionToolParam
23
24
from openai .types .chat .completion_create_params import ResponseFormat
24
25
from openai .types .responses import (
27
28
ResponseFunctionToolCall ,
28
29
ResponseFunctionToolCallParam ,
29
30
ResponseInputContentParam ,
31
+ ResponseInputFileParam ,
30
32
ResponseInputImageParam ,
31
33
ResponseInputTextParam ,
32
34
ResponseOutputMessage ,
@@ -251,7 +253,19 @@ def extract_all_content(
251
253
)
252
254
)
253
255
elif isinstance (c , dict ) and c .get ("type" ) == "input_file" :
254
- raise UserError (f"File uploads are not supported for chat completions { c } " )
256
+ casted_file_param = cast (ResponseInputFileParam , c )
257
+ if "file_data" not in casted_file_param or not casted_file_param ["file_data" ]:
258
+ raise UserError (
259
+ f"Only file_data is supported for input_file { casted_file_param } "
260
+ )
261
+ out .append (
262
+ File (
263
+ type = "file" ,
264
+ file = FileFile (
265
+ file_data = casted_file_param ["file_data" ],
266
+ ),
267
+ )
268
+ )
255
269
else :
256
270
raise UserError (f"Unknown content: { c } " )
257
271
return out
You can’t perform that action at this time.
0 commit comments