From 72572f06d99aee80e941da8bb00456cd346493fa Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 07:41:42 -0300 Subject: [PATCH 001/288] fix: Improve commit message generation by handling large diffs --- aider/repo.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/aider/repo.py b/aider/repo.py index 5403c5845..ab98bc081 100644 --- a/aider/repo.py +++ b/aider/repo.py @@ -155,10 +155,6 @@ class GitRepo: return self.repo.git_dir def get_commit_message(self, diffs, context): - if len(diffs) >= 4 * 1024 * 4: - self.io.tool_error("Diff is too large to generate a commit message.") - return - diffs = "# Diffs:\n" + diffs content = "" @@ -172,7 +168,12 @@ class GitRepo: dict(role="user", content=content), ] + commit_message = None for model in self.models: + num_tokens = model.token_count(messages) + max_tokens = model.info.get("max_input_tokens") or 0 + if max_tokens and num_tokens > max_tokens: + continue commit_message = simple_send_with_retries(model.name, messages) if commit_message: break From e48fecee14693162189eec29d92117a45ece7917 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 07:45:39 -0300 Subject: [PATCH 002/288] fix: Handle missing model info values gracefully --- aider/coders/base_coder.py | 6 +++--- aider/commands.py | 4 ++-- aider/models.py | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 35c3ac8d5..ddf9e85e5 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -852,7 +852,7 @@ class Coder: final = messages[-1] - max_input_tokens = self.main_model.info.get("max_input_tokens") + max_input_tokens = self.main_model.info.get("max_input_tokens") or 0 # Add the reminder prompt if we still have room to include it. if ( max_input_tokens is None @@ -1011,10 +1011,10 @@ class Coder: output_tokens = 0 if self.partial_response_content: output_tokens = self.main_model.token_count(self.partial_response_content) - max_output_tokens = self.main_model.info.get("max_output_tokens", 0) + max_output_tokens = self.main_model.info.get("max_output_tokens") or 0 input_tokens = self.main_model.token_count(self.format_messages()) - max_input_tokens = self.main_model.info.get("max_input_tokens", 0) + max_input_tokens = self.main_model.info.get("max_input_tokens") or 0 total_tokens = input_tokens + output_tokens diff --git a/aider/commands.py b/aider/commands.py index a1a225261..5ec6e451c 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -344,7 +344,7 @@ class Commands: total_cost = 0.0 for tk, msg, tip in res: total += tk - cost = tk * self.coder.main_model.info.get("input_cost_per_token", 0) + cost = tk * (self.coder.main_model.info.get("input_cost_per_token") or 0) total_cost += cost msg = msg.ljust(col_width) self.io.tool_output(f"${cost:7.4f} {fmt(tk)} {msg} {tip}") # noqa: E231 @@ -352,7 +352,7 @@ class Commands: self.io.tool_output("=" * (width + cost_width + 1)) self.io.tool_output(f"${total_cost:7.4f} {fmt(total)} tokens total") # noqa: E231 - limit = self.coder.main_model.info.get("max_input_tokens", 0) + limit = self.coder.main_model.info.get("max_input_tokens") or 0 if not limit: return diff --git a/aider/models.py b/aider/models.py index 344fc9d78..12a8a8046 100644 --- a/aider/models.py +++ b/aider/models.py @@ -405,9 +405,7 @@ class Model: self.missing_keys = res.get("missing_keys") self.keys_in_environment = res.get("keys_in_environment") - max_input_tokens = self.info.get("max_input_tokens") - if not max_input_tokens: - max_input_tokens = 0 + max_input_tokens = self.info.get("max_input_tokens") or 0 if max_input_tokens < 32 * 1024: self.max_chat_history_tokens = 1024 else: From 0e14014118b76c65511ff97b01a524d15606a53c Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 11:24:37 -0300 Subject: [PATCH 003/288] restore openrouter attribution with extra_headers --- aider/models.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/aider/models.py b/aider/models.py index 12a8a8046..c716c4302 100644 --- a/aider/models.py +++ b/aider/models.py @@ -273,7 +273,11 @@ MODEL_SETTINGS = [ examples_as_sys_msg=True, can_prefill=True, max_tokens=8192, - extra_headers={"anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15"}, + extra_headers={ + "anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15", + "HTTP-Referer": "https://aider.chat", + "X-Title": "Aider", + }, ), ModelSettings( "openrouter/anthropic/claude-3.5-sonnet", @@ -284,7 +288,11 @@ MODEL_SETTINGS = [ can_prefill=True, accepts_images=True, max_tokens=8192, - extra_headers={"anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15"}, + extra_headers={ + "anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15", + "HTTP-Referer": "https://aider.chat", + "X-Title": "Aider", + }, ), # Vertex AI Claude models # Does not yet support 8k token From 19ad89e1d76fdf54b7029f75adb2bc5f4137c86a Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 11:26:15 -0300 Subject: [PATCH 004/288] Added gpt-4o-2024-08-06 --- HISTORY.md | 4 ++++ aider/models.py | 10 ++++++++++ aider/website/docs/leaderboards/index.md | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 239e3b238..c00213313 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,10 @@ # Release history +### Aider v0.48.1 + +- Added `openai/gpt-4o-2024-08-06`. + ### Aider v0.48.0 - Performance improvements for large/mono repos. diff --git a/aider/models.py b/aider/models.py index c716c4302..96db32bb6 100644 --- a/aider/models.py +++ b/aider/models.py @@ -152,6 +152,16 @@ MODEL_SETTINGS = [ lazy=True, reminder_as_sys_msg=True, ), + ModelSettings( + "gpt-4o-2024-08-06", + "diff", + weak_model_name="gpt-4o-mini", + use_repo_map=True, + send_undo_reply=True, + accepts_images=True, + lazy=True, + reminder_as_sys_msg=True, + ), ModelSettings( "gpt-4o", "diff", diff --git a/aider/website/docs/leaderboards/index.md b/aider/website/docs/leaderboards/index.md index 66fc11f73..3b1140705 100644 --- a/aider/website/docs/leaderboards/index.md +++ b/aider/website/docs/leaderboards/index.md @@ -305,6 +305,6 @@ latest_mod_time = max(mod_times) mod_date = datetime.datetime.fromtimestamp(latest_mod_time) cog.out(f"{mod_date.strftime('%B %d, %Y.')}") ]]]--> -August 06, 2024. +August 07, 2024.

From 1ecc780f740ff24dedecaafc5fdd937f8b8e89e8 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 11:29:31 -0300 Subject: [PATCH 005/288] Revert "Stop using litellm._should_retry" This reverts commit 1e232d4db685d34c9a79381a2fb6262c21046d87. --- aider/sendchat.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/aider/sendchat.py b/aider/sendchat.py index d840fb476..e3d40c23c 100644 --- a/aider/sendchat.py +++ b/aider/sendchat.py @@ -18,6 +18,27 @@ def lazy_litellm_retry_decorator(func): def wrapper(*args, **kwargs): import httpx + def should_giveup(e): + if not hasattr(e, "status_code"): + return False + + if type(e) in ( + httpx.ConnectError, + httpx.RemoteProtocolError, + httpx.ReadTimeout, + ): + return False + + # These seem to return .status_code = "" + # litellm._should_retry() expects an int and throws a TypeError + # + # litellm.llms.anthropic.AnthropicError + # litellm.exceptions.APIError + if not e.status_code: + return False + + return not litellm._should_retry(e.status_code) + decorated_func = backoff.on_exception( backoff.expo, ( @@ -32,6 +53,7 @@ def lazy_litellm_retry_decorator(func): litellm.exceptions.InternalServerError, litellm.llms.anthropic.AnthropicError, ), + giveup=should_giveup, max_time=60, on_backoff=lambda details: print( f"{details.get('exception', 'Exception')}\nRetry in {details['wait']:.1f} seconds." From 3d66aea572234059d128c971df63d3aab41125ca Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 11:30:43 -0300 Subject: [PATCH 006/288] retry sends in most cases --- aider/sendchat.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aider/sendchat.py b/aider/sendchat.py index e3d40c23c..c1ccbbe0e 100644 --- a/aider/sendchat.py +++ b/aider/sendchat.py @@ -26,6 +26,13 @@ def lazy_litellm_retry_decorator(func): httpx.ConnectError, httpx.RemoteProtocolError, httpx.ReadTimeout, + litellm.exceptions.APIConnectionError, + litellm.exceptions.APIError, + litellm.exceptions.RateLimitError, + litellm.exceptions.ServiceUnavailableError, + litellm.exceptions.Timeout, + litellm.exceptions.InternalServerError, + litellm.llms.anthropic.AnthropicError, ): return False From 0e60dfe5f42311b5c6ef17bfb6704fb09caa4656 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 11:30:57 -0300 Subject: [PATCH 007/288] copy --- HISTORY.md | 4 ++++ aider/website/HISTORY.md | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index c00213313..cfe1856c9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,10 @@ ### Aider v0.48.1 - Added `openai/gpt-4o-2024-08-06`. +- Worked around litellm bug that removes OpenRouter app headers when using `extra_headers`. +- Improved progress indication during repo map processing. +- Corrected instructions for upgrading the docker container to latest aider version. +- Removed obsolete limit on 16k token limit on commit diffs. ### Aider v0.48.0 diff --git a/aider/website/HISTORY.md b/aider/website/HISTORY.md index a523b16b1..ad32aa8ab 100644 --- a/aider/website/HISTORY.md +++ b/aider/website/HISTORY.md @@ -16,6 +16,14 @@ cog.out(text) # Release history +### Aider v0.48.1 + +- Added `openai/gpt-4o-2024-08-06`. +- Worked around litellm bug that removes OpenRouter app headers when using `extra_headers`. +- Improved progress indication during repo map processing. +- Corrected instructions for upgrading the docker container to latest aider version. +- Removed obsolete limit on 16k token limit on commit diffs. + ### Aider v0.48.0 - Performance improvements for large/mono repos. From efc71a0e83fd00cd1edc2646e4f7c69633f22413 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 7 Aug 2024 11:42:11 -0300 Subject: [PATCH 008/288] refactor: Refactor "https://aider.chat" and "Aider" into constants in llm.py --- aider/llm.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aider/llm.py b/aider/llm.py index f65398729..950f1a29a 100644 --- a/aider/llm.py +++ b/aider/llm.py @@ -4,8 +4,11 @@ import warnings warnings.filterwarnings("ignore", category=UserWarning, module="pydantic") -os.environ["OR_SITE_URL"] = "http://aider.chat" -os.environ["OR_APP_NAME"] = "Aider" +AIDER_SITE_URL = "https://aider.chat" +AIDER_APP_NAME = "Aider" + +os.environ["OR_SITE_URL"] = AIDER_SITE_URL +os.environ["OR_APP_NAME"] = AIDER_APP_NAME # `import litellm` takes 1.5 seconds, defer it! From f16564994f62abcf5eaf95192c73dfd0ac47dccf Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 7 Aug 2024 11:42:34 -0300 Subject: [PATCH 009/288] feat: use constants from llm.py in models.py --- aider/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aider/models.py b/aider/models.py index 96db32bb6..5e6c21fdd 100644 --- a/aider/models.py +++ b/aider/models.py @@ -13,7 +13,7 @@ from PIL import Image from aider import urls from aider.dump import dump # noqa: F401 -from aider.llm import litellm +from aider.llm import litellm, AIDER_SITE_URL, AIDER_APP_NAME DEFAULT_MODEL_NAME = "gpt-4o" @@ -285,8 +285,8 @@ MODEL_SETTINGS = [ max_tokens=8192, extra_headers={ "anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15", - "HTTP-Referer": "https://aider.chat", - "X-Title": "Aider", + "HTTP-Referer": AIDER_SITE_URL, + "X-Title": AIDER_APP_NAME, }, ), ModelSettings( From f1bd90c02465b268d413e263ed599b24d536c966 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 7 Aug 2024 11:42:37 -0300 Subject: [PATCH 010/288] style: Fix import order in aider/models.py --- aider/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/models.py b/aider/models.py index 5e6c21fdd..f2fb3b458 100644 --- a/aider/models.py +++ b/aider/models.py @@ -13,7 +13,7 @@ from PIL import Image from aider import urls from aider.dump import dump # noqa: F401 -from aider.llm import litellm, AIDER_SITE_URL, AIDER_APP_NAME +from aider.llm import AIDER_APP_NAME, AIDER_SITE_URL, litellm DEFAULT_MODEL_NAME = "gpt-4o" From cec596cadfc01c8e7eacd9267df0e8004428d68e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 11:43:32 -0300 Subject: [PATCH 011/288] copy --- HISTORY.md | 2 +- aider/website/HISTORY.md | 2 +- aider/website/docs/llms/other.md | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index cfe1856c9..a1062cb40 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,7 +7,7 @@ - Worked around litellm bug that removes OpenRouter app headers when using `extra_headers`. - Improved progress indication during repo map processing. - Corrected instructions for upgrading the docker container to latest aider version. -- Removed obsolete limit on 16k token limit on commit diffs. +- Removed obsolete 16k token limit on commit diffs, use per-model limits. ### Aider v0.48.0 diff --git a/aider/website/HISTORY.md b/aider/website/HISTORY.md index ad32aa8ab..cc612d201 100644 --- a/aider/website/HISTORY.md +++ b/aider/website/HISTORY.md @@ -22,7 +22,7 @@ cog.out(text) - Worked around litellm bug that removes OpenRouter app headers when using `extra_headers`. - Improved progress indication during repo map processing. - Corrected instructions for upgrading the docker container to latest aider version. -- Removed obsolete limit on 16k token limit on commit diffs. +- Removed obsolete 16k token limit on commit diffs, use per-model limits. ### Aider v0.48.0 diff --git a/aider/website/docs/llms/other.md b/aider/website/docs/llms/other.md index 007b0fbf1..7c34109fe 100644 --- a/aider/website/docs/llms/other.md +++ b/aider/website/docs/llms/other.md @@ -77,6 +77,7 @@ cog.out(''.join(lines)) - FIREWORKS_API_KEY - FRIENDLIAI_API_KEY - GEMINI_API_KEY +- GITHUB_API_KEY - GROQ_API_KEY - HUGGINGFACE_API_KEY - MARITALK_API_KEY From 77c13c5cbe64e4e7f362144ce657a5510ee716e0 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 11:45:51 -0300 Subject: [PATCH 012/288] version bump to 0.48.1 --- aider/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/__init__.py b/aider/__init__.py index 1ec4c9f61..f2897f343 100644 --- a/aider/__init__.py +++ b/aider/__init__.py @@ -1 +1 @@ -__version__ = "0.48.1-dev" +__version__ = "0.48.1" From ed38497c684fb0adea014c2c24a414da1dd6c800 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 11:47:36 -0300 Subject: [PATCH 013/288] set version to 0.48.2-dev --- aider/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/__init__.py b/aider/__init__.py index f2897f343..11303a548 100644 --- a/aider/__init__.py +++ b/aider/__init__.py @@ -1 +1 @@ -__version__ = "0.48.1" +__version__ = "0.48.2-dev" From 0a5b5c3fd67ce86f101ca8cc88d2cd5d2cd364e3 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 13:13:10 -0300 Subject: [PATCH 014/288] fix: Fix token_count method to handle list of messages --- aider/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aider/models.py b/aider/models.py index f2fb3b458..908404343 100644 --- a/aider/models.py +++ b/aider/models.py @@ -528,6 +528,9 @@ class Model: return litellm.encode(model=self.name, text=text) def token_count(self, messages): + if type(messages) is list: + return litellm.token_counter(model=self.name, messages=messages) + if not self.tokenizer: return From c8b5375709f306d652645994f743c5a488b5744e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 7 Aug 2024 13:39:02 -0300 Subject: [PATCH 015/288] do not supply . if no git_dname #865 --- aider/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/main.py b/aider/main.py index 8bb04ef2b..a7c3ac808 100644 --- a/aider/main.py +++ b/aider/main.py @@ -475,7 +475,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F repo = GitRepo( io, fnames, - git_dname or ".", + git_dname, args.aiderignore, models=main_model.commit_message_models(), attribute_author=args.attribute_author, From bb4ee1a2212faf9b5b3015cca79c5cfcb515481b Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 8 Aug 2024 09:56:03 -0300 Subject: [PATCH 016/288] perf: cache TreeContext for each filename and re-use it --- aider/repomap.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/aider/repomap.py b/aider/repomap.py index c7b2629fb..5836cdd4b 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -60,6 +60,9 @@ class RepoMap: self.main_model = main_model + self.tree_cache = {} + self.tree_context_cache = {} + def token_count(self, text): len_text = len(text) if len_text < 200: @@ -471,24 +474,28 @@ class RepoMap: if key in self.tree_cache: return self.tree_cache[key] - code = self.io.read_text(abs_fname) or "" - if not code.endswith("\n"): - code += "\n" + if rel_fname not in self.tree_context_cache: + code = self.io.read_text(abs_fname) or "" + if not code.endswith("\n"): + code += "\n" - context = TreeContext( - rel_fname, - code, - color=False, - line_number=False, - child_context=False, - last_line=False, - margin=0, - mark_lois=False, - loi_pad=0, - # header_max=30, - show_top_of_file_parent_scope=False, - ) + context = TreeContext( + rel_fname, + code, + color=False, + line_number=False, + child_context=False, + last_line=False, + margin=0, + mark_lois=False, + loi_pad=0, + # header_max=30, + show_top_of_file_parent_scope=False, + ) + self.tree_context_cache[rel_fname] = context + context = self.tree_context_cache[rel_fname] + context.clear_lines_of_interest() context.add_lines_of_interest(lois) context.add_context() res = context.format() From 30af7f68bd7b6ab6271701ddec0cbea414ad1c7a Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 8 Aug 2024 09:58:46 -0300 Subject: [PATCH 017/288] fix: Clear lines of interest instead of clearing the entire context --- aider/repomap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/repomap.py b/aider/repomap.py index 5836cdd4b..27ca3c0c2 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -495,7 +495,7 @@ class RepoMap: self.tree_context_cache[rel_fname] = context context = self.tree_context_cache[rel_fname] - context.clear_lines_of_interest() + context.lines_of_interest = set() context.add_lines_of_interest(lois) context.add_context() res = context.format() From 381f33c743348c43a7ca528faebb37f4f30a3bee Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 8 Aug 2024 13:00:07 -0300 Subject: [PATCH 018/288] Added py -m aider tip to main install page --- aider/website/_includes/python-m-aider.md | 4 ++++ aider/website/docs/install.md | 2 ++ aider/website/docs/install/install.md | 5 +---- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 aider/website/_includes/python-m-aider.md diff --git a/aider/website/_includes/python-m-aider.md b/aider/website/_includes/python-m-aider.md new file mode 100644 index 000000000..fe8f5d499 --- /dev/null +++ b/aider/website/_includes/python-m-aider.md @@ -0,0 +1,4 @@ +{: .tip } +In some environments the `aider` command may not be available +on your shell path. +You can also run aider like this: `python -m aider` diff --git a/aider/website/docs/install.md b/aider/website/docs/install.md index 58cc3957b..df5358c89 100644 --- a/aider/website/docs/install.md +++ b/aider/website/docs/install.md @@ -15,6 +15,8 @@ for more details, or the [usage instructions](https://aider.chat/docs/usage.html) to start coding with aider. +{% include python-m-aider.md %} +