From 513e75ff75ec5d7b9c97c9387486d7fa61fb5e2f Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Tue, 5 Aug 2025 16:09:17 -0400 Subject: [PATCH] fix --- .../langchain_core/messages/content_blocks.py | 51 ++----------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/libs/core/langchain_core/messages/content_blocks.py b/libs/core/langchain_core/messages/content_blocks.py index 57ce608ff8e..ed45c77bb6e 100644 --- a/libs/core/langchain_core/messages/content_blocks.py +++ b/libs/core/langchain_core/messages/content_blocks.py @@ -108,6 +108,7 @@ from uuid import uuid4 from typing_extensions import NotRequired, TypedDict, TypeGuard, get_args, get_origin + def _ensure_id(id_val: Optional[str]) -> str: """Ensure the ID is a valid string, generating a new UUID if not provided. @@ -313,6 +314,7 @@ class ToolCallChunk(TypedDict): + AIMessageChunk(content="", tool_call_chunks=right_chunks) ).tool_call_chunks == [ToolCallChunk(name='foo', args='{"a":1}', index=0)] """ + # TODO: Consider making fields NotRequired[str] in the future. type: NotRequired[Literal["tool_call_chunk"]] @@ -584,9 +586,6 @@ class ImageContentBlock(TypedDict): """Provider-specific metadata.""" -class VideoContentBlock(TypedDict): - """Video data. - class VideoContentBlock(TypedDict): """Video data. @@ -763,7 +762,7 @@ class FileContentBlock(TypedDict): mime_type: NotRequired[str] """MIME type of the file. Required for base64. - + `Examples from IANA `__ """ @@ -822,49 +821,6 @@ class NonStandardContentBlock(TypedDict): """Index of block in aggregate response. Used during streaming.""" -# --- Aliases --- - -# Future modalities to consider: -# - 3D models -# - Tabular data - - -class NonStandardContentBlock(TypedDict): - """Provider-specific data. - - This block contains data for which there is not yet a standard type. - - The purpose of this block should be to simply hold a provider-specific payload. - If a provider's non-standard output includes reasoning and tool calls, it should be - the adapter's job to parse that payload and emit the corresponding standard - ReasoningContentBlock and ToolCallContentBlocks. - - .. note:: - ``create_non_standard_block`` may also be used as a factory to create a - ``NonStandardContentBlock``. Benefits include: - - * Automatic ID generation (when not provided) - * Required arguments strictly validated at creation time - - """ - - type: Literal["non_standard"] - """Type of the content block. Used for discrimination.""" - - id: NotRequired[str] - """Content block identifier. Either: - - - Generated by the provider (e.g., OpenAI's file ID) - - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``)) - """ - - value: dict[str, Any] - """Provider-specific data.""" - - index: NotRequired[int] - """Index of block in aggregate response. Used during streaming.""" - - # --- Aliases --- DataContentBlock = Union[ ImageContentBlock, @@ -999,6 +955,7 @@ def is_invalid_tool_call_block( """Type guard to check if a content block is an invalid tool call.""" return block.get("type") == "invalid_tool_call" + def convert_to_openai_image_block(block: dict[str, Any]) -> dict: """Convert image content block to format expected by OpenAI Chat Completions API.""" if "url" in block: