Skip to content

Commit 9de4f22

Browse files
langchain[patch]: smith.evaluation.progress.ProgressBarCallback: Make output after progress bar ends configurable (#31583)
1 parent 6105a58 commit 9de4f22

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libs/langchain/langchain/smith/evaluation/progress.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
class ProgressBarCallback(base_callbacks.BaseCallbackHandler):
1414
"""A simple progress bar for the console."""
1515

16-
def __init__(self, total: int, ncols: int = 50, **kwargs: Any):
16+
def __init__(
17+
self, total: int, ncols: int = 50, end_with: str = "\n", **kwargs: Any
18+
):
1719
"""Initialize the progress bar.
1820
1921
Args:
2022
total: int, the total number of items to be processed.
2123
ncols: int, the character width of the progress bar.
24+
end_with: str, last string to print after progress bar reaches end.
2225
"""
2326
self.total = total
2427
self.ncols = ncols
28+
self.end_with = end_with
2529
self.counter = 0
2630
self.lock = threading.Lock()
2731
self._print_bar()
@@ -37,7 +41,8 @@ def _print_bar(self) -> None:
3741
progress = self.counter / self.total
3842
arrow = "-" * int(round(progress * self.ncols) - 1) + ">"
3943
spaces = " " * (self.ncols - len(arrow))
40-
print(f"\r[{arrow + spaces}] {self.counter}/{self.total}", end="") # noqa: T201
44+
end = "" if self.counter < self.total else self.end_with
45+
print(f"\r[{arrow + spaces}] {self.counter}/{self.total}", end=end) # noqa: T201
4146

4247
def on_chain_error(
4348
self,

0 commit comments

Comments
 (0)