prettier /tokens output

This commit is contained in:
Paul Gauthier 2023-06-23 10:10:45 -07:00
parent 949a633e95
commit 803423cc6a
2 changed files with 14 additions and 8 deletions

View file

@ -371,8 +371,9 @@ class Coder:
exhausted = True exhausted = True
if exhausted: if exhausted:
self.io.tool_error("The chat session is larger than the context window!") self.io.tool_error("The chat session is larger than the context window!\n")
self.io.tool_error(" - Use /tokens to see token usage.") self.commands.cmd_tokens("")
self.io.tool_error("\nTo reduce token usage:")
self.io.tool_error(" - Use /drop to remove unneeded files from the chat session.") self.io.tool_error(" - Use /drop to remove unneeded files from the chat session.")
self.io.tool_error(" - Use /clear to clear chat history.") self.io.tool_error(" - Use /clear to clear chat history.")
return return

View file

@ -120,11 +120,13 @@ class Commands:
tokens = len(self.tokenizer.encode(quoted)) tokens = len(self.tokenizer.encode(quoted))
res.append((tokens, f"{relative_fname}", "use /drop to drop from chat")) res.append((tokens, f"{relative_fname}", "use /drop to drop from chat"))
print("Context window usage, in tokens:") print("Approximate context window usage, in tokens:")
print() print()
width = 8
def fmt(v): def fmt(v):
return format(int(v), ",").rjust(6) return format(int(v), ",").rjust(width)
col_width = max(len(row[1]) for row in res) col_width = max(len(row[1]) for row in res)
@ -134,13 +136,16 @@ class Commands:
msg = msg.ljust(col_width) msg = msg.ljust(col_width)
print(f"{fmt(tk)} {msg} {tip}") print(f"{fmt(tk)} {msg} {tip}")
print() print("=" * width)
print(f"{fmt(total)} total") print(f"{fmt(total)} tokens total")
limit = self.coder.main_model.max_context_tokens limit = self.coder.main_model.max_context_tokens
remaining = limit - total remaining = limit - total
print(f"{fmt(remaining)} remaining") if remaining > 0:
print(f"{fmt(limit)} max context window") print(f"{fmt(remaining)} tokens remaining in context window")
else:
print(f"{fmt(remaining)} tokens remaining, window exhausted!")
print(f"{fmt(limit)} tokens max context window size")
def cmd_undo(self, args): def cmd_undo(self, args):
"Undo the last git commit if it was done by aider" "Undo the last git commit if it was done by aider"