mirror of
https://github.com/mistralai/mistral-vibe
synced 2026-04-26 01:24:55 +02:00
Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai> Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai> Co-Authored-By: Clément Drouin <clement.drouin@mistral.ai> Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai> Co-Authored-By: Clément Siriex <clement.sirieix@mistral.ai> Co-Authored-By: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai> Co-Authored-By: Thaddee Tyl <thaddee.tyl@gmail.com> Co-Authored-By: David Brochart <david.brochart@gmail.com> Co-Authored-By: Joseph Guhlin <joseph.guhlin@gmail.com> Co-Authored-By: Thomas Kenbeek <thomaskenbeek@gmail.com> Co-Authored-By: Remenby31 <baptiste.cruvellier31@gmail.com>
31 lines
764 B
Python
31 lines
764 B
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
from textual.reactive import reactive
|
|
|
|
from vibe.cli.textual_ui.widgets.no_markup_static import NoMarkupStatic
|
|
|
|
|
|
@dataclass
|
|
class TokenState:
|
|
max_tokens: int = 0
|
|
current_tokens: int = 0
|
|
|
|
|
|
class ContextProgress(NoMarkupStatic):
|
|
tokens = reactive(TokenState())
|
|
|
|
def __init__(self, **kwargs: Any) -> None:
|
|
super().__init__(**kwargs)
|
|
|
|
def watch_tokens(self, new_state: TokenState) -> None:
|
|
if new_state.max_tokens == 0:
|
|
self.update("")
|
|
return
|
|
|
|
ratio = min(1, new_state.current_tokens / new_state.max_tokens)
|
|
text = f"{ratio:.0%} of {new_state.max_tokens // 1000}k tokens"
|
|
self.update(text)
|