Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show how much of the raw repo map fits in the token budget #1780

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion aider/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ def cmd_tokens(self, args):
repo_content = self.coder.repo_map.get_repo_map(self.coder.abs_fnames, other_files)
if repo_content:
tokens = self.coder.main_model.token_count(repo_content)
res.append((tokens, "repository map", "use --map-tokens to resize"))
fit = self.coder.repo_map.fit_percentage
res.append((tokens, f"repository map ({fit:.1f}%)", "use --map-tokens to resize"))

fence = "`" * 3

Expand Down
9 changes: 9 additions & 0 deletions aider/repomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def __init__(
self.map_cache = {}
self.map_processing_time = 0
self.last_map = None
self.fit_percentage = None

if self.verbose:
self.io.tool_output(
Expand Down Expand Up @@ -535,6 +536,8 @@ def get_ranked_tags_map_uncached(
best_tree_tokens = 0

chat_rel_fnames = set(self.get_rel_fname(fname) for fname in chat_fnames)
full_tree = self.to_tree(ranked_tags, chat_rel_fnames)
total_tokens = self.token_count(full_tree)

self.tree_cache = dict()

Expand Down Expand Up @@ -564,6 +567,12 @@ def get_ranked_tags_map_uncached(
middle = (lower_bound + upper_bound) // 2

spin.end()

# Calculate and store the fit percentage
self.fit_percentage = (best_tree_tokens / total_tokens) * 100
if self.verbose:
self.io.tool_output(f"Repo-map fit: {self.fit_percentage:.1f}% of raw map")

return best_tree

tree_cache = dict()
Expand Down