From d21de778ffd6ab44445baa838b17f97ed100d81b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 26 Apr 2024 11:24:42 -0700 Subject: [PATCH] announcements --- aider/coders/base_coder.py | 90 +++++++++++++++----------- aider/gui.py | 127 +++++-------------------------------- aider/main.py | 28 ++++---- 3 files changed, 85 insertions(+), 160 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index daaa5fc7e..883ce8269 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -16,7 +16,7 @@ from jsonschema import Draft7Validator from rich.console import Console, Text from rich.markdown import Markdown -from aider import models, prompts, utils +from aider import __version__, models, prompts, utils from aider.commands import Commands from aider.history import ChatSummary from aider.io import InputOutput @@ -80,6 +80,54 @@ class Coder: else: raise ValueError(f"Unknown edit format {edit_format}") + def get_announcements(self): + lines = [] + lines.append(f"Aider v{__version__}") + + # Model + main_model = self.main_model + weak_model = main_model.weak_model + prefix = "Model:" + output = f" {main_model.name} with {self.edit_format} edit format" + if weak_model is not main_model: + prefix = "Models:" + output += f", weak model {weak_model.name}" + lines.append(prefix + output) + + # Repo + if self.repo: + rel_repo_dir = self.repo.get_rel_repo_dir() + num_files = len(self.repo.get_tracked_files()) + lines.append(f"Git repo: {rel_repo_dir} with {num_files:,} files") + if num_files > 1000: + lines.append( + "Warning: For large repos, consider using an .aiderignore file to ignore" + " irrelevant files/dirs." + ) + else: + lines.append("Git repo: none") + + # Repo-map + map_tokens = self.repo_map.max_map_tokens if self.repo_map else 0 + if map_tokens > 0 and self.repo_map: + lines.append(f"Repo-map: using {map_tokens} tokens") + max_map_tokens = 2048 + if map_tokens > max_map_tokens: + lines.append( + f"Warning: map-tokens > {max_map_tokens} is not recommended as too much" + " irrelevant code can confuse GPT." + ) + elif not map_tokens: + lines.append("Repo-map: disabled because map_tokens == 0") + else: + lines.append("Repo-map: disabled") + + # Files + for fname in self.get_inchat_relative_files(): + lines.append(f"Added {fname} to the chat.") + + return lines + def __init__( self, main_model, @@ -136,15 +184,6 @@ class Coder: self.main_model = main_model - weak_model = main_model.weak_model - prefix = "Model:" - output = f" {main_model.name} with {self.edit_format} edit format" - if weak_model is not main_model: - prefix = "Models:" - output += f", weak model {weak_model.name}" - - self.io.tool_output(prefix + output) - self.show_diffs = show_diffs self.commands = Commands(self.io, self, voice_language) @@ -181,17 +220,7 @@ class Coder: self.abs_fnames.add(fname) self.check_added_files() - if self.repo: - rel_repo_dir = self.repo.get_rel_repo_dir() - num_files = len(self.repo.get_tracked_files()) - self.io.tool_output(f"Git repo: {rel_repo_dir} with {num_files:,} files") - if num_files > 1000: - self.io.tool_error( - "Warning: For large repos, consider using an .aiderignore file to ignore" - " irrelevant files/dirs." - ) - else: - self.io.tool_output("Git repo: none") + if not self.repo: self.find_common_root() if main_model.use_repo_map and self.repo and self.gpt_prompts.repo_content_prefix: @@ -204,22 +233,6 @@ class Coder: self.verbose, ) - if map_tokens > 0 and self.repo_map: - self.io.tool_output(f"Repo-map: using {map_tokens} tokens") - max_map_tokens = 2048 - if map_tokens > max_map_tokens: - self.io.tool_error( - f"Warning: map-tokens > {max_map_tokens} is not recommended as too much" - " irrelevant code can confuse GPT." - ) - elif not map_tokens: - self.io.tool_output("Repo-map: disabled because map_tokens == 0") - else: - self.io.tool_output("Repo-map: disabled") - - for fname in self.get_inchat_relative_files(): - self.io.tool_output(f"Added {fname} to the chat.") - self.summarizer = ChatSummary( self.main_model.weak_model, self.main_model.max_chat_history_tokens, @@ -237,6 +250,9 @@ class Coder: self.io.tool_output("JSON Schema:") self.io.tool_output(json.dumps(self.functions, indent=4)) + for line in self.get_announcements(): + self.io.tool_output(line) + def find_common_root(self): if len(self.abs_fnames) == 1: self.root = os.path.dirname(list(self.abs_fnames)[0]) diff --git a/aider/gui.py b/aider/gui.py index ea8c77d09..632b2f795 100755 --- a/aider/gui.py +++ b/aider/gui.py @@ -8,7 +8,7 @@ import streamlit as st from aider.coders import Coder from aider.dump import dump # noqa: F401 -from aider.models import Model +from aider.main import main if "recent_msgs_num" not in st.session_state: st.session_state.recent_msgs_num = 0 @@ -100,122 +100,25 @@ def search(text=None): # selected_value = st_searchbox(search) -model = Model("claude-3-haiku-20240307") -fnames = ["greeting.py"] -coder = Coder.create(main_model=model, fnames=fnames, use_git=False, pretty=False) - -lorem_words = [ - "lorem", - "ipsum", - "dolor", - "sit", - "amet", - "consectetur", - "adipiscing", - "elit", - "sed", - "do", - "eiusmod", - "tempor", - "incididunt", - "ut", - "labore", - "et", - "dolore", - "magna", - "aliqua", - "enim", - "ad", - "minim", - "veniam", - "quis", - "nostrudlorem", - "ipsum", - "dolor", - "sit", - "amet", - "consectetur", - "adipiscing", - "elit", - "sed", - "do", - "eiusmod", - "tempor", - "incididunt", - "ut", - "labore", - "et", - "dolore", - "magna", - "aliqua", - "enim", - "ad", - "minim", - "veniam", - "quis", - "nostrudlorem", - "ipsum", - "dolor", - "sit", - "amet", - "consectetur", - "adipiscing", - "elit", - "sed", - "do", - "eiusmod", - "tempor", - "incididunt", - "ut", - "labore", - "et", - "dolore", - "magna", - "aliqua", - "enim", - "ad", - "minim", - "veniam", - "quis", - "nostrudlorem", - "ipsum", - "dolor", - "sit", - "amet", - "consectetur", - "adipiscing", - "elit", - "sed", - "do", - "eiusmod", - "tempor", - "incididunt", - "ut", - "labore", - "et", - "dolore", - "magna", - "aliqua", - "enim", - "ad", - "minim", - "veniam", - "quis", - "nostrud\n\n", - "\n\n", - "\n\n", -] +@st.cache_resource +def get_coder(): + coder = main(return_coder=True) + if isinstance(coder, Coder): + return coder + raise ValueError() -def generate_lorem_text(min_words=10, max_words=50): - num_words = random.randint(min_words, max_words) - words = random.sample(lorem_words, num_words) - return " ".join(words) +coder = get_coder() + + +def announce(coder): + lines = coder.get_announcements() + lines = " \n".join(lines) + st.info(lines) with st.sidebar: st.title("Aider") - cmds_tab, settings_tab = st.tabs(["Commands", "Settings"]) with cmds_tab: @@ -303,6 +206,8 @@ messages = st.container() # stuff a bunch of vertical whitespace at the top # to get all the chat text to the bottom messages.container(height=1200, border=False) +with messages: + announce(coder) with recent_msgs_empty: old_prompt = recent_msgs() diff --git a/aider/main.py b/aider/main.py index ffee5ee6e..ca778382b 100644 --- a/aider/main.py +++ b/aider/main.py @@ -122,7 +122,7 @@ def check_gitignore(git_root, io, ask=True): io.tool_output(f"Added {pat} to .gitignore") -def main(argv=None, input=None, output=None, force_git_root=None): +def main(argv=None, input=None, output=None, force_git_root=None, return_coder=False): if argv is None: argv = sys.argv[1:] @@ -554,20 +554,14 @@ def main(argv=None, input=None, output=None, force_git_root=None): if args.git and not force_git_root: right_repo_root = guessed_wrong_repo(io, git_root, fnames, git_dname) if right_repo_root: - return main(argv, input, output, right_repo_root) - - io.tool_output(f"Aider v{__version__}") + return main(argv, input, output, right_repo_root, return_coder=return_coder) if not args.skip_check_update: check_version(io.tool_error) if args.check_update: update_available = check_version(lambda msg: None) - sys.exit(0 if not update_available else 1) - - if "VSCODE_GIT_IPC_HANDLE" in os.environ: - args.pretty = False - io.tool_output("VSCode terminal detected, pretty output has been disabled.") + return 0 if not update_available else 1 if args.models: matches = models.fuzzy_match_models(args.models) @@ -652,6 +646,9 @@ def main(argv=None, input=None, output=None, force_git_root=None): io.tool_error(str(err)) return 1 + if return_coder: + return coder + if args.commit: coder.commands.cmd_commit("") return @@ -670,6 +667,10 @@ def main(argv=None, input=None, output=None, force_git_root=None): coder.apply_updates() return + if "VSCODE_GIT_IPC_HANDLE" in os.environ: + args.pretty = False + io.tool_output("VSCode terminal detected, pretty output has been disabled.") + io.tool_output("Use /help to see in-chat commands, run with --help to see cmd line args") if git_root and Path.cwd().resolve() != Path(git_root).resolve(): @@ -685,7 +686,9 @@ def main(argv=None, input=None, output=None, force_git_root=None): io.add_to_input_history(args.message) io.tool_output() coder.run(with_message=args.message) - elif args.message_file: + return + + if args.message_file: try: message_from_file = io.read_text(args.message_file) io.tool_output() @@ -696,8 +699,9 @@ def main(argv=None, input=None, output=None, force_git_root=None): except IOError as e: io.tool_error(f"Error reading message file: {e}") return 1 - else: - coder.run() + return + + coder.run() if __name__ == "__main__":