Home / Function/ __add__() — langchain Function Reference

__add__() — langchain Function Reference

Architecture documentation for the __add__() function in chat_generation.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  3647eccf_27cf_5a34_71d9_9009ce452998["__add__()"]
  b114f430_2bfc_a8db_3787_d43839f4ce3a["ChatGenerationChunk"]
  3647eccf_27cf_5a34_71d9_9009ce452998 -->|defined in| b114f430_2bfc_a8db_3787_d43839f4ce3a
  style 3647eccf_27cf_5a34_71d9_9009ce452998 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/outputs/chat_generation.py lines 89–126

    def __add__(
        self, other: ChatGenerationChunk | list[ChatGenerationChunk]
    ) -> ChatGenerationChunk:
        """Concatenate two `ChatGenerationChunk`s.

        Args:
            other: The other `ChatGenerationChunk` or list of `ChatGenerationChunk` to
                concatenate.

        Raises:
            TypeError: If other is not a `ChatGenerationChunk` or list of
                `ChatGenerationChunk`.

        Returns:
            A new `ChatGenerationChunk` concatenated from self and other.
        """
        if isinstance(other, ChatGenerationChunk):
            generation_info = merge_dicts(
                self.generation_info or {},
                other.generation_info or {},
            )
            return ChatGenerationChunk(
                message=self.message + other.message,
                generation_info=generation_info or None,
            )
        if isinstance(other, list) and all(
            isinstance(x, ChatGenerationChunk) for x in other
        ):
            generation_info = merge_dicts(
                self.generation_info or {},
                *[chunk.generation_info for chunk in other if chunk.generation_info],
            )
            return ChatGenerationChunk(
                message=self.message + [chunk.message for chunk in other],
                generation_info=generation_info or None,
            )
        msg = f"unsupported operand type(s) for +: '{type(self)}' and '{type(other)}'"
        raise TypeError(msg)

Domain

Subdomains

Frequently Asked Questions

What does __add__() do?
__add__() is a function in the langchain codebase, defined in libs/core/langchain_core/outputs/chat_generation.py.
Where is __add__() defined?
__add__() is defined in libs/core/langchain_core/outputs/chat_generation.py at line 89.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free