mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 00:05:01 +00:00
Added diff-fenced coder
This commit is contained in:
parent
921c7ceb80
commit
5d32dd77fc
5 changed files with 118 additions and 3 deletions
|
@ -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,
|
||||
|
|
|
@ -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":
|
||||
|
|
11
aider/coders/editblock_fenced_coder.py
Normal file
11
aider/coders/editblock_fenced_coder.py
Normal file
|
@ -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()
|
95
aider/coders/editblock_fenced_prompts.py
Normal file
95
aider/coders/editblock_fenced_prompts.py
Normal file
|
@ -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]}
|
||||
""",
|
||||
),
|
||||
]
|
|
@ -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,
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue