Skip to content

langchain.smith.evaluation.progress.ProgressBarCallback: Make output after progress bar ends configurable #31583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions libs/langchain/langchain/smith/evaluation/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
class ProgressBarCallback(base_callbacks.BaseCallbackHandler):
"""A simple progress bar for the console."""

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

Args:
total: int, the total number of items to be processed.
ncols: int, the character width of the progress bar.
end_with: str, 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()
Expand All @@ -37,7 +41,8 @@ def _print_bar(self) -> None:
progress = self.counter / self.total
arrow = "-" * int(round(progress * self.ncols) - 1) + ">"
spaces = " " * (self.ncols - len(arrow))
print(f"\r[{arrow + spaces}] {self.counter}/{self.total}", end="") # noqa: T201
end = "" if self.counter < self.total else self.end_with
print(f"\r[{arrow + spaces}] {self.counter}/{self.total}", end=end) # noqa: T201

def on_chain_error(
self,
Expand Down
Loading