Home / File/ fake_callback_handler.py — langchain Source File

fake_callback_handler.py — langchain Source File

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

File python LangChainCore ApiManagement 7 imports 5 classes

Entity Profile

Dependency Diagram

graph LR
  729da20b_aca8_b25d_9976_5af23b3e4b63["fake_callback_handler.py"]
  3741f36e_1d35_fcc3_9884_1c5e40d99797["itertools"]
  729da20b_aca8_b25d_9976_5af23b3e4b63 --> 3741f36e_1d35_fcc3_9884_1c5e40d99797
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  729da20b_aca8_b25d_9976_5af23b3e4b63 --> feec1ec4_6917_867b_d228_b134d0ff8099
  02f66451_d2a9_e7c3_9765_c3a7594721ad["uuid"]
  729da20b_aca8_b25d_9976_5af23b3e4b63 --> 02f66451_d2a9_e7c3_9765_c3a7594721ad
  3da01f49_ed2a_3d9f_9faa_7ea2c3c67c7f["langchain_core.callbacks.base"]
  729da20b_aca8_b25d_9976_5af23b3e4b63 --> 3da01f49_ed2a_3d9f_9faa_7ea2c3c67c7f
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  729da20b_aca8_b25d_9976_5af23b3e4b63 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  dd5e7909_a646_84f1_497b_cae69735550e["pydantic"]
  729da20b_aca8_b25d_9976_5af23b3e4b63 --> dd5e7909_a646_84f1_497b_cae69735550e
  f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"]
  729da20b_aca8_b25d_9976_5af23b3e4b63 --> f85fae70_1011_eaec_151c_4083140ae9e5
  style 729da20b_aca8_b25d_9976_5af23b3e4b63 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 langchain_core.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler
from langchain_core.messages import BaseMessage
from pydantic import BaseModel
from typing_extensions import override


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

    starts: int = 0
    ends: int = 0
    errors: int = 0
    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) -> None:
        self.errors += 1

    def on_llm_new_token_common(self) -> None:
// ... (366 more lines)

Domain

Subdomains

Dependencies

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

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free