mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
Added the "code" chat mode
This commit is contained in:
parent
87eb7359d1
commit
c17ef53deb
3 changed files with 41 additions and 22 deletions
|
@ -1,23 +1,17 @@
|
||||||
from .base_coder import Coder
|
from .base_coder import Coder
|
||||||
from .editblock_coder import EditBlockCoder
|
from .editblock_coder import EditBlockCoder
|
||||||
from .editblock_fenced_coder import EditBlockFencedCoder
|
from .editblock_fenced_coder import EditBlockFencedCoder
|
||||||
from .editblock_func_coder import EditBlockFunctionCoder
|
|
||||||
from .help_coder import HelpCoder
|
from .help_coder import HelpCoder
|
||||||
from .single_wholefile_func_coder import SingleWholeFileFunctionCoder
|
|
||||||
from .udiff_coder import UnifiedDiffCoder
|
from .udiff_coder import UnifiedDiffCoder
|
||||||
from .wholefile_coder import WholeFileCoder
|
from .wholefile_coder import WholeFileCoder
|
||||||
from .wholefile_func_coder import WholeFileFunctionCoder
|
|
||||||
from .ask_coder import AskCoder
|
from .ask_coder import AskCoder
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
HelpCoder,
|
||||||
|
AskCoder,
|
||||||
Coder,
|
Coder,
|
||||||
EditBlockCoder,
|
EditBlockCoder,
|
||||||
EditBlockFencedCoder,
|
EditBlockFencedCoder,
|
||||||
WholeFileCoder,
|
WholeFileCoder,
|
||||||
WholeFileFunctionCoder,
|
|
||||||
EditBlockFunctionCoder,
|
|
||||||
SingleWholeFileFunctionCoder,
|
|
||||||
UnifiedDiffCoder,
|
UnifiedDiffCoder,
|
||||||
HelpCoder,
|
|
||||||
AskCoder,
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -22,8 +22,9 @@ Other messages in the chat may contain outdated versions of the files' contents.
|
||||||
files_no_full_files_with_repo_map = ""
|
files_no_full_files_with_repo_map = ""
|
||||||
files_no_full_files_with_repo_map_reply = ""
|
files_no_full_files_with_repo_map_reply = ""
|
||||||
|
|
||||||
repo_content_prefix = """Here are summaries of some files present in my git repository.
|
repo_content_prefix = """I am working with you on code in a git repository.
|
||||||
If you need to see more of the contents of these files, ask me to *add them to the chat*.
|
Here are summaries of some files present in my git repo.
|
||||||
|
If you need to see the full contents of any files to answer my questions, ask me to *add them to the chat*.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
system_reminder = ""
|
system_reminder = ""
|
||||||
|
|
|
@ -2,6 +2,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from collections import OrderedDict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import git
|
import git
|
||||||
|
@ -50,22 +51,45 @@ class Commands:
|
||||||
from aider import coders
|
from aider import coders
|
||||||
|
|
||||||
ef = args.strip()
|
ef = args.strip()
|
||||||
valid_formats = [
|
valid_formats = OrderedDict(
|
||||||
(coder.edit_format, coder.__doc__.strip().split('\n')[0] if coder.__doc__ else "No description")
|
sorted(
|
||||||
for coder in coders.__all__ if getattr(coder, 'edit_format', None)
|
(
|
||||||
|
coder.edit_format,
|
||||||
|
coder.__doc__.strip().split("\n")[0] if coder.__doc__ else "No description",
|
||||||
|
)
|
||||||
|
for coder in coders.__all__
|
||||||
|
if getattr(coder, "edit_format", None)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
show_formats = OrderedDict(
|
||||||
|
[
|
||||||
|
("help", "Get help about using aider (usage, config, troubleshoot)."),
|
||||||
|
("ask", "Ask questions about your code without making any changes."),
|
||||||
|
("code", "Ask for changes to your code (using the best edit format)."),
|
||||||
]
|
]
|
||||||
|
)
|
||||||
|
|
||||||
if ef not in [format[0] for format in valid_formats]:
|
if ef not in valid_formats and ef not in show_formats:
|
||||||
if ef:
|
if ef:
|
||||||
self.io.tool_error(f"Chat mode \"{ef}\" must be one of:\n")
|
self.io.tool_error(f'Chat mode "{ef}" should be one of these:\n')
|
||||||
else:
|
else:
|
||||||
self.io.tool_output(f"Chat mode must be one of:\n")
|
self.io.tool_output("Chat mode should be one of these:\n")
|
||||||
|
|
||||||
|
max_format_length = max(len(format) for format in valid_formats.keys())
|
||||||
|
for format, description in show_formats.items():
|
||||||
|
self.io.tool_output(f"- {format:<{max_format_length}} : {description}")
|
||||||
|
|
||||||
|
self.io.tool_output("\nOr a valid edit format:\n")
|
||||||
|
for format, description in valid_formats.items():
|
||||||
|
if format not in show_formats:
|
||||||
|
self.io.tool_output(f"- {format:<{max_format_length}} : {description}")
|
||||||
|
|
||||||
max_format_length = max(len(format) for format, _ in valid_formats)
|
|
||||||
for format, description in valid_formats:
|
|
||||||
self.io.tool_output(f"- {format:<{max_format_length}} {description}")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if ef == "code":
|
||||||
|
ef = self.coder.main_model.edit_format
|
||||||
|
|
||||||
raise SwitchCoder(edit_format=ef)
|
raise SwitchCoder(edit_format=ef)
|
||||||
|
|
||||||
def completions_model(self):
|
def completions_model(self):
|
||||||
|
@ -124,13 +148,13 @@ class Commands:
|
||||||
if not attr.startswith("cmd_"):
|
if not attr.startswith("cmd_"):
|
||||||
continue
|
continue
|
||||||
cmd = attr[4:]
|
cmd = attr[4:]
|
||||||
cmd = cmd.replace('_', '-')
|
cmd = cmd.replace("_", "-")
|
||||||
commands.append("/" + cmd)
|
commands.append("/" + cmd)
|
||||||
|
|
||||||
return commands
|
return commands
|
||||||
|
|
||||||
def do_run(self, cmd_name, args):
|
def do_run(self, cmd_name, args):
|
||||||
cmd_name = cmd_name.replace('-', '_')
|
cmd_name = cmd_name.replace("-", "_")
|
||||||
cmd_method_name = f"cmd_{cmd_name}"
|
cmd_method_name = f"cmd_{cmd_name}"
|
||||||
cmd_method = getattr(self, cmd_method_name, None)
|
cmd_method = getattr(self, cmd_method_name, None)
|
||||||
if cmd_method:
|
if cmd_method:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue