ahvn.utils.basic.progress_utils module¶
- class ahvn.utils.basic.progress_utils.Progress(total=None, desc=None, initial=0, unit='it', leave=True)[源代码]¶
基类:
ABCAbstract base class for progress reporting.
Provides a unified interface for progress tracking that can be extended for different backends (tqdm, custom frontends, etc.).
Subclasses must implement: emit, update_total, update, close. Optional helpers: set_description, set_postfix, write.
- __init__(total=None, desc=None, initial=0, unit='it', leave=True)[源代码]¶
Initialize the progress bar.
- emit(payload)[源代码]¶
Emit a structured progress update.
The base implementation maps standardized keys: - total: calls update_total - update/advance: calls update - refresh: forwarded to subclasses when they override emit
- write(s, level=logging.INFO, **kwargs)[源代码]¶
Write a message through the progress bar's output mechanism. Default to using the AgentHeaven logger using the progress bar's class name.
- class ahvn.utils.basic.progress_utils.NoProgress(total=None, desc=None, initial=0, unit='it', leave=True)[源代码]¶
基类:
ProgressA silent progress implementation that does nothing.
Used as the default when no progress bar is requested.
- emit(payload)[源代码]¶
Emit a structured progress update.
The base implementation maps standardized keys: - total: calls update_total - update/advance: calls update - refresh: forwarded to subclasses when they override emit
- class ahvn.utils.basic.progress_utils.LogProgress(total=None, desc=None, initial=0, unit='it', leave=True, logger=None, level=logging.INFO, interval=10)[源代码]¶
基类:
ProgressProgress implementation using logging.
Outputs progress as log messages in format: [INFO] <desc>: <prefix> [xx%] <suffix> Logs at configurable intervals to avoid spam.
- 参数:
- __init__(total=None, desc=None, initial=0, unit='it', leave=True, logger=None, level=logging.INFO, interval=10)[源代码]¶
Initialize logger-based progress.
- 参数:
total (Optional[int]) -- Total number of iterations.
desc (Optional[str]) -- Description prefix.
initial (int) -- Initial counter value.
unit (str) -- Unit of iteration.
leave (bool) -- Whether to log completion message.
logger (Optional[logging.Logger]) -- Logger to use. Defaults to ahvn logger.
level (int) -- Log level. Defaults to INFO.
interval (int) -- Log every N percent change. Defaults to 10.
- emit(payload)[源代码]¶
Emit a structured progress update.
The base implementation maps standardized keys: - total: calls update_total - update/advance: calls update - refresh: forwarded to subclasses when they override emit
- class ahvn.utils.basic.progress_utils.TqdmProgress(total=None, desc=None, initial=0, unit='it', leave=True, **tqdm_kwargs)[源代码]¶
基类:
ProgressProgress implementation using tqdm.
Wraps tqdm to provide a consistent interface with other Progress implementations.
- __init__(total=None, desc=None, initial=0, unit='it', leave=True, **tqdm_kwargs)[源代码]¶
Initialize tqdm-based progress bar.
- emit(payload)[源代码]¶
Emit a structured progress update.
The base implementation maps standardized keys: - total: calls update_total - update/advance: calls update - refresh: forwarded to subclasses when they override emit
- write(s, file=None, end='\\n', **kwargs)[源代码]¶
Write a message through the tqdm progress bar's output mechanism.
- ahvn.utils.basic.progress_utils.get_progress()[源代码]¶
Get the currently active progress bar for this thread.
- 返回:
The active progress bar, or a NoProgress instance if none is active.
- 返回类型:
- ahvn.utils.basic.progress_utils.progress(p)[源代码]¶
Context manager to set the active progress bar.
Supports nesting - each context pushes onto a stack and pops on exit.
- 参数:
p (Progress) -- The progress bar to activate.
- 生成器:
Progress -- The activated progress bar.
示例
- with progress(TqdmProgress(total=100)) as pbar:
- for i in range(100):
pbar.update(1)