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:
ccurme
2025-04-17 08:48:46 -04:00
committed by GitHub
parent 83b66cb916
commit 86d51f6be6
7 changed files with 27 additions and 17 deletions

View File

@@ -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

View File

@@ -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?"},
]