Home / File/ callbacks.py — langchain Source File

callbacks.py — langchain Source File

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

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

from __future__ import annotations

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


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
// ... (213 more lines)

Subdomains

Dependencies

  • itertools
  • langchain_core.callbacks.base
  • langchain_core.messages
  • pydantic
  • typing
  • 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, RunnableInterface subdomain.
What does callbacks.py depend on?
callbacks.py imports 6 module(s): itertools, langchain_core.callbacks.base, langchain_core.messages, pydantic, typing, uuid.
Where is callbacks.py in the architecture?
callbacks.py is located at libs/partners/openai/tests/unit_tests/fake/callbacks.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/partners/openai/tests/unit_tests/fake).

Analyze Your Own Codebase

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

Try Supermodel Free