mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-22 23:00:00 +00:00
update core
This commit is contained in:
parent
4556b81b1d
commit
99646c143d
@ -27,6 +27,10 @@ from langchain_core.messages.base import (
|
||||
messages_to_dict,
|
||||
)
|
||||
from langchain_core.messages.chat import ChatMessage, ChatMessageChunk
|
||||
from langchain_core.messages.content_blocks import (
|
||||
DataContentBlock,
|
||||
is_data_content_block,
|
||||
)
|
||||
from langchain_core.messages.function import FunctionMessage, FunctionMessageChunk
|
||||
from langchain_core.messages.human import HumanMessage, HumanMessageChunk
|
||||
from langchain_core.messages.modifier import RemoveMessage
|
||||
@ -60,6 +64,7 @@ __all__ = [
|
||||
"BaseMessageChunk",
|
||||
"ChatMessage",
|
||||
"ChatMessageChunk",
|
||||
"DataContentBlock",
|
||||
"FunctionMessage",
|
||||
"FunctionMessageChunk",
|
||||
"HumanMessage",
|
||||
@ -76,6 +81,7 @@ __all__ = [
|
||||
"_message_from_dict",
|
||||
"convert_to_messages",
|
||||
"get_buffer_string",
|
||||
"is_data_content_block",
|
||||
"merge_content",
|
||||
"message_chunk_to_message",
|
||||
"message_to_dict",
|
||||
|
35
libs/core/langchain_core/messages/content_blocks.py
Normal file
35
libs/core/langchain_core/messages/content_blocks.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""Types for content blocks."""
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from typing_extensions import Required, TypedDict
|
||||
|
||||
|
||||
class DataContentBlock(TypedDict, total=False):
|
||||
"""Data content block."""
|
||||
|
||||
type: Required[Literal["image", "audio", "file"]]
|
||||
"""Type of the content block."""
|
||||
source_type: Required[Literal["url", "base64", "id", "text"]]
|
||||
"""Source type."""
|
||||
source: Required[str]
|
||||
"""Data as a URL or data-URI, identifier, or plain-text."""
|
||||
mime_type: str
|
||||
"""MIME type of the content block (if block represents base64 data.)"""
|
||||
metadata: dict
|
||||
"""Provider-specific metadata such as citations or filenames."""
|
||||
|
||||
|
||||
def is_data_content_block(
|
||||
content_block: dict,
|
||||
) -> bool:
|
||||
"""Check if the content block is a data content block.
|
||||
|
||||
Args:
|
||||
content_block: The content block to check.
|
||||
|
||||
Returns:
|
||||
True if the content block is a data content block, False otherwise.
|
||||
"""
|
||||
required_keys = DataContentBlock.__required_keys__
|
||||
return all(required_key in content_block for required_key in required_keys)
|
Loading…
Reference in New Issue
Block a user