mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-21 18:39:57 +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:
@@ -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):
|
||||
|
@@ -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",
|
||||
|
Reference in New Issue
Block a user