From ee4d84de7cf10a2a3b1c69cda62a1395fa059def Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Wed, 24 Sep 2025 16:11:21 -0400 Subject: [PATCH] style(core): typo/docs lint pass (#33093) --- docs/docs/how_to/index.mdx | 4 +- .../language_models/chat_models.py | 2 +- .../language_models/fake_chat_models.py | 7 +- libs/core/langchain_core/messages/ai.py | 32 ++- libs/core/langchain_core/messages/base.py | 46 ++-- libs/core/langchain_core/messages/chat.py | 5 +- libs/core/langchain_core/messages/function.py | 14 +- libs/core/langchain_core/messages/human.py | 15 +- libs/core/langchain_core/messages/modifier.py | 1 + libs/core/langchain_core/messages/system.py | 11 +- libs/core/langchain_core/messages/tool.py | 43 +-- libs/core/langchain_core/messages/utils.py | 170 ++++++------ .../langchain_core/outputs/chat_generation.py | 16 +- libs/core/langchain_core/prompt_values.py | 8 +- .../prompts/__snapshots__/test_chat.ambr | 62 ++--- .../runnables/__snapshots__/test_graph.ambr | 31 +-- .../__snapshots__/test_runnable.ambr | 248 ++++++++---------- libs/core/tests/unit_tests/stubs.py | 9 +- libs/core/uv.lock | 4 +- 19 files changed, 387 insertions(+), 341 deletions(-) diff --git a/docs/docs/how_to/index.mdx b/docs/docs/how_to/index.mdx index 6420936bc76..5a78a7fddd6 100644 --- a/docs/docs/how_to/index.mdx +++ b/docs/docs/how_to/index.mdx @@ -72,7 +72,7 @@ See [supported integrations](/docs/integrations/chat/) for details on getting st ### Example selectors -[Example Selectors](/docs/concepts/example_selectors) are responsible for selecting the correct few shot examples to pass to the prompt. +[Example Selectors](/docs/concepts/example_selectors) are responsible for selecting the correct few-shot examples to pass to the prompt. - [How to: use example selectors](/docs/how_to/example_selectors) - [How to: select examples by length](/docs/how_to/example_selectors_length_based) @@ -168,7 +168,7 @@ See [supported integrations](/docs/integrations/vectorstores/) for details on ge Indexing is the process of keeping your vectorstore in-sync with the underlying data source. -- [How to: reindex data to keep your vectorstore in sync with the underlying data source](/docs/how_to/indexing) +- [How to: reindex data to keep your vectorstore in-sync with the underlying data source](/docs/how_to/indexing) ### Tools diff --git a/libs/core/langchain_core/language_models/chat_models.py b/libs/core/langchain_core/language_models/chat_models.py index 3bfa38449a1..109aef5095e 100644 --- a/libs/core/langchain_core/language_models/chat_models.py +++ b/libs/core/langchain_core/language_models/chat_models.py @@ -471,7 +471,7 @@ class BaseChatModel(BaseLanguageModel[BaseMessage], ABC): **kwargs: Any, ) -> Iterator[BaseMessageChunk]: if not self._should_stream(async_api=False, **{**kwargs, "stream": True}): - # model doesn't implement streaming, so use default implementation + # Model doesn't implement streaming, so use default implementation yield cast( "BaseMessageChunk", self.invoke(input, config=config, stop=stop, **kwargs), diff --git a/libs/core/langchain_core/language_models/fake_chat_models.py b/libs/core/langchain_core/language_models/fake_chat_models.py index 3b90259e525..7244db721ad 100644 --- a/libs/core/langchain_core/language_models/fake_chat_models.py +++ b/libs/core/langchain_core/language_models/fake_chat_models.py @@ -19,7 +19,7 @@ from langchain_core.runnables import RunnableConfig class FakeMessagesListChatModel(BaseChatModel): - """Fake ChatModel for testing purposes.""" + """Fake ``ChatModel`` for testing purposes.""" responses: list[BaseMessage] """List of responses to **cycle** through in order.""" @@ -212,10 +212,11 @@ class GenericFakeChatModel(BaseChatModel): """Generic fake chat model that can be used to test the chat model interface. * Chat model should be usable in both sync and async tests - * Invokes on_llm_new_token to allow for testing of callback related code for new + * Invokes ``on_llm_new_token`` to allow for testing of callback related code for new tokens. * Includes logic to break messages into message chunk to facilitate testing of streaming. + """ messages: Iterator[Union[AIMessage, str]] @@ -230,6 +231,7 @@ class GenericFakeChatModel(BaseChatModel): .. warning:: Streaming is not implemented yet. We should try to implement it in the future by delegating to invoke and then breaking the resulting output into message chunks. + """ @override @@ -351,6 +353,7 @@ class ParrotFakeChatModel(BaseChatModel): """Generic fake chat model that can be used to test the chat model interface. * Chat model should be usable in both sync and async tests + """ @override diff --git a/libs/core/langchain_core/messages/ai.py b/libs/core/langchain_core/messages/ai.py index e0208d5f5a3..100d9e1787b 100644 --- a/libs/core/langchain_core/messages/ai.py +++ b/libs/core/langchain_core/messages/ai.py @@ -45,7 +45,6 @@ class InputTokenDetails(TypedDict, total=False): Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -72,6 +71,7 @@ class InputTokenDetails(TypedDict, total=False): Since there was a cache hit, the tokens were read from the cache. More precisely, the model state given these tokens was read from the cache. + """ @@ -81,7 +81,6 @@ class OutputTokenDetails(TypedDict, total=False): Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -100,6 +99,7 @@ class OutputTokenDetails(TypedDict, total=False): Tokens generated by the model in a chain of thought process (i.e. by OpenAI's o1 models) that are not returned as part of model output. + """ @@ -109,7 +109,6 @@ class UsageMetadata(TypedDict): This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { @@ -148,6 +147,7 @@ class UsageMetadata(TypedDict): """Breakdown of output token counts. Does *not* need to sum to full output token count. Does *not* need to have all keys. + """ @@ -159,12 +159,14 @@ class AIMessage(BaseMessage): This message represents the output of the model and consists of both the raw output as returned by the model together standardized fields (e.g., tool calls, usage metadata) added by the LangChain framework. + """ example: bool = False """Use to denote that a message is part of an example conversation. At the moment, this is ignored by most models. Usage is discouraged. + """ tool_calls: list[ToolCall] = [] @@ -175,15 +177,18 @@ class AIMessage(BaseMessage): """If provided, usage metadata for a message, such as token counts. This is a standard representation of token usage that is consistent across models. + """ type: Literal["ai"] = "ai" - """The type of the message (used for deserialization). Defaults to "ai".""" + """The type of the message (used for deserialization). Defaults to ``'ai'``.""" def __init__( - self, content: Union[str, list[Union[str, dict]]], **kwargs: Any + self, + content: Union[str, list[Union[str, dict]]], + **kwargs: Any, ) -> None: - """Pass in content as positional arg. + """Initialize ``AIMessage``. Args: content: The content of the message. @@ -254,6 +259,7 @@ class AIMessage(BaseMessage): Returns: A pretty representation of the message. + """ base = super().pretty_repr(html=html) lines = [] @@ -293,7 +299,10 @@ class AIMessageChunk(AIMessage, BaseMessageChunk): # non-chunk variant. type: Literal["AIMessageChunk"] = "AIMessageChunk" # type: ignore[assignment] """The type of the message (used for deserialization). - Defaults to "AIMessageChunk".""" + + Defaults to ``AIMessageChunk``. + + """ tool_call_chunks: list[ToolCallChunk] = [] """If provided, tool call chunks associated with the message.""" @@ -311,7 +320,10 @@ class AIMessageChunk(AIMessage, BaseMessageChunk): """Initialize tool calls from tool call chunks. Returns: - This ``AIMessageChunk``. + The values with tool calls initialized. + + Raises: + ValueError: If the tool call chunks are malformed. """ if not self.tool_call_chunks: if self.tool_calls: @@ -522,9 +534,9 @@ def add_usage( def subtract_usage( left: Optional[UsageMetadata], right: Optional[UsageMetadata] ) -> UsageMetadata: - """Recursively subtract two UsageMetadata objects. + """Recursively subtract two ``UsageMetadata`` objects. - Token counts cannot be negative so the actual operation is max(left - right, 0). + Token counts cannot be negative so the actual operation is ``max(left - right, 0)``. Example: .. code-block:: python diff --git a/libs/core/langchain_core/messages/base.py b/libs/core/langchain_core/messages/base.py index 4b5b296614b..2bda8d5ca4e 100644 --- a/libs/core/langchain_core/messages/base.py +++ b/libs/core/langchain_core/messages/base.py @@ -20,7 +20,7 @@ if TYPE_CHECKING: class BaseMessage(Serializable): """Base abstract message class. - Messages are the inputs and outputs of ChatModels. + Messages are the inputs and outputs of ``ChatModel``s. """ content: Union[str, list[Union[str, dict]]] @@ -31,17 +31,18 @@ class BaseMessage(Serializable): For example, for a message from an AI, this could include tool calls as encoded by the model provider. + """ response_metadata: dict = Field(default_factory=dict) - """Response metadata. For example: response headers, logprobs, token counts, model - name.""" + """Examples: response headers, logprobs, token counts, model name.""" type: str """The type of the message. Must be a string that is unique to the message type. The purpose of this field is to allow for easy identification of the message type when deserializing messages. + """ name: Optional[str] = None @@ -51,20 +52,26 @@ class BaseMessage(Serializable): Usage of this field is optional, and whether it's used or not is up to the model implementation. + """ id: Optional[str] = Field(default=None, coerce_numbers_to_str=True) - """An optional unique identifier for the message. This should ideally be - provided by the provider/model which created the message.""" + """An optional unique identifier for the message. + + This should ideally be provided by the provider/model which created the message. + + """ model_config = ConfigDict( extra="allow", ) def __init__( - self, content: Union[str, list[Union[str, dict]]], **kwargs: Any + self, + content: Union[str, list[Union[str, dict]]], + **kwargs: Any, ) -> None: - """Pass in content as positional arg. + """Initialize ``BaseMessage``. Args: content: The string contents of the message. @@ -73,7 +80,7 @@ class BaseMessage(Serializable): @classmethod def is_lc_serializable(cls) -> bool: - """BaseMessage is serializable. + """``BaseMessage`` is serializable. Returns: True @@ -90,10 +97,11 @@ class BaseMessage(Serializable): return ["langchain", "schema", "messages"] def text(self) -> str: - """Get the text content of the message. + """Get the text ``content`` of the message. Returns: The text content of the message. + """ if isinstance(self.content, str): return self.content @@ -136,6 +144,7 @@ class BaseMessage(Serializable): Returns: A pretty representation of the message. + """ title = get_msg_title_repr(self.type.title() + " Message", bold=html) # TODO: handle non-string content. @@ -155,11 +164,12 @@ def merge_content( """Merge multiple message contents. Args: - first_content: The first content. Can be a string or a list. - contents: The other contents. Can be a string or a list. + first_content: The first ``content``. Can be a string or a list. + contents: The other ``content``s. Can be a string or a list. Returns: The merged content. + """ merged = first_content for content in contents: @@ -207,9 +217,10 @@ class BaseMessageChunk(BaseMessage): For example, - `AIMessageChunk(content="Hello") + AIMessageChunk(content=" World")` + ``AIMessageChunk(content="Hello") + AIMessageChunk(content=" World")`` + + will give ``AIMessageChunk(content="Hello World")`` - will give `AIMessageChunk(content="Hello World")` """ if isinstance(other, BaseMessageChunk): # If both are (subclasses of) BaseMessageChunk, @@ -257,8 +268,9 @@ def message_to_dict(message: BaseMessage) -> dict: message: Message to convert. Returns: - Message as a dict. The dict will have a "type" key with the message type - and a "data" key with the message data as a dict. + Message as a dict. The dict will have a ``type`` key with the message type + and a ``data`` key with the message data as a dict. + """ return {"type": message.type, "data": message.model_dump()} @@ -267,10 +279,11 @@ def messages_to_dict(messages: Sequence[BaseMessage]) -> list[dict]: """Convert a sequence of Messages to a list of dictionaries. Args: - messages: Sequence of messages (as BaseMessages) to convert. + messages: Sequence of messages (as ``BaseMessage``s) to convert. Returns: List of messages as dicts. + """ return [message_to_dict(m) for m in messages] @@ -284,6 +297,7 @@ def get_msg_title_repr(title: str, *, bold: bool = False) -> str: Returns: The title representation. + """ padded = " " + title + " " sep_len = (80 - len(padded)) // 2 diff --git a/libs/core/langchain_core/messages/chat.py b/libs/core/langchain_core/messages/chat.py index a4791423fad..35d7aafebfd 100644 --- a/libs/core/langchain_core/messages/chat.py +++ b/libs/core/langchain_core/messages/chat.py @@ -30,7 +30,10 @@ class ChatMessageChunk(ChatMessage, BaseMessageChunk): # non-chunk variant. type: Literal["ChatMessageChunk"] = "ChatMessageChunk" # type: ignore[assignment] """The type of the message (used during serialization). - Defaults to "ChatMessageChunk".""" + + Defaults to ``'ChatMessageChunk'``. + + """ @override def __add__(self, other: Any) -> BaseMessageChunk: # type: ignore[override] diff --git a/libs/core/langchain_core/messages/function.py b/libs/core/langchain_core/messages/function.py index fc1018775b7..770806ffb22 100644 --- a/libs/core/langchain_core/messages/function.py +++ b/libs/core/langchain_core/messages/function.py @@ -15,19 +15,20 @@ from langchain_core.utils._merge import merge_dicts class FunctionMessage(BaseMessage): """Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. + """ name: str """The name of the function that was executed.""" type: Literal["function"] = "function" - """The type of the message (used for serialization). Defaults to "function".""" + """The type of the message (used for serialization). Defaults to ``'function'``.""" class FunctionMessageChunk(FunctionMessage, BaseMessageChunk): @@ -38,7 +39,10 @@ class FunctionMessageChunk(FunctionMessage, BaseMessageChunk): # non-chunk variant. type: Literal["FunctionMessageChunk"] = "FunctionMessageChunk" # type: ignore[assignment] """The type of the message (used for serialization). - Defaults to "FunctionMessageChunk".""" + + Defaults to ``'FunctionMessageChunk'``. + + """ @override def __add__(self, other: Any) -> BaseMessageChunk: # type: ignore[override] diff --git a/libs/core/langchain_core/messages/human.py b/libs/core/langchain_core/messages/human.py index d6260cd14bd..3cc7b8135d8 100644 --- a/libs/core/langchain_core/messages/human.py +++ b/libs/core/langchain_core/messages/human.py @@ -8,7 +8,7 @@ from langchain_core.messages.base import BaseMessage, BaseMessageChunk class HumanMessage(BaseMessage): """Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -32,15 +32,22 @@ class HumanMessage(BaseMessage): At the moment, this is ignored by most models. Usage is discouraged. Defaults to False. + """ type: Literal["human"] = "human" - """The type of the message (used for serialization). Defaults to "human".""" + """The type of the message (used for serialization). + + Defaults to ``'human'``. + + """ def __init__( - self, content: Union[str, list[Union[str, dict]]], **kwargs: Any + self, + content: Union[str, list[Union[str, dict]]], + **kwargs: Any, ) -> None: - """Pass in content as positional arg. + """Initialize ``HumanMessage``. Args: content: The string contents of the message. diff --git a/libs/core/langchain_core/messages/modifier.py b/libs/core/langchain_core/messages/modifier.py index 5f1602a4908..94ce8356fb3 100644 --- a/libs/core/langchain_core/messages/modifier.py +++ b/libs/core/langchain_core/messages/modifier.py @@ -24,6 +24,7 @@ class RemoveMessage(BaseMessage): Raises: ValueError: If the 'content' field is passed in kwargs. + """ if kwargs.pop("content", None): msg = "RemoveMessage does not support 'content' field." diff --git a/libs/core/langchain_core/messages/system.py b/libs/core/langchain_core/messages/system.py index 491bea204ea..186ae02baf9 100644 --- a/libs/core/langchain_core/messages/system.py +++ b/libs/core/langchain_core/messages/system.py @@ -28,7 +28,11 @@ class SystemMessage(BaseMessage): """ type: Literal["system"] = "system" - """The type of the message (used for serialization). Defaults to "system".""" + """The type of the message (used for serialization). + + Defaults to ``'system'``. + + """ def __init__( self, content: Union[str, list[Union[str, dict]]], **kwargs: Any @@ -50,4 +54,7 @@ class SystemMessageChunk(SystemMessage, BaseMessageChunk): # non-chunk variant. type: Literal["SystemMessageChunk"] = "SystemMessageChunk" # type: ignore[assignment] """The type of the message (used for serialization). - Defaults to "SystemMessageChunk".""" + + Defaults to ``'SystemMessageChunk'``. + + """ diff --git a/libs/core/langchain_core/messages/tool.py b/libs/core/langchain_core/messages/tool.py index b2f858d8138..614d4f37023 100644 --- a/libs/core/langchain_core/messages/tool.py +++ b/libs/core/langchain_core/messages/tool.py @@ -14,19 +14,20 @@ from langchain_core.utils._merge import merge_dicts, merge_obj class ToolOutputMixin: """Mixin for objects that tools can return directly. - If a custom BaseTool is invoked with a ToolCall and the output of custom code is - not an instance of ToolOutputMixin, the output will automatically be coerced to a - string and wrapped in a ToolMessage. + If a custom BaseTool is invoked with a ``ToolCall`` and the output of custom code is + not an instance of ``ToolOutputMixin``, the output will automatically be coerced to + a string and wrapped in a ``ToolMessage``. + """ class ToolMessage(BaseMessage, ToolOutputMixin): """Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -35,7 +36,7 @@ class ToolMessage(BaseMessage, ToolOutputMixin): ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -57,7 +58,7 @@ class ToolMessage(BaseMessage, ToolOutputMixin): tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. @@ -67,7 +68,11 @@ class ToolMessage(BaseMessage, ToolOutputMixin): """Tool call that this message is responding to.""" type: Literal["tool"] = "tool" - """The type of the message (used for serialization). Defaults to "tool".""" + """The type of the message (used for serialization). + + Defaults to ``'tool'``. + + """ artifact: Any = None """Artifact of the Tool execution which is not meant to be sent to the model. @@ -77,12 +82,14 @@ class ToolMessage(BaseMessage, ToolOutputMixin): output is needed in other parts of the code. .. versionadded:: 0.2.17 + """ status: Literal["success", "error"] = "success" """Status of the tool invocation. .. versionadded:: 0.2.24 + """ additional_kwargs: dict = Field(default_factory=dict, repr=False) @@ -97,6 +104,7 @@ class ToolMessage(BaseMessage, ToolOutputMixin): Args: values: The model arguments. + """ content = values["content"] if isinstance(content, tuple): @@ -135,9 +143,11 @@ class ToolMessage(BaseMessage, ToolOutputMixin): return values def __init__( - self, content: Union[str, list[Union[str, dict]]], **kwargs: Any + self, + content: Union[str, list[Union[str, dict]]], + **kwargs: Any, ) -> None: - """Create a ToolMessage. + """Initialize ``ToolMessage``. Args: content: The string contents of the message. @@ -187,8 +197,8 @@ class ToolCall(TypedDict): {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. """ @@ -201,6 +211,7 @@ class ToolCall(TypedDict): An identifier is needed to associate a tool call request with a tool call result in events when multiple concurrent tool calls are made. + """ type: NotRequired[Literal["tool_call"]] @@ -227,9 +238,9 @@ def tool_call( class ToolCallChunk(TypedDict): """A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -282,7 +293,7 @@ def tool_call_chunk( class InvalidToolCall(TypedDict): """Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) """ diff --git a/libs/core/langchain_core/messages/utils.py b/libs/core/langchain_core/messages/utils.py index 6f681d7a65e..ea72ae06bad 100644 --- a/libs/core/langchain_core/messages/utils.py +++ b/libs/core/langchain_core/messages/utils.py @@ -5,6 +5,7 @@ Some examples of what you can do with these functions include: * Convert messages to strings (serialization) * Convert messages from dicts to Message objects (deserialization) * Filter messages from a list of messages based on name, type or id etc. + """ from __future__ import annotations @@ -91,13 +92,14 @@ AnyMessage = Annotated[ def get_buffer_string( messages: Sequence[BaseMessage], human_prefix: str = "Human", ai_prefix: str = "AI" ) -> str: - r"""Convert a sequence of Messages to strings and concatenate them into one string. + r"""Convert a sequence of messages to strings and concatenate them into one string. Args: messages: Messages to be converted to strings. - human_prefix: The prefix to prepend to contents of HumanMessages. - Default is "Human". - ai_prefix: The prefix to prepend to contents of AIMessages. Default is "AI". + human_prefix: The prefix to prepend to contents of ``HumanMessage``s. + Default is ``'Human'``. + ai_prefix: The prefix to prepend to contents of ``AIMessage``. Default is + ``'AI'``. Returns: A single string concatenation of all input messages. @@ -176,19 +178,20 @@ def _message_from_dict(message: dict) -> BaseMessage: def messages_from_dict(messages: Sequence[dict]) -> list[BaseMessage]: - """Convert a sequence of messages from dicts to Message objects. + """Convert a sequence of messages from dicts to ``Message`` objects. Args: messages: Sequence of messages (as dicts) to convert. Returns: list of messages (BaseMessages). + """ return [_message_from_dict(m) for m in messages] def message_chunk_to_message(chunk: BaseMessage) -> BaseMessage: - """Convert a message chunk to a message. + """Convert a message chunk to a ``Message``. Args: chunk: Message chunk to convert. @@ -221,10 +224,10 @@ def _create_message_from_message_type( id: Optional[str] = None, **additional_kwargs: Any, ) -> BaseMessage: - """Create a message from a message type and content string. + """Create a message from a ``Message`` type and content string. Args: - message_type: (str) the type of the message (e.g., "human", "ai", etc.). + message_type: (str) the type of the message (e.g., ``'human'``, ``'ai'``, etc.). content: (str) the content string. name: (str) the name of the message. Default is None. tool_call_id: (str) the tool call id. Default is None. @@ -236,8 +239,9 @@ def _create_message_from_message_type( a message of the appropriate type. Raises: - ValueError: if the message type is not one of "human", "user", "ai", - "assistant", "function", "tool", "system", or "developer". + ValueError: if the message type is not one of ``'human'``, ``'user'``, ``'ai'``, + ``'assistant'``, ``'function'``, ``'tool'``, ``'system'``, or + ``'developer'``. """ kwargs: dict[str, Any] = {} if name is not None: @@ -303,15 +307,15 @@ def _create_message_from_message_type( def _convert_to_message(message: MessageLikeRepresentation) -> BaseMessage: - """Instantiate a message from a variety of message formats. + """Instantiate a ``Message`` from a variety of message formats. The message format can be one of the following: - - BaseMessagePromptTemplate - - BaseMessage - - 2-tuple of (role string, template); e.g., ("human", "{user_input}") + - ``BaseMessagePromptTemplate`` + - ``BaseMessage`` + - 2-tuple of (role string, template); e.g., (``'human'``, ``'{user_input}'``) - dict: a message dict with role and content keys - - string: shorthand for ("human", template); e.g., "{user_input}" + - string: shorthand for (``'human'``, template); e.g., ``'{user_input}'`` Args: message: a representation of a message in one of the supported formats. @@ -322,6 +326,7 @@ def _convert_to_message(message: MessageLikeRepresentation) -> BaseMessage: Raises: NotImplementedError: if the message type is not supported. ValueError: if the message dict does not contain the required keys. + """ if isinstance(message, BaseMessage): message_ = message @@ -367,6 +372,7 @@ def convert_to_messages( Returns: list of messages (BaseMessages). + """ # Import here to avoid circular imports from langchain_core.prompt_values import PromptValue # noqa: PLC0415 @@ -417,36 +423,36 @@ def filter_messages( exclude_ids: Optional[Sequence[str]] = None, exclude_tool_calls: Optional[Sequence[str] | bool] = None, ) -> list[BaseMessage]: - """Filter messages based on name, type or id. + """Filter messages based on ``name``, ``type`` or ``id``. Args: messages: Sequence Message-like objects to filter. include_names: Message names to include. Default is None. exclude_names: Messages names to exclude. Default is None. - include_types: Message types to include. Can be specified as string names (e.g. - "system", "human", "ai", ...) or as BaseMessage classes (e.g. - SystemMessage, HumanMessage, AIMessage, ...). Default is None. - exclude_types: Message types to exclude. Can be specified as string names (e.g. - "system", "human", "ai", ...) or as BaseMessage classes (e.g. - SystemMessage, HumanMessage, AIMessage, ...). Default is None. + include_types: Message types to include. Can be specified as string names + (e.g. ``'system'``, ``'human'``, ``'ai'``, ...) or as ``BaseMessage`` + classes (e.g. ``SystemMessage``, ``HumanMessage``, ``AIMessage``, ...). + Default is None. + exclude_types: Message types to exclude. Can be specified as string names + (e.g. ``'system'``, ``'human'``, ``'ai'``, ...) or as ``BaseMessage`` + classes (e.g. ``SystemMessage``, ``HumanMessage``, ``AIMessage``, ...). + Default is None. include_ids: Message IDs to include. Default is None. exclude_ids: Message IDs to exclude. Default is None. exclude_tool_calls: Tool call IDs to exclude. Default is None. Can be one of the following: - - - ``True``: Each ``AIMessages`` with tool calls and all ``ToolMessages`` - will be excluded. + - ``True``: all ``AIMessage``s with tool calls and all + ``ToolMessage``s will be excluded. - a sequence of tool call IDs to exclude: - - - ToolMessages with the corresponding tool call ID will be excluded. - - The ``tool_calls`` in the AIMessage will be updated to exclude matching - tool calls. - If all tool_calls are filtered from an AIMessage, - the whole message is excluded. + - ``ToolMessage``s with the corresponding tool call ID will be + excluded. + - The ``tool_calls`` in the AIMessage will be updated to exclude + matching tool calls. If all ``tool_calls`` are filtered from an + AIMessage, the whole message is excluded. Returns: - A list of Messages that meets at least one of the incl_* conditions and none - of the excl_* conditions. If not incl_* conditions are specified then + A list of Messages that meets at least one of the ``incl_*`` conditions and none + of the ``excl_*`` conditions. If not ``incl_*`` conditions are specified then anything that is not explicitly excluded will be included. Raises: @@ -558,13 +564,14 @@ def merge_message_runs( ) -> list[BaseMessage]: r"""Merge consecutive Messages of the same type. - **NOTE**: ToolMessages are not merged, as each has a distinct tool call id that - can't be merged. + .. note:: + ToolMessages are not merged, as each has a distinct tool call id that can't be + merged. Args: messages: Sequence Message-like objects to merge. chunk_separator: Specify the string to be inserted between message chunks. - Default is "\n". + Default is ``'\n'``. Returns: list of BaseMessages with consecutive runs of message types merged into single @@ -705,8 +712,8 @@ def trim_messages( ) -> list[BaseMessage]: r"""Trim messages to be below a token count. - trim_messages can be used to reduce the size of a chat history to a specified token - count or specified message count. + ``trim_messages`` can be used to reduce the size of a chat history to a specified + token count or specified message count. In either case, if passing the trimmed chat history back into a chat model directly, the resulting chat history should usually satisfy the following @@ -714,13 +721,13 @@ def trim_messages( 1. The resulting chat history should be valid. Most chat models expect that chat history starts with either (1) a ``HumanMessage`` or (2) a ``SystemMessage`` - followed by a ``HumanMessage``. To achieve this, set ``start_on="human"``. + followed by a ``HumanMessage``. To achieve this, set ``start_on='human'``. In addition, generally a ``ToolMessage`` can only appear after an ``AIMessage`` that involved a tool call. Please see the following link for more information about messages: https://python.langchain.com/docs/concepts/#messages 2. It includes recent messages and drops old messages in the chat history. - To achieve this set the ``strategy="last"``. + To achieve this set the ``strategy='last'``. 3. Usually, the new chat history should include the ``SystemMessage`` if it was present in the original chat history since the ``SystemMessage`` includes special instructions to the chat model. The ``SystemMessage`` is almost always @@ -734,67 +741,67 @@ def trim_messages( Args: messages: Sequence of Message-like objects to trim. max_tokens: Max token count of trimmed messages. - token_counter: Function or llm for counting tokens in a BaseMessage or a list of - BaseMessage. If a BaseLanguageModel is passed in then - BaseLanguageModel.get_num_tokens_from_messages() will be used. - Set to `len` to count the number of **messages** in the chat history. + token_counter: Function or llm for counting tokens in a ``BaseMessage`` or a + list of ``BaseMessage``. If a ``BaseLanguageModel`` is passed in then + ``BaseLanguageModel.get_num_tokens_from_messages()`` will be used. + Set to ``len`` to count the number of **messages** in the chat history. .. note:: - Use `count_tokens_approximately` to get fast, approximate token counts. - This is recommended for using `trim_messages` on the hot path, where + Use ``count_tokens_approximately`` to get fast, approximate token + counts. + This is recommended for using ``trim_messages`` on the hot path, where exact token counting is not necessary. strategy: Strategy for trimming. - - - "first": Keep the first <= n_count tokens of the messages. - - "last": Keep the last <= n_count tokens of the messages. - + - ``'first'``: Keep the first ``<= n_count`` tokens of the messages. + - ``'last'``: Keep the last ``<= n_count`` tokens of the messages. Default is ``'last'``. allow_partial: Whether to split a message if only part of the message can be - included. If ``strategy="last"`` then the last partial contents of a message - are included. If ``strategy="first"`` then the first partial contents of a + included. If ``strategy='last'`` then the last partial contents of a message + are included. If ``strategy='first'`` then the first partial contents of a message are included. Default is False. end_on: The message type to end on. If specified then every message after the - last occurrence of this type is ignored. If ``strategy=="last"`` then this + last occurrence of this type is ignored. If ``strategy='last'`` then this is done before we attempt to get the last ``max_tokens``. If - ``strategy=="first"`` then this is done after we get the first - ``max_tokens``. Can be specified as string names (e.g. "system", "human", - "ai", ...) or as BaseMessage classes (e.g. SystemMessage, HumanMessage, - AIMessage, ...). Can be a single type or a list of types. + ``strategy='first'`` then this is done after we get the first + ``max_tokens``. Can be specified as string names (e.g. ``'system'``, + ``'human'``, ``'ai'``, ...) or as ``BaseMessage`` classes (e.g. + ``SystemMessage``, ``HumanMessage``, ``AIMessage``, ...). Can be a single + type or a list of types. Default is None. start_on: The message type to start on. Should only be specified if - ``strategy="last"``. If specified then every message before + ``strategy='last'``. If specified then every message before the first occurrence of this type is ignored. This is done after we trim the initial messages to the last ``max_tokens``. Does not - apply to a SystemMessage at index 0 if ``include_system=True``. Can be - specified as string names (e.g. "system", "human", "ai", ...) or as - BaseMessage classes (e.g. SystemMessage, HumanMessage, AIMessage, ...). Can - be a single type or a list of types. + apply to a ``SystemMessage`` at index 0 if ``include_system=True``. Can be + specified as string names (e.g. ``'system'``, ``'human'``, ``'ai'``, ...) or + as ``BaseMessage`` classes (e.g. ``SystemMessage``, ``HumanMessage``, + ``AIMessage``, ...). Can be a single type or a list of types. Default is None. include_system: Whether to keep the SystemMessage if there is one at index 0. Should only be specified if ``strategy="last"``. Default is False. text_splitter: Function or ``langchain_text_splitters.TextSplitter`` for splitting the string contents of a message. Only used if - ``allow_partial=True``. If ``strategy="last"`` then the last split tokens - from a partial message will be included. if ``strategy=="first"`` then the + ``allow_partial=True``. If ``strategy='last'`` then the last split tokens + from a partial message will be included. if ``strategy='first'`` then the first split tokens from a partial message will be included. Token splitter assumes that separators are kept, so that split contents can be directly concatenated to recreate the original text. Defaults to splitting on newlines. Returns: - list of trimmed BaseMessages. + list of trimmed ``BaseMessage``. Raises: ValueError: if two incompatible arguments are specified or an unrecognized ``strategy`` is specified. Example: - Trim chat history based on token count, keeping the SystemMessage if - present, and ensuring that the chat history starts with a HumanMessage ( - or a SystemMessage followed by a HumanMessage). + Trim chat history based on token count, keeping the ``SystemMessage`` if + present, and ensuring that the chat history starts with a ``HumanMessage`` ( + or a ``SystemMessage`` followed by a ``HumanMessage``). .. code-block:: python @@ -849,9 +856,9 @@ def trim_messages( HumanMessage(content="what do you call a speechless parrot"), ] - Trim chat history based on the message count, keeping the SystemMessage if - present, and ensuring that the chat history starts with a HumanMessage ( - or a SystemMessage followed by a HumanMessage). + Trim chat history based on the message count, keeping the ``SystemMessage`` if + present, and ensuring that the chat history starts with a ``HumanMessage`` ( + or a ``SystemMessage`` followed by a ``HumanMessage``). trim_messages( messages, @@ -1040,17 +1047,16 @@ def convert_to_openai_messages( messages: Message-like object or iterable of objects whose contents are in OpenAI, Anthropic, Bedrock Converse, or VertexAI formats. text_format: How to format string or text block contents: - - - ``'string'``: - If a message has a string content, this is left as a string. If - a message has content blocks that are all of type 'text', these are - joined with a newline to make a single string. If a message has - content blocks and at least one isn't of type 'text', then - all blocks are left as dicts. - - ``'block'``: - If a message has a string content, this is turned into a list - with a single content block of type 'text'. If a message has content - blocks these are left as is. + - ``'string'``: + If a message has a string content, this is left as a string. If + a message has content blocks that are all of type ``'text'``, these + are joined with a newline to make a single string. If a message has + content blocks and at least one isn't of type ``'text'``, then + all blocks are left as dicts. + - ``'block'``: + If a message has a string content, this is turned into a list + with a single content block of type ``'text'``. If a message has + content blocks these are left as is. Raises: ValueError: if an unrecognized ``text_format`` is specified, or if a message diff --git a/libs/core/langchain_core/outputs/chat_generation.py b/libs/core/langchain_core/outputs/chat_generation.py index 594066f2fb7..35102a18d59 100644 --- a/libs/core/langchain_core/outputs/chat_generation.py +++ b/libs/core/langchain_core/outputs/chat_generation.py @@ -15,14 +15,14 @@ from langchain_core.utils._merge import merge_dicts class ChatGeneration(Generation): """A single chat generation output. - A subclass of Generation that represents the response from a chat model + A subclass of ``Generation`` that represents the response from a chat model that generates chat messages. - The `message` attribute is a structured representation of the chat message. - Most of the time, the message will be of type `AIMessage`. + The ``message`` attribute is a structured representation of the chat message. + Most of the time, the message will be of type ``AIMessage``. Users working with chat models will usually access information via either - `AIMessage` (returned from runnable interfaces) or `LLMResult` (available + ``AIMessage`` (returned from runnable interfaces) or ``LLMResult`` (available via callbacks). """ @@ -31,6 +31,7 @@ class ChatGeneration(Generation): .. warning:: SHOULD NOT BE SET DIRECTLY! + """ message: BaseMessage """The message output by the chat model.""" @@ -47,6 +48,9 @@ class ChatGeneration(Generation): Returns: The values of the object with the text attribute set. + + Raises: + ValueError: If the message is not a string or a list. """ text = "" if isinstance(self.message.content, str): @@ -66,9 +70,9 @@ class ChatGeneration(Generation): class ChatGenerationChunk(ChatGeneration): - """ChatGeneration chunk. + """``ChatGeneration`` chunk. - ChatGeneration chunks can be concatenated with other ChatGeneration chunks. + ``ChatGeneration`` chunks can be concatenated with other ``ChatGeneration`` chunks. """ message: BaseMessageChunk diff --git a/libs/core/langchain_core/prompt_values.py b/libs/core/langchain_core/prompt_values.py index 5b7c2e414bb..908dafaa92d 100644 --- a/libs/core/langchain_core/prompt_values.py +++ b/libs/core/langchain_core/prompt_values.py @@ -113,8 +113,12 @@ class ImageURL(TypedDict, total=False): """Image URL.""" detail: Literal["auto", "low", "high"] - """Specifies the detail level of the image. Defaults to "auto". - Can be "auto", "low", or "high".""" + """Specifies the detail level of the image. Defaults to ``'auto'``. + Can be ``'auto'``, ``'low'``, or ``'high'``. + + This follows OpenAI's Chat Completion API's image URL format. + + """ url: str """Either a URL of the image or the base64 encoded image data.""" diff --git a/libs/core/tests/unit_tests/prompts/__snapshots__/test_chat.ambr b/libs/core/tests/unit_tests/prompts/__snapshots__/test_chat.ambr index c851464cd5b..9dd7d3e1b9a 100644 --- a/libs/core/tests/unit_tests/prompts/__snapshots__/test_chat.ambr +++ b/libs/core/tests/unit_tests/prompts/__snapshots__/test_chat.ambr @@ -382,10 +382,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -517,7 +517,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -688,7 +688,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -722,7 +721,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -792,7 +791,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -984,8 +982,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -1025,9 +1023,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -1106,10 +1104,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -1118,7 +1116,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -1140,7 +1138,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -1312,7 +1310,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { @@ -1803,10 +1800,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -1938,7 +1935,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -2109,7 +2106,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -2143,7 +2139,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -2213,7 +2209,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -2405,8 +2400,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -2446,9 +2441,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -2527,10 +2522,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -2539,7 +2534,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -2561,7 +2556,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -2733,7 +2728,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { diff --git a/libs/core/tests/unit_tests/runnables/__snapshots__/test_graph.ambr b/libs/core/tests/unit_tests/runnables/__snapshots__/test_graph.ambr index 0232a6f9877..728a1e03636 100644 --- a/libs/core/tests/unit_tests/runnables/__snapshots__/test_graph.ambr +++ b/libs/core/tests/unit_tests/runnables/__snapshots__/test_graph.ambr @@ -806,10 +806,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -941,7 +941,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -1112,7 +1112,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -1146,7 +1145,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -1216,7 +1215,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -1408,8 +1406,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -1449,9 +1447,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -1530,10 +1528,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -1542,7 +1540,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -1564,7 +1562,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -1736,7 +1734,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { diff --git a/libs/core/tests/unit_tests/runnables/__snapshots__/test_runnable.ambr b/libs/core/tests/unit_tests/runnables/__snapshots__/test_runnable.ambr index 4cd36110b0e..e52e8e22e02 100644 --- a/libs/core/tests/unit_tests/runnables/__snapshots__/test_runnable.ambr +++ b/libs/core/tests/unit_tests/runnables/__snapshots__/test_runnable.ambr @@ -2334,10 +2334,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -2467,7 +2467,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -2636,7 +2636,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -2670,7 +2669,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -2739,7 +2738,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -2929,8 +2927,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -2969,9 +2967,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -3049,10 +3047,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -3061,7 +3059,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -3083,7 +3081,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -3253,7 +3251,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { @@ -3799,10 +3796,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -3932,7 +3929,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -4101,7 +4098,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -4135,7 +4131,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -4204,7 +4200,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -4413,8 +4408,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -4453,9 +4448,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -4533,10 +4528,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -4545,7 +4540,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -4567,7 +4562,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -4737,7 +4732,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { @@ -5295,10 +5289,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -5428,7 +5422,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -5597,7 +5591,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -5631,7 +5624,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -5700,7 +5693,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -5909,8 +5901,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -5949,9 +5941,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -6029,10 +6021,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -6041,7 +6033,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -6063,7 +6055,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -6233,7 +6225,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { @@ -6666,10 +6657,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -6799,7 +6790,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -6968,7 +6959,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -7002,7 +6992,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -7071,7 +7061,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -7261,8 +7250,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -7301,9 +7290,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -7381,10 +7370,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -7393,7 +7382,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -7415,7 +7404,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -7585,7 +7574,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { @@ -8173,10 +8161,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -8306,7 +8294,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -8475,7 +8463,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -8509,7 +8496,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -8578,7 +8565,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -8787,8 +8773,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -8827,9 +8813,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -8907,10 +8893,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -8919,7 +8905,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -8941,7 +8927,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -9111,7 +9097,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { @@ -9589,10 +9574,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -9722,7 +9707,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -9891,7 +9876,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -9925,7 +9909,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -9994,7 +9978,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -10184,8 +10167,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -10224,9 +10207,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -10304,10 +10287,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -10316,7 +10299,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -10338,7 +10321,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -10508,7 +10491,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { @@ -11004,10 +10986,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -11137,7 +11119,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -11306,7 +11288,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -11340,7 +11321,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -11409,7 +11390,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -11629,8 +11609,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -11669,9 +11649,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -11749,10 +11729,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -11761,7 +11741,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -11783,7 +11763,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -11953,7 +11933,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { @@ -12461,10 +12440,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - FunctionMessage are an older version of the ToolMessage schema, and - do not contain the tool_call_id field. + ``FunctionMessage`` are an older version of the ``ToolMessage`` schema, and + do not contain the ``tool_call_id`` field. - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -12594,7 +12573,7 @@ 'description': ''' Message from a human. - HumanMessages are messages that are passed in from a human to the model. + ``HumanMessage``s are messages that are passed in from a human to the model. Example: @@ -12763,7 +12742,6 @@ Does *not* need to sum to full input token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -12797,7 +12775,7 @@ 'description': ''' Allowance for errors made by LLM. - Here we add an `error` key to surface errors made during generation + Here we add an ``error`` key to surface errors made during generation (e.g., invalid JSON arguments.) ''', 'properties': dict({ @@ -12866,7 +12844,6 @@ Does *not* need to sum to full output token count. Does *not* need to have all keys. Example: - .. code-block:: python { @@ -13075,8 +13052,8 @@ {"name": "foo", "args": {"a": 1}, "id": "123"} - This represents a request to call the tool named "foo" with arguments {"a": 1} - and an identifier of "123". + This represents a request to call the tool named ``'foo'`` with arguments + ``{"a": 1}`` and an identifier of ``'123'``. ''', 'properties': dict({ 'args': dict({ @@ -13115,9 +13092,9 @@ 'description': ''' A chunk of a tool call (e.g., as part of a stream). - When merging ToolCallChunks (e.g., via AIMessageChunk.__add__), + When merging ``ToolCallChunk``s (e.g., via ``AIMessageChunk.__add__``), all string attributes are concatenated. Chunks are only merged if their - values of `index` are equal and not None. + values of ``index`` are equal and not None. Example: @@ -13195,10 +13172,10 @@ 'description': ''' Message for passing the result of executing a tool back to a model. - ToolMessages contain the result of a tool invocation. Typically, the result - is encoded inside the `content` field. + ``ToolMessage``s contain the result of a tool invocation. Typically, the result + is encoded inside the ``content`` field. - Example: A ToolMessage representing a result of 42 from a tool call with id + Example: A ``ToolMessage`` representing a result of ``42`` from a tool call with id .. code-block:: python @@ -13207,7 +13184,7 @@ ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL") - Example: A ToolMessage where only part of the tool output is sent to the model + Example: A ``ToolMessage`` where only part of the tool output is sent to the model and the full output is passed in to artifact. .. versionadded:: 0.2.17 @@ -13229,7 +13206,7 @@ tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL", ) - The tool_call_id field is used to associate the tool call request with the + The ``tool_call_id`` field is used to associate the tool call request with the tool call response. This is useful in situations where a chat model is able to request multiple tool calls in parallel. ''', @@ -13399,7 +13376,6 @@ This is a standard representation of token usage that is consistent across models. Example: - .. code-block:: python { diff --git a/libs/core/tests/unit_tests/stubs.py b/libs/core/tests/unit_tests/stubs.py index 5cd45afb41f..57759ec9d47 100644 --- a/libs/core/tests/unit_tests/stubs.py +++ b/libs/core/tests/unit_tests/stubs.py @@ -15,34 +15,35 @@ class AnyStr(str): # The code below creates version of pydantic models # that will work in unit tests with AnyStr as id field + # Please note that the `id` field is assigned AFTER the model is created # to workaround an issue with pydantic ignoring the __eq__ method on # subclassed strings. def _any_id_document(**kwargs: Any) -> Document: - """Create a document with an id field.""" + """Create a `Document` with an id field.""" message = Document(**kwargs) message.id = AnyStr() return message def _any_id_ai_message(**kwargs: Any) -> AIMessage: - """Create ai message with an any id field.""" + """Create an `AIMessage` with an any id field.""" message = AIMessage(**kwargs) message.id = AnyStr() return message def _any_id_ai_message_chunk(**kwargs: Any) -> AIMessageChunk: - """Create ai message with an any id field.""" + """Create an `AIMessageChunk` with an any id field.""" message = AIMessageChunk(**kwargs) message.id = AnyStr() return message def _any_id_human_message(**kwargs: Any) -> HumanMessage: - """Create a human with an any id field.""" + """Create a `HumanMessage` with an any id field.""" message = HumanMessage(**kwargs) message.id = AnyStr() return message diff --git a/libs/core/uv.lock b/libs/core/uv.lock index 5e5675550ad..55201aa4006 100644 --- a/libs/core/uv.lock +++ b/libs/core/uv.lock @@ -567,7 +567,7 @@ name = "importlib-metadata" version = "8.7.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "zipp", marker = "python_full_version < '3.13'" }, + { name = "zipp", marker = "python_full_version < '3.10'" }, ] sdist = { url = "https://files.pythonhosted.org/packages/76/66/650a33bd90f786193e4de4b3ad86ea60b53c89b669a5c7be931fac31cdb0/importlib_metadata-8.7.0.tar.gz", hash = "sha256:d13b81ad223b890aa16c5471f2ac3056cf76c5f10f82d6f9292f0b415f389000", size = 56641, upload-time = "2025-04-27T15:29:01.736Z" } wheels = [ @@ -1126,6 +1126,8 @@ test = [ test-integration = [ { name = "en-core-web-sm", url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl" }, { name = "nltk", specifier = ">=3.9.1,<4.0.0" }, + { name = "scipy", marker = "python_full_version == '3.12.*'", specifier = ">=1.7.0,<2.0.0" }, + { name = "scipy", marker = "python_full_version >= '3.13'", specifier = ">=1.14.1,<2.0.0" }, { name = "sentence-transformers", specifier = ">=3.0.1,<4.0.0" }, { name = "spacy", specifier = ">=3.8.7,<4.0.0" }, { name = "thinc", specifier = ">=8.3.6,<9.0.0" },