Add file data type support

This commit is contained in:
Tao Chen
2026-04-24 12:04:58 -07:00
Unverified
parent 334ce4dfe0
commit 2c6aa98b18
2 changed files with 43 additions and 0 deletions
@@ -1117,6 +1117,8 @@ def _convert_message_content(content: MessageContent) -> Content:
return Content.from_uri(file.file_url)
if file.file_id:
return Content.from_hosted_file(file.file_id, name=file.filename)
if file.file_data:
return Content.from_uri(file.file_data)
if content.type == "computer_screenshot":
screenshot = cast(ComputerScreenshotContent, content)
return Content.from_uri(screenshot.image_url)
@@ -1507,6 +1507,47 @@ class TestMultiTurnMixedContent:
assert messages[0].contents[1].type == "uri"
assert messages[0].contents[1].uri == "https://example.com/doc.pdf"
async def test_text_and_file_data_input_single_turn(self) -> None:
"""Agent receives a message with text and file content via inline file_data."""
agent = _make_agent(
response=AgentResponse(messages=[Message(role="assistant", contents=[Content.from_text("File received")])])
)
server = _make_server(agent)
resp = await _post_json(
server,
{
"model": "test-model",
"input": [
{
"type": "message",
"role": "user",
"content": [
{"type": "input_text", "text": "Summarize this document"},
{
"type": "input_file",
"file_data": "data:application/pdf;base64,JVBERi0xLjQ=",
"filename": "doc.pdf",
},
],
}
],
"stream": False,
},
)
assert resp.status_code == 200
body = resp.json()
assert body["status"] == "completed"
messages = agent.run.call_args.kwargs["messages"]
assert len(messages) == 1
assert len(messages[0].contents) == 2
assert messages[0].contents[0].type == "text"
assert messages[0].contents[0].text == "Summarize this document"
assert messages[0].contents[1].type == "data"
assert messages[0].contents[1].uri == "data:application/pdf;base64,JVBERi0xLjQ="
async def test_mixed_text_and_image_input(self) -> None:
"""Agent receives a single message with both text and image content."""
agent = _make_agent(