mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +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:
@@ -239,11 +239,12 @@ def _format_data_content_block(block: dict) -> dict:
|
||||
else:
|
||||
raise ValueError(f"Block of type {block['type']} is not supported.")
|
||||
|
||||
if formatted_block and (metadata := block.get("metadata")):
|
||||
if "cache_control" in metadata:
|
||||
formatted_block["cache_control"] = metadata["cache_control"]
|
||||
if "citations" in metadata:
|
||||
formatted_block["citations"] = metadata["citations"]
|
||||
if formatted_block:
|
||||
for key in ["cache_control", "citations", "title", "context"]:
|
||||
if key in block:
|
||||
formatted_block[key] = block[key]
|
||||
elif (metadata := block.get("metadata")) and key in metadata:
|
||||
formatted_block[key] = metadata[key]
|
||||
|
||||
return formatted_block
|
||||
|
||||
|
||||
@@ -703,7 +703,7 @@ def test__format_messages_with_cache_control() -> None:
|
||||
"source_type": "base64",
|
||||
"mime_type": "application/pdf",
|
||||
"data": "<base64 data>",
|
||||
"metadata": {"cache_control": {"type": "ephemeral"}},
|
||||
"cache_control": {"type": "ephemeral"},
|
||||
},
|
||||
]
|
||||
)
|
||||
@@ -742,7 +742,7 @@ def test__format_messages_with_citations() -> None:
|
||||
"source_type": "text",
|
||||
"text": "The grass is green. The sky is blue.",
|
||||
"mime_type": "text/plain",
|
||||
"metadata": {"citations": {"enabled": True}},
|
||||
"citations": {"enabled": True},
|
||||
},
|
||||
{"type": "text", "text": "What color is the grass and sky?"},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user