feat(core): impute placeholder filenames for OpenAI file inputs (#36433)

This commit is contained in:
ccurme
2026-04-01 14:41:53 -04:00
committed by GitHub
parent 86238a775e
commit bdfd4462ac
4 changed files with 71 additions and 101 deletions

View File

@@ -854,17 +854,19 @@ def test_format_message_content() -> None:
for content in contents:
assert expected == _format_message_content([content])
# Test warn if PDF is missing a filename
# Test warn if PDF is missing a filename and that we add a default filename
pdf_block = {
"type": "file",
"base64": "<base64 data>",
"mime_type": "application/pdf",
}
expected = [
# N.B. this format is invalid for OpenAI
{
"type": "file",
"file": {"file_data": "data:application/pdf;base64,<base64 data>"},
"file": {
"file_data": "data:application/pdf;base64,<base64 data>",
"filename": "LC_AUTOGENERATED",
},
}
]
with pytest.warns(match="filename"):
@@ -3530,6 +3532,61 @@ def test_context_overflow_error_backwards_compatibility() -> None:
assert isinstance(exc_info.value, ContextOverflowError)
def test_get_request_payload_responses_api_input_file_blocks_passthrough() -> None:
llm = ChatOpenAI(model="gpt-5", use_responses_api=True)
payload = llm._get_request_payload(
[
HumanMessage(
content=[
{
"type": "input_text",
"text": "Analyze the letter and summarize key points.",
},
{
"type": "input_file",
"file_url": "https://www.berkshirehathaway.com/letters/2024ltr.pdf",
},
{
"type": "input_file",
"file_id": "file-6F2ksmvXxt4VdoqmHRw6kL",
},
{
"type": "input_file",
"filename": "draconomicon.pdf",
"file_data": "data:application/pdf;base64,Zm9v",
},
]
)
]
)
assert payload["input"] == [
{
"type": "message",
"role": "user",
"content": [
{
"type": "input_text",
"text": "Analyze the letter and summarize key points.",
},
{
"type": "input_file",
"file_url": "https://www.berkshirehathaway.com/letters/2024ltr.pdf",
},
{
"type": "input_file",
"file_id": "file-6F2ksmvXxt4VdoqmHRw6kL",
},
{
"type": "input_file",
"filename": "draconomicon.pdf",
"file_data": "data:application/pdf;base64,Zm9v",
},
],
}
]
def test_tool_search_passthrough() -> None:
"""Test that tool_search dict is passed through as a built-in tool."""
llm = ChatOpenAI(model="gpt-4o")