Home / File/ progress.py — langchain Source File

progress.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  8d636ab9_d317_4e39_4251_d46559a839f5["progress.py"]
  115d9bf0_a63e_564c_f8d8_eb2c82bbd856["threading"]
  8d636ab9_d317_4e39_4251_d46559a839f5 --> 115d9bf0_a63e_564c_f8d8_eb2c82bbd856
  2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"]
  8d636ab9_d317_4e39_4251_d46559a839f5 --> 2bf6d401_816d_d011_3b05_a6114f55ff58
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  8d636ab9_d317_4e39_4251_d46559a839f5 --> feec1ec4_6917_867b_d228_b134d0ff8099
  02f66451_d2a9_e7c3_9765_c3a7594721ad["uuid"]
  8d636ab9_d317_4e39_4251_d46559a839f5 --> 02f66451_d2a9_e7c3_9765_c3a7594721ad
  17a62cb3_fefd_6320_b757_b53bb4a1c661["langchain_core.callbacks"]
  8d636ab9_d317_4e39_4251_d46559a839f5 --> 17a62cb3_fefd_6320_b757_b53bb4a1c661
  6a98b0a5_5607_0043_2e22_a46a464c2d62["langchain_core.documents"]
  8d636ab9_d317_4e39_4251_d46559a839f5 --> 6a98b0a5_5607_0043_2e22_a46a464c2d62
  4382dc25_6fba_324a_49e2_e9742d579385["langchain_core.outputs"]
  8d636ab9_d317_4e39_4251_d46559a839f5 --> 4382dc25_6fba_324a_49e2_e9742d579385
  f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"]
  8d636ab9_d317_4e39_4251_d46559a839f5 --> f85fae70_1011_eaec_151c_4083140ae9e5
  style 8d636ab9_d317_4e39_4251_d46559a839f5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""A simple progress bar for the console."""

import threading
from collections.abc import Sequence
from typing import Any
from uuid import UUID

from langchain_core.callbacks import base as base_callbacks
from langchain_core.documents import Document
from langchain_core.outputs import LLMResult
from typing_extensions import override


class ProgressBarCallback(base_callbacks.BaseCallbackHandler):
    """A simple progress bar for the console."""

    def __init__(
        self,
        total: int,
        ncols: int = 50,
        end_with: str = "\n",
    ):
        """Initialize the progress bar.

        Args:
            total: The total number of items to be processed.
            ncols: The character width of the progress bar.
            end_with: Last string to print after progress bar reaches end.
        """
        self.total = total
        self.ncols = ncols
        self.end_with = end_with
        self.counter = 0
        self.lock = threading.Lock()
        self._print_bar()

    def increment(self) -> None:
        """Increment the counter and update the progress bar."""
        with self.lock:
            self.counter += 1
            self._print_bar()

    def _print_bar(self) -> None:
        """Print the progress bar to the console."""
        progress = self.counter / self.total
        arrow = "-" * int(round(progress * self.ncols) - 1) + ">"
        spaces = " " * (self.ncols - len(arrow))
        end = "" if self.counter < self.total else self.end_with
        print(f"\r[{arrow + spaces}] {self.counter}/{self.total}", end=end)  # noqa: T201

    @override
    def on_chain_error(
        self,
        error: BaseException,
        *,
        run_id: UUID,
        parent_run_id: UUID | None = None,
        **kwargs: Any,
    ) -> Any:
        if parent_run_id is None:
// ... (86 more lines)

Domain

Subdomains

Dependencies

  • collections.abc
  • langchain_core.callbacks
  • langchain_core.documents
  • langchain_core.outputs
  • threading
  • typing
  • typing_extensions
  • uuid

Frequently Asked Questions

What does progress.py do?
progress.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What does progress.py depend on?
progress.py imports 8 module(s): collections.abc, langchain_core.callbacks, langchain_core.documents, langchain_core.outputs, threading, typing, typing_extensions, uuid.
Where is progress.py in the architecture?
progress.py is located at libs/langchain/langchain_classic/smith/evaluation/progress.py (domain: LangChainCore, subdomain: MessageInterface, directory: libs/langchain/langchain_classic/smith/evaluation).

Analyze Your Own Codebase

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

Try Supermodel Free