MCPcopy Create free account
hub / github.com/CJackHwang/AIstudioProxyAPI / update

Method update

logging_utils/core/rendering.py:522–582  ·  view source on GitHub ↗

Update progress on the same line. Args: current: Current progress value total: Total value for 100% extra: Additional info to display after progress bar

(self, current: int, total: int, extra: str = "")

Source from the content-addressed store, hash-verified

520 self._min_interval = 0.05 # Minimum time between updates (50ms)
521
522 def update(self, current: int, total: int, extra: str = "") -> None:
523 """
524 Update progress on the same line.
525
526 Args:
527 current: Current progress value
528 total: Total value for 100%
529 extra: Additional info to display after progress bar
530 """
531 now = time.time()
532
533 # Rate limit updates to avoid flickering
534 if now - self.last_update < self._min_interval and current < total:
535 return
536
537 self.last_update = now
538 self._started = True
539
540 # Get context
541 try:
542 req_id = request_id_var.get()
543 except LookupError:
544 req_id = " "
545
546 source = self.source
547 if source is None:
548 try:
549 source = source_var.get()
550 except LookupError:
551 source = "SYS"
552
553 source_normalized = normalize_source(source)
554
555 # Build timestamp
556 timestamp = (
557 datetime.now().strftime("%H:%M:%S.") + f"{int(now * 1000) % 1000:03d}"
558 )
559
560 # Calculate progress
561 percentage = (current / total * 100) if total > 0 else 0
562 bar_width = 20
563 filled = int(bar_width * current / total) if total > 0 else 0
564 bar = "#" * filled + "-" * (bar_width - filled)
565
566 extra_text = f" {extra}" if extra else ""
567
568 # Build the line with colors
569 source_color = Colors.SOURCES.get(source_normalized, Fore.WHITE)
570 line = (
571 f"\r{Colors.TIME}{timestamp}{Colors.RESET} "
572 f"{Colors.LEVELS['INFO']}INF{Colors.RESET} "
573 f"{source_color}{source_normalized}{Colors.RESET} "
574 f"{Colors.REQUEST_ID}{req_id:<{Columns.ID}}{Colors.RESET} "
575 f"{Colors.MESSAGE}{self.message} [{bar}] "
576 f"{Colors.NUMBER}{current}{Colors.RESET}/{Colors.NUMBER}{total}{Colors.RESET} "
577 f"({Colors.NUMBER}{percentage:.0f}%{Colors.RESET}){extra_text}"
578 )
579

Calls 4

normalize_sourceFunction · 0.85
getMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45