Skip to content

Support for file_input content (#fix 893) #1009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025
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