Only expand the repomap if we know it will fit into context window

This commit is contained in:
Paul Gauthier 2024-05-20 10:22:57 -07:00
parent 449cbf507f
commit 1effd73e80
2 changed files with 12 additions and 3 deletions

View file

@ -310,6 +310,7 @@ class Coder:
io, io,
self.gpt_prompts.repo_content_prefix, self.gpt_prompts.repo_content_prefix,
self.verbose, self.verbose,
self.main_model.info.get("max_input_tokens"),
) )
if max_chat_history_tokens is None: if max_chat_history_tokens is None:

View file

@ -40,6 +40,7 @@ class RepoMap:
io=None, io=None,
repo_content_prefix=None, repo_content_prefix=None,
verbose=False, verbose=False,
max_context_window=None,
): ):
self.io = io self.io = io
self.verbose = verbose self.verbose = verbose
@ -51,6 +52,7 @@ class RepoMap:
self.load_tags_cache() self.load_tags_cache()
self.max_map_tokens = map_tokens self.max_map_tokens = map_tokens
self.max_context_window = max_context_window
self.token_count = main_model.token_count self.token_count = main_model.token_count
self.repo_content_prefix = repo_content_prefix self.repo_content_prefix = repo_content_prefix
@ -66,9 +68,15 @@ class RepoMap:
mentioned_idents = set() mentioned_idents = set()
max_map_tokens = self.max_map_tokens max_map_tokens = self.max_map_tokens
if not chat_files:
# with no code in the chat, give a bigger view of the entire repo # With no files in the chat, give a bigger view of the entire repo
max_map_tokens *= 16 MUL = 16
if (
not chat_files
and self.max_context_window
and max_map_tokens * MUL < (self.max_context_window - 2048)
):
max_map_tokens *= MUL
dump(max_map_tokens) dump(max_map_tokens)