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

@@ -6,13 +6,11 @@ from pydantic import TypeAdapter, ValidationError
from typing_extensions import NotRequired, TypedDict
class BaseDataContentBlock(TypedDict):
class BaseDataContentBlock(TypedDict, total=False):
"""Base class for data content blocks."""
mime_type: NotRequired[str]
"""MIME type of the content block (if needed)."""
metadata: NotRequired[dict]
"""Provider-specific metadata such as citations or filenames."""
class URLContentBlock(BaseDataContentBlock):

View File

@@ -1107,6 +1107,15 @@ def test_is_data_content_block() -> None:
"mime_type": "image/jpeg",
}
)
assert is_data_content_block(
{
"type": "image",
"source_type": "base64",
"data": "<base64 data>",
"mime_type": "image/jpeg",
"cache_control": {"type": "ephemeral"},
}
)
assert is_data_content_block(
{
"type": "image",
@@ -1148,7 +1157,7 @@ def test_convert_to_openai_image_block() -> None:
"type": "image",
"source_type": "url",
"url": "https://...",
"metadata": {"cache_control": {"type": "ephemeral"}},
"cache_control": {"type": "ephemeral"},
}
expected = {
"type": "image_url",
@@ -1162,7 +1171,7 @@ def test_convert_to_openai_image_block() -> None:
"source_type": "base64",
"data": "<base64 data>",
"mime_type": "image/jpeg",
"metadata": {"cache_control": {"type": "ephemeral"}},
"cache_control": {"type": "ephemeral"},
}
expected = {
"type": "image_url",