mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-16 08:06:14 +00:00
fix
This commit is contained in:
parent
733da01bd4
commit
513e75ff75
@ -108,6 +108,7 @@ from uuid import uuid4
|
|||||||
|
|
||||||
from typing_extensions import NotRequired, TypedDict, TypeGuard, get_args, get_origin
|
from typing_extensions import NotRequired, TypedDict, TypeGuard, get_args, get_origin
|
||||||
|
|
||||||
|
|
||||||
def _ensure_id(id_val: Optional[str]) -> str:
|
def _ensure_id(id_val: Optional[str]) -> str:
|
||||||
"""Ensure the ID is a valid string, generating a new UUID if not provided.
|
"""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)
|
+ AIMessageChunk(content="", tool_call_chunks=right_chunks)
|
||||||
).tool_call_chunks == [ToolCallChunk(name='foo', args='{"a":1}', index=0)]
|
).tool_call_chunks == [ToolCallChunk(name='foo', args='{"a":1}', index=0)]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO: Consider making fields NotRequired[str] in the future.
|
# TODO: Consider making fields NotRequired[str] in the future.
|
||||||
|
|
||||||
type: NotRequired[Literal["tool_call_chunk"]]
|
type: NotRequired[Literal["tool_call_chunk"]]
|
||||||
@ -584,9 +586,6 @@ class ImageContentBlock(TypedDict):
|
|||||||
"""Provider-specific metadata."""
|
"""Provider-specific metadata."""
|
||||||
|
|
||||||
|
|
||||||
class VideoContentBlock(TypedDict):
|
|
||||||
"""Video data.
|
|
||||||
|
|
||||||
class VideoContentBlock(TypedDict):
|
class VideoContentBlock(TypedDict):
|
||||||
"""Video data.
|
"""Video data.
|
||||||
|
|
||||||
@ -763,7 +762,7 @@ class FileContentBlock(TypedDict):
|
|||||||
|
|
||||||
mime_type: NotRequired[str]
|
mime_type: NotRequired[str]
|
||||||
"""MIME type of the file. Required for base64.
|
"""MIME type of the file. Required for base64.
|
||||||
|
|
||||||
`Examples from IANA <https://www.iana.org/assignments/media-types/media-types.xhtml>`__
|
`Examples from IANA <https://www.iana.org/assignments/media-types/media-types.xhtml>`__
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -822,49 +821,6 @@ class NonStandardContentBlock(TypedDict):
|
|||||||
"""Index of block in aggregate response. Used during streaming."""
|
"""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 ---
|
# --- Aliases ---
|
||||||
DataContentBlock = Union[
|
DataContentBlock = Union[
|
||||||
ImageContentBlock,
|
ImageContentBlock,
|
||||||
@ -999,6 +955,7 @@ def is_invalid_tool_call_block(
|
|||||||
"""Type guard to check if a content block is an invalid tool call."""
|
"""Type guard to check if a content block is an invalid tool call."""
|
||||||
return block.get("type") == "invalid_tool_call"
|
return block.get("type") == "invalid_tool_call"
|
||||||
|
|
||||||
|
|
||||||
def convert_to_openai_image_block(block: dict[str, Any]) -> dict:
|
def convert_to_openai_image_block(block: dict[str, Any]) -> dict:
|
||||||
"""Convert image content block to format expected by OpenAI Chat Completions API."""
|
"""Convert image content block to format expected by OpenAI Chat Completions API."""
|
||||||
if "url" in block:
|
if "url" in block:
|
||||||
|
Loading…
Reference in New Issue
Block a user