Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/agents/models/chatcmpl_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ChatCompletionToolMessageParam,
ChatCompletionUserMessageParam,
)
from openai.types.chat.chat_completion_content_part_param import File, FileFile
from openai.types.chat.chat_completion_tool_param import ChatCompletionToolParam
from openai.types.chat.completion_create_params import ResponseFormat
from openai.types.responses import (
Expand All @@ -27,6 +28,7 @@
ResponseFunctionToolCall,
ResponseFunctionToolCallParam,
ResponseInputContentParam,
ResponseInputFileParam,
ResponseInputImageParam,
ResponseInputTextParam,
ResponseOutputMessage,
Expand Down Expand Up @@ -251,7 +253,19 @@ def extract_all_content(
)
)
elif isinstance(c, dict) and c.get("type") == "input_file":
raise UserError(f"File uploads are not supported for chat completions {c}")
casted_file_param = cast(ResponseInputFileParam, c)
if "file_data" not in casted_file_param or not casted_file_param["file_data"]:
raise UserError(
f"Only file_data is supported for input_file {casted_file_param}"
)
out.append(
File(
type="file",
file=FileFile(
file_data=casted_file_param["file_data"],
),
)
)
else:
raise UserError(f"Unknown content: {c}")
return out
Expand Down