mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
feat(core): impute placeholder filenames for OpenAI file inputs (#36433)
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user