ProgressBarCallback Class — langchain Architecture
Architecture documentation for the ProgressBarCallback class in progress.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 8f7245e3_8bd3_bce9_4868_73ea9b0cf467["ProgressBarCallback"] 8d636ab9_d317_4e39_4251_d46559a839f5["progress.py"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|defined in| 8d636ab9_d317_4e39_4251_d46559a839f5 fa184006_711f_00be_ca5a_3ffdcca482e4["__init__()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| fa184006_711f_00be_ca5a_3ffdcca482e4 d3fbccba_a17d_4737_e36f_b0c86b86e89e["increment()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| d3fbccba_a17d_4737_e36f_b0c86b86e89e 1a06c0ec_3a65_38c7_efa5_66cac1eec4cf["_print_bar()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| 1a06c0ec_3a65_38c7_efa5_66cac1eec4cf c125186e_0bc0_6835_fae1_362c9061b699["on_chain_error()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| c125186e_0bc0_6835_fae1_362c9061b699 23d4f7ba_413c_af00_c052_3988c133f380["on_chain_end()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| 23d4f7ba_413c_af00_c052_3988c133f380 75f76742_7840_1c83_541f_09ec822c2dff["on_retriever_error()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| 75f76742_7840_1c83_541f_09ec822c2dff 45ce09f2_3550_d89f_5423_a122924fd123["on_retriever_end()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| 45ce09f2_3550_d89f_5423_a122924fd123 eb97610c_6489_96b8_efed_37f320cdf098["on_llm_error()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| eb97610c_6489_96b8_efed_37f320cdf098 a914fbf0_f0cd_d943_6c83_4fa1caf9fe4a["on_llm_end()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| a914fbf0_f0cd_d943_6c83_4fa1caf9fe4a 4efc0434_f27d_bb2d_1139_c3331d672c71["on_tool_error()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| 4efc0434_f27d_bb2d_1139_c3331d672c71 5f7a7514_91bc_1074_9178_e0d7941dca67["on_tool_end()"] 8f7245e3_8bd3_bce9_4868_73ea9b0cf467 -->|method| 5f7a7514_91bc_1074_9178_e0d7941dca67
Relationship Graph
Source Code
libs/langchain/langchain_classic/smith/evaluation/progress.py lines 14–145
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:
self.increment()
@override
def on_chain_end(
self,
outputs: dict[str, Any],
*,
run_id: UUID,
parent_run_id: UUID | None = None,
**kwargs: Any,
) -> Any:
if parent_run_id is None:
self.increment()
@override
def on_retriever_error(
self,
error: BaseException,
*,
run_id: UUID,
parent_run_id: UUID | None = None,
**kwargs: Any,
) -> Any:
if parent_run_id is None:
self.increment()
@override
def on_retriever_end(
self,
documents: Sequence[Document],
*,
run_id: UUID,
parent_run_id: UUID | None = None,
**kwargs: Any,
Source
Frequently Asked Questions
What is the ProgressBarCallback class?
ProgressBarCallback is a class in the langchain codebase, defined in libs/langchain/langchain_classic/smith/evaluation/progress.py.
Where is ProgressBarCallback defined?
ProgressBarCallback is defined in libs/langchain/langchain_classic/smith/evaluation/progress.py at line 14.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free