From cd838901d17b3e78b6af7a001a5760740e51efd7 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 20 Apr 2024 09:59:56 -0700 Subject: [PATCH] Added improved editing support for command-r-plus --- aider/coders/editblock_coder.py | 12 +++++++++--- aider/coders/wholefile_coder.py | 2 ++ aider/models.py | 10 ++++++++++ docs/llms.md | 15 +++++++++++++-- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index fe367a173..4c5339359 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -312,7 +312,10 @@ separators = "|".join([HEAD, DIVIDER, UPDATED]) split_re = re.compile(r"^((?:" + separators + r")[ ]*\n)", re.MULTILINE | re.DOTALL) -missing_filename_err = f"Bad/missing filename. Filename should be alone on the line before {HEAD}" +missing_filename_err = ( + "Bad/missing filename. The filename must be alone on the line before the opening fence" + " {fence[0]}" +) def strip_filename(filename, fence): @@ -325,6 +328,9 @@ def strip_filename(filename, fence): if filename.startswith(start_fence): return + filename = filename.rstrip(":") + filename = filename.strip("`") + return filename @@ -363,12 +369,12 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE): if current_filename: filename = current_filename else: - raise ValueError(missing_filename_err) + raise ValueError(missing_filename_err.format(fence=fence)) except IndexError: if current_filename: filename = current_filename else: - raise ValueError(missing_filename_err) + raise ValueError(missing_filename_err.format(fence=fence)) current_filename = filename diff --git a/aider/coders/wholefile_coder.py b/aider/coders/wholefile_coder.py index 7c0975cb7..4b244f637 100644 --- a/aider/coders/wholefile_coder.py +++ b/aider/coders/wholefile_coder.py @@ -65,6 +65,8 @@ class WholeFileCoder(Coder): fname_source = "block" fname = lines[i - 1].strip() fname = fname.strip("*") # handle **filename.py** + fname = fname.rstrip(":") + fname = fname.strip("`") # Did gpt prepend a bogus dir? It especially likes to # include the path/to prefix from the one-shot example in diff --git a/aider/models.py b/aider/models.py index 672138446..095f6dd7d 100644 --- a/aider/models.py +++ b/aider/models.py @@ -117,6 +117,14 @@ MODEL_SETTINGS = [ use_repo_map=True, send_undo_reply=True, ), + # Cohere + ModelSettings( + "command-r-plus", + "whole", + weak_model_name="command-r-plus", + use_repo_map=True, + send_undo_reply=True, + ), ] @@ -187,6 +195,8 @@ class Model: return # <-- # use the defaults + if self.edit_format == "diff": + self.use_repo_map = True def __str__(self): return self.name diff --git a/docs/llms.md b/docs/llms.md index 1b6efa205..f2b139f0c 100644 --- a/docs/llms.md +++ b/docs/llms.md @@ -4,9 +4,11 @@ Aider works well with OpenAI's GPT 3.5, GPT-4, GPT-4 Turbo with Vision and Anthropic's Claude 3 Opus and Sonnet. -GPT-4 Turbo and Claude 3 Opus are recommended for the best results. +GPT-4 Turbo and Claude 3 Opus are recommended, as they are the very best coding assistants. +Cohere offers *free* API access to their Command-R+ model, which works well with aider +as a *very basic* coding assistant. -Aider also supports connecting to almost any LLM, +Aider supports connecting to almost any LLM, but it may not work well with some models depending on their capabilities. For example, GPT-3.5 is just barely capable of reliably *editing code* to provide aider's interactive "pair programming" style workflow. @@ -14,6 +16,7 @@ So you should expect that models which are less capable than GPT-3.5 may struggl - [OpenAI](#openai) - [Anthropic](#anthropic) +- [Cohere](#cohere) - [Azure](#azure) - [OpenAI compatible APIs](#openai-compatible-apis) - [Other LLMs](#other-llms) @@ -54,6 +57,14 @@ You can use `aider --model ` to use any other Anthropic model. For example, if you want to use a specific version of Opus you could do `aider --model claude-3-opus-20240229`. +## Cohere + +To work with Cohere's models, you need to provide your +[Cohere API key](https://dashboard.cohere.com/) +in the `COHERE_API_KEY` environment variable. + +- **Command-R+**: `aider --model command-r-plus` + ## Azure Aider can be configured to connect to the OpenAI models on Azure.