Home / File/ callbacks.py — langchain Source File

callbacks.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  07deddc6_bb63_0758_8452_6935ef3e67d6["callbacks.py"]
  436f77bc_653d_0edb_555c_c2679d5a59ac["itertools"]
  07deddc6_bb63_0758_8452_6935ef3e67d6 --> 436f77bc_653d_0edb_555c_c2679d5a59ac
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  07deddc6_bb63_0758_8452_6935ef3e67d6 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  8dfa0cac_d802_3ccd_f710_43a5e70da3a5["uuid"]
  07deddc6_bb63_0758_8452_6935ef3e67d6 --> 8dfa0cac_d802_3ccd_f710_43a5e70da3a5
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  07deddc6_bb63_0758_8452_6935ef3e67d6 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  07deddc6_bb63_0758_8452_6935ef3e67d6 --> 91721f45_4909_e489_8c1f_084f8bd87145
  7e64d143_ea36_1c73_4897_1d0ae1757b5b["langchain_core.callbacks.base"]
  07deddc6_bb63_0758_8452_6935ef3e67d6 --> 7e64d143_ea36_1c73_4897_1d0ae1757b5b
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  07deddc6_bb63_0758_8452_6935ef3e67d6 --> d758344f_537f_649e_f467_b9d7442e86df
  style 07deddc6_bb63_0758_8452_6935ef3e67d6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""A fake callback handler for testing purposes."""

from itertools import chain
from typing import Any
from uuid import UUID

from pydantic import BaseModel
from typing_extensions import override

from langchain_core.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler
from langchain_core.messages import BaseMessage


class BaseFakeCallbackHandler(BaseModel):
    """Base fake callback handler for testing."""

    starts: int = 0
    ends: int = 0
    errors: int = 0
    errors_args: list[Any] = []
    text: int = 0
    ignore_llm_: bool = False
    ignore_chain_: bool = False
    ignore_agent_: bool = False
    ignore_retriever_: bool = False
    ignore_chat_model_: bool = False

    # to allow for similar callback handlers that are not technically equal
    fake_id: str | None = None

    # add finer-grained counters for easier debugging of failing tests
    chain_starts: int = 0
    chain_ends: int = 0
    llm_starts: int = 0
    llm_ends: int = 0
    llm_streams: int = 0
    tool_starts: int = 0
    tool_ends: int = 0
    agent_actions: int = 0
    agent_ends: int = 0
    chat_model_starts: int = 0
    retriever_starts: int = 0
    retriever_ends: int = 0
    retriever_errors: int = 0
    retries: int = 0


class BaseFakeCallbackHandlerMixin(BaseFakeCallbackHandler):
    """Base fake callback handler mixin for testing."""

    def on_llm_start_common(self) -> None:
        self.llm_starts += 1
        self.starts += 1

    def on_llm_end_common(self) -> None:
        self.llm_ends += 1
        self.ends += 1

    def on_llm_error_common(self, *args: Any, **kwargs: Any) -> None:
        self.errors += 1
// ... (373 more lines)

Subdomains

Dependencies

  • itertools
  • langchain_core.callbacks.base
  • langchain_core.messages
  • pydantic
  • typing
  • typing_extensions
  • uuid

Frequently Asked Questions

What does callbacks.py do?
callbacks.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What does callbacks.py depend on?
callbacks.py imports 7 module(s): itertools, langchain_core.callbacks.base, langchain_core.messages, pydantic, typing, typing_extensions, uuid.
Where is callbacks.py in the architecture?
callbacks.py is located at libs/core/tests/unit_tests/fake/callbacks.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/tests/unit_tests/fake).

Analyze Your Own Codebase

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

Try Supermodel Free