diff --git a/aider/coders/__init__.py b/aider/coders/__init__.py index bf9163328..19d12b0d7 100644 --- a/aider/coders/__init__.py +++ b/aider/coders/__init__.py @@ -1,5 +1,6 @@ from .base_coder import Coder from .editblock_coder import EditBlockCoder +from .editblock_fenced_coder import EditBlockFencedCoder from .editblock_func_coder import EditBlockFunctionCoder from .single_wholefile_func_coder import SingleWholeFileFunctionCoder from .udiff_coder import UnifiedDiffCoder @@ -9,6 +10,7 @@ from .wholefile_func_coder import WholeFileFunctionCoder __all__ = [ Coder, EditBlockCoder, + EditBlockFencedCoder, WholeFileCoder, WholeFileFunctionCoder, EditBlockFunctionCoder, diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 45d67b1ed..74122ac33 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -69,7 +69,12 @@ class Coder: from_coder=None, **kwargs, ): - from . import EditBlockCoder, UnifiedDiffCoder, WholeFileCoder + from . import ( + EditBlockCoder, + EditBlockFencedCoder, + UnifiedDiffCoder, + WholeFileCoder, + ) if not main_model: main_model = models.Model(models.DEFAULT_MODEL_NAME) @@ -102,6 +107,8 @@ class Coder: if edit_format == "diff": res = EditBlockCoder(main_model, io, **kwargs) + elif edit_format == "diff-fenced": + res = EditBlockFencedCoder(main_model, io, **kwargs) elif edit_format == "whole": res = WholeFileCoder(main_model, io, **kwargs) elif edit_format == "udiff": diff --git a/aider/coders/editblock_fenced_coder.py b/aider/coders/editblock_fenced_coder.py new file mode 100644 index 000000000..2f612c754 --- /dev/null +++ b/aider/coders/editblock_fenced_coder.py @@ -0,0 +1,11 @@ +from ..dump import dump # noqa: F401 +from .editblock_coder import EditBlockCoder +from .editblock_fenced_prompts import EditBlockFencedPrompts + + +class EditBlockFencedCoder(EditBlockCoder): + edit_format = "diff-fenced" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.gpt_prompts = EditBlockFencedPrompts() diff --git a/aider/coders/editblock_fenced_prompts.py b/aider/coders/editblock_fenced_prompts.py new file mode 100644 index 000000000..07a8fbbab --- /dev/null +++ b/aider/coders/editblock_fenced_prompts.py @@ -0,0 +1,95 @@ +# flake8: noqa: E501 + +from .editblock_prompts import EditBlockPrompts + + +class EditBlockFencedPrompts(EditBlockPrompts): + example_messages = [ + dict( + role="user", + content="Change get_factorial() to use math.factorial", + ), + dict( + role="assistant", + content="""To make this change we need to modify `mathweb/flask/app.py` to: + +1. Import the math package. +2. Remove the existing factorial() function. +3. Update get_factorial() to call math.factorial instead. + +Here are the *SEARCH/REPLACE* blocks: + +{fence[0]} +mathweb/flask/app.py +<<<<<<< SEARCH +from flask import Flask +======= +import math +from flask import Flask +>>>>>>> REPLACE +{fence[1]} + +{fence[0]} +mathweb/flask/app.py +<<<<<<< SEARCH +def factorial(n): + "compute factorial" + + if n == 0: + return 1 + else: + return n * factorial(n-1) + +======= +>>>>>>> REPLACE +{fence[1]} + +{fence[0]} +mathweb/flask/app.py +<<<<<<< SEARCH + return str(factorial(n)) +======= + return str(math.factorial(n)) +>>>>>>> REPLACE +{fence[1]} +<<<<<<< HEAD +""", + ), + dict( + role="user", + content="Refactor hello() into its own file.", + ), + dict( + role="assistant", + content="""To make this change we need to modify `main.py` and make a new file `hello.py`: + +1. Make a new hello.py file with hello() in it. +2. Remove hello() from main.py and replace it with an import. + +Here are the *SEARCH/REPLACE* blocks: + +{fence[0]} +hello.py +<<<<<<< SEARCH +======= +def hello(): + "print a greeting" + + print("hello") +>>>>>>> REPLACE +{fence[1]} + +{fence[0]} +main.py +<<<<<<< SEARCH +def hello(): + "print a greeting" + + print("hello") +======= +from hello import hello +>>>>>>> REPLACE +{fence[1]} +""", + ), + ] diff --git a/aider/models.py b/aider/models.py index dc7092d2c..24d001eee 100644 --- a/aider/models.py +++ b/aider/models.py @@ -154,13 +154,13 @@ MODEL_SETTINGS = [ # Gemini ModelSettings( "gemini/gemini-1.5-pro", - "whole", + "diff-fenced", use_repo_map=True, send_undo_reply=True, ), ModelSettings( "gemini/gemini-1.5-pro-latest", - "whole", + "diff-fenced", use_repo_map=True, send_undo_reply=True, ),