Home / File/ stubs.py — langchain Source File

stubs.py — langchain Source File

Architecture documentation for stubs.py, a python file in the langchain codebase. 3 imports, 0 dependents.

File python CoreAbstractions Serialization 3 imports 4 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  12a520c3_62e1_cdd4_fbd2_d2a1106cf9e4["stubs.py"]
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  12a520c3_62e1_cdd4_fbd2_d2a1106cf9e4 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  12a520c3_62e1_cdd4_fbd2_d2a1106cf9e4 --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  12a520c3_62e1_cdd4_fbd2_d2a1106cf9e4 --> d758344f_537f_649e_f467_b9d7442e86df
  style 12a520c3_62e1_cdd4_fbd2_d2a1106cf9e4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from typing import Any

from langchain_core.documents import Document
from langchain_core.messages import AIMessage, AIMessageChunk, HumanMessage


class AnyStr(str):
    __slots__ = ()

    def __eq__(self, other: object) -> bool:
        return isinstance(other, str)

    __hash__ = str.__hash__


# 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."""
    message = Document(**kwargs)
    message.id = AnyStr()
    return message


def _any_id_ai_message(**kwargs: Any) -> AIMessage:
    """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 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 `HumanMessage` with an any id field."""
    message = HumanMessage(**kwargs)
    message.id = AnyStr()
    return message

Subdomains

Classes

Dependencies

  • langchain_core.documents
  • langchain_core.messages
  • typing

Frequently Asked Questions

What does stubs.py do?
stubs.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in stubs.py?
stubs.py defines 4 function(s): _any_id_ai_message, _any_id_ai_message_chunk, _any_id_document, _any_id_human_message.
What does stubs.py depend on?
stubs.py imports 3 module(s): langchain_core.documents, langchain_core.messages, typing.
Where is stubs.py in the architecture?
stubs.py is located at libs/core/tests/unit_tests/stubs.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/tests/unit_tests).

Analyze Your Own Codebase

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

Try Supermodel Free