mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 18:50:33 +00:00
multiple: permit optional fields on multimodal content blocks (#30887)
Instead of stuffing provider-specific fields in `metadata`, they can go directly on the content block.
This commit is contained in:
@@ -194,14 +194,16 @@ def _format_data_content_block(block: dict) -> dict:
|
||||
elif block["type"] == "file":
|
||||
if block["source_type"] == "base64":
|
||||
file = {"file_data": f"data:{block['mime_type']};base64,{block['data']}"}
|
||||
if (metadata := block.get("metadata")) and ("filename" in metadata):
|
||||
if filename := block.get("filename"):
|
||||
file["filename"] = filename
|
||||
elif (metadata := block.get("metadata")) and ("filename" in metadata):
|
||||
file["filename"] = metadata["filename"]
|
||||
else:
|
||||
warnings.warn(
|
||||
"OpenAI may require a filename for file inputs. Specify a filename "
|
||||
"in the metadata: {'type': 'file', 'source_type': 'base64', "
|
||||
"in the content block: {'type': 'file', 'source_type': 'base64', "
|
||||
"'mime_type': 'application/pdf', 'data': '...', "
|
||||
"'metadata': {'filename': 'my-pdf'}}"
|
||||
"'filename': 'my-pdf'}"
|
||||
)
|
||||
formatted_block = {"type": "file", "file": file}
|
||||
elif block["source_type"] == "id":
|
||||
|
||||
@@ -96,7 +96,7 @@ class TestOpenAIStandard(ChatModelIntegrationTests):
|
||||
"source_type": "base64",
|
||||
"mime_type": "application/pdf",
|
||||
"data": pdf_data,
|
||||
"metadata": {"filename": "my-pdf"}, # OpenAI requires a filename
|
||||
"filename": "my-pdf", # OpenAI requires a filename
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
@@ -676,7 +676,7 @@ def test_format_message_content() -> None:
|
||||
"source_type": "base64",
|
||||
"data": "<base64 data>",
|
||||
"mime_type": "application/pdf",
|
||||
"metadata": {"filename": "my_file"},
|
||||
"filename": "my_file",
|
||||
}
|
||||
]
|
||||
expected = [
|
||||
|
||||
Reference in New Issue
Block a user