final details on --map-tokens

This commit is contained in:
Paul Gauthier 2023-06-03 18:06:14 -07:00
parent 1f9e9be64d
commit ef22f44d19
2 changed files with 21 additions and 15 deletions

View file

@ -63,6 +63,8 @@ class Coder:
self.auto_commits = auto_commits self.auto_commits = auto_commits
self.dirty_commits = dirty_commits self.dirty_commits = dirty_commits
self.dry_run = dry_run self.dry_run = dry_run
self.pretty = pretty
self.show_diffs = show_diffs
if pretty: if pretty:
self.console = Console() self.console = Console()
@ -86,21 +88,21 @@ class Coder:
if self.repo: if self.repo:
rel_repo_dir = os.path.relpath(self.repo.git_dir, os.getcwd()) rel_repo_dir = os.path.relpath(self.repo.git_dir, os.getcwd())
self.io.tool_output("Using git repo:", rel_repo_dir) capabilities_msg = f"Using git repo {rel_repo_dir}, "
else: else:
self.io.tool_error("No suitable git repo, will not automatically commit edits.") capabilities_msg = "Not using git, "
self.find_common_root() self.find_common_root()
self.pretty = pretty rm_io = io if self.verbose else None
self.show_diffs = show_diffs
if self.verbose:
rm_io = io
else:
rm_io = None
self.repo_map = RepoMap(map_tokens, self.root, self.main_model, rm_io) self.repo_map = RepoMap(map_tokens, self.root, self.main_model, rm_io)
if self.repo_map.has_ctags:
capabilities_msg += "using ctags."
else:
capabilities_msg += "not using ctags."
self.io.tool_output(capabilities_msg)
def find_common_root(self): def find_common_root(self):
if self.abs_fnames: if self.abs_fnames:
common_prefix = os.path.commonpath(list(self.abs_fnames)) common_prefix = os.path.commonpath(list(self.abs_fnames))

View file

@ -58,9 +58,6 @@ class RepoMap:
IDENT_CACHE_DIR = ".aider.ident.cache" IDENT_CACHE_DIR = ".aider.ident.cache"
TAGS_CACHE_DIR = ".aider.tags.cache" TAGS_CACHE_DIR = ".aider.tags.cache"
# 1/4 of gpt-4's context window
max_map_tokens = 512
def __init__(self, map_tokens=1024, root=None, main_model="gpt-4", io=None): def __init__(self, map_tokens=1024, root=None, main_model="gpt-4", io=None):
self.io = io self.io = io
@ -71,7 +68,11 @@ class RepoMap:
self.load_ident_cache() self.load_ident_cache()
self.load_tags_cache() self.load_tags_cache()
self.map_tokens = map_tokens self.max_map_tokens = map_tokens
if map_tokens > 0:
self.has_ctags = self.check_for_ctags()
else:
self.has_ctags = False
self.tokenizer = tiktoken.encoding_for_model(main_model) self.tokenizer = tiktoken.encoding_for_model(main_model)
@ -96,10 +97,13 @@ class RepoMap:
return repo_content return repo_content
def choose_files_listing(self, chat_files, other_files): def choose_files_listing(self, chat_files, other_files):
if self.max_map_tokens <= 0:
return
if not other_files: if not other_files:
return return
if self.use_ctags: if self.has_ctags:
files_listing = self.get_ranked_tags_map(chat_files, other_files) files_listing = self.get_ranked_tags_map(chat_files, other_files)
num_tokens = self.token_count(files_listing) num_tokens = self.token_count(files_listing)
if self.io: if self.io: