improved prompting, fix ctags bug

This commit is contained in:
Paul Gauthier 2023-05-19 09:47:06 -07:00
parent 4593e7812c
commit 680fc45fb3
4 changed files with 33 additions and 15 deletions

View file

@ -159,17 +159,28 @@ class Coder:
return prompt
def get_files_messages(self):
all_content = ""
if self.abs_fnames:
files_content = prompts.files_content_prefix
files_content += self.get_files_content()
all_content = files_content
all_content += files_content
if self.repo is not None:
files_listing = get_tags_map(self.get_all_abs_files())
repo_content = prompts.repo_content_prefix
other_files = set(self.get_all_abs_files()) - set(self.abs_fnames)
if other_files:
files_listing = get_tags_map(other_files)
if self.abs_fnames:
other = "other "
else:
other = ""
repo_content = prompts.repo_content_prefix.format(other=other)
repo_content += files_listing
all_content = repo_content + "\n\n" + files_content
if all_content:
all_content += "\n\n"
all_content += repo_content
files_messages = [
dict(role="user", content=all_content),
@ -180,7 +191,7 @@ class Coder:
),
]
# utils.show_messages(files_messages, "FILES")
utils.show_messages(files_messages, "FILES")
return files_messages
def run(self):

View file

@ -50,12 +50,13 @@ def split_path(path, root_dname):
def get_tags(filename, root_dname):
yield split_path(filename, root_dname)
cmd = ["ctags", "--fields=+S", "--output-format=json", filename]
output = subprocess.check_output(cmd).decode("utf-8")
output = output.splitlines()
if not output:
yield split_path(filename, root_dname)
for line in output:
tag = json.loads(line)
path = tag.get("path")

View file

@ -79,10 +79,13 @@ files_content_gpt_no_edits = "I wasn't able to see any properly formatted edits
files_content_local_edits = "I made some changes to the files myself."
repo_content_prefix = "Here is a map showing all the other files and key content:\n\n"
files_content_prefix = (
"You can propose changes to *only* these files (ask if you need to see others):\n\n"
"You can propose changes to *only* these files (ask before editing others):\n\n"
)
repo_content_prefix = (
"Here is a map showing all the {other}files and ctags content. You *must* ask with the full"
" path of the file before suggesting edits to these files:\n\n"
)
files_content_suffix = (

View file

@ -5,6 +5,7 @@ from unittest.mock import MagicMock
from aider.commands import Commands
from aider.io import InputOutput
class TestCommands(TestCase):
def test_cmd_add(self):
# Create a temporary directory and change the current working directory
@ -13,7 +14,9 @@ class TestCommands(TestCase):
# Initialize the Commands and InputOutput objects
io = InputOutput(pretty=False, yes=True)
coder = MagicMock()
from aider.coder import Coder
coder = Coder(io)
commands = Commands(io, coder)
# Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string