Skip to content

Commit

Permalink
Merge pull request #3127 from FeepingCreature/fix/sort-file-tokens
Browse files Browse the repository at this point in the history
refactor: Sort files by token count in cmd_tokens
  • Loading branch information
paul-gauthier authored Feb 18, 2025
2 parents 5402ed1 + 6d6e25d commit 86175a1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions aider/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ def cmd_tokens(self, args):

fence = "`" * 3

file_res = []
# files
for fname in self.coder.abs_fnames:
relative_fname = self.coder.get_rel_fname(fname)
Expand All @@ -414,7 +415,7 @@ def cmd_tokens(self, args):
# approximate
content = f"{relative_fname}\n{fence}\n" + content + "{fence}\n"
tokens = self.coder.main_model.token_count(content)
res.append((tokens, f"{relative_fname}", "/drop to remove"))
file_res.append((tokens, f"{relative_fname}", "/drop to remove"))

# read-only files
for fname in self.coder.abs_read_only_fnames:
Expand All @@ -424,7 +425,10 @@ def cmd_tokens(self, args):
# approximate
content = f"{relative_fname}\n{fence}\n" + content + "{fence}\n"
tokens = self.coder.main_model.token_count(content)
res.append((tokens, f"{relative_fname} (read-only)", "/drop to remove"))
file_res.append((tokens, f"{relative_fname} (read-only)", "/drop to remove"))

file_res.sort()
res.extend(file_res)

self.io.tool_output(
f"Approximate context window usage for {self.coder.main_model.name}, in tokens:"
Expand Down

0 comments on commit 86175a1

Please sign in to comment.