feat(TokenTracker): Add context manager support to simplify token tracking

This commit is contained in:
choizhang
2025-03-30 00:59:23 +08:00
parent 6eea8bdf5d
commit 164faf94e2
3 changed files with 31 additions and 30 deletions

View File

@@ -962,6 +962,13 @@ class TokenTracker:
def __init__(self):
self.reset()
def __enter__(self):
self.reset()
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print(self)
def reset(self):
self.prompt_tokens = 0
self.completion_tokens = 0