feat: Add progress indicator and format cached tokens in warm_cache_worker

This commit is contained in:
Paul Gauthier (aider) 2024-08-26 15:42:04 -07:00
parent 8319df775e
commit a6ff08b2c5

View file

@ -996,7 +996,7 @@ class Coder:
self.cache_warming_thread.cancel()
def warm_cache_worker():
for _ in range(self.num_cache_warming_pings):
for i in range(self.num_cache_warming_pings):
time.sleep(20) # 290 == 4 minutes and 50 seconds
try:
completion = litellm.completion(
@ -1013,7 +1013,16 @@ class Coder:
cache_hit_tokens = getattr(
completion.usage, "prompt_cache_hit_tokens", 0
) or getattr(completion.usage, "cache_read_input_tokens", 0)
self.io.tool_output(f"Warmed {cache_hit_tokens} cached tokens.")
def format_tokens(count):
if count < 1000:
return f"{count}"
elif count < 10000:
return f"{count / 1000:.1f}k"
else:
return f"{round(count / 1000)}k"
self.io.tool_output(f"Warmed {format_tokens(cache_hit_tokens)} cached tokens. ({i+1}/{self.num_cache_warming_pings})")
self.io.tool_output("Stopped warming.")