From 58e763cee76fe4ec47e946e0b490fc62fe429a2b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 29 Jun 2023 15:10:33 -0700 Subject: [PATCH] roughed in diff-func-string --- aider/coders/base_coder.py | 4 +-- aider/coders/editblock_func_coder.py | 39 +++++++++++++++++++++++++--- aider/utils.py | 5 +++- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 52de85ed4..5dd284ccd 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -87,7 +87,7 @@ class Coder: elif edit_format == "whole-func": return WholeFileFunctionCoder(main_model, io, **kwargs) elif edit_format == "diff-func": - return EditBlockFunctionCoder(main_model, io, **kwargs) + return EditBlockFunctionCoder("string", main_model, io, **kwargs) else: raise ValueError(f"Unknown edit format {edit_format}") @@ -432,7 +432,7 @@ class Coder: messages += self.cur_messages if self.verbose: - utils.show_messages(messages) + utils.show_messages(messages, functions=self.functions) exhausted = False interrupted = False diff --git a/aider/coders/editblock_func_coder.py b/aider/coders/editblock_func_coder.py index be32c48a0..75f95f95d 100644 --- a/aider/coders/editblock_func_coder.py +++ b/aider/coders/editblock_func_coder.py @@ -38,7 +38,7 @@ class EditBlockFunctionCoder(Coder): type="string", ), description=( - "Lines from the original file, including all" + "Some lines from the original file, including all" " whitespace, without skipping any lines" ), ), @@ -57,7 +57,29 @@ class EditBlockFunctionCoder(Coder): ), ] - def __init__(self, *args, **kwargs): + def __init__(self, code_format, *args, **kwargs): + self.code_format = code_format + + if code_format == "string": + original_lines = dict( + type="string", + description=( + "Some lines from the original file, including all" + " whitespace and newlines, without skipping any lines" + ), + ) + updated_lines = dict( + type="string", + description="New content to replace the `original_lines` with", + ) + + self.functions[0]["parameters"]["properties"]["edits"]["items"]["properties"][ + "original_lines" + ] = original_lines + self.functions[0]["parameters"]["properties"]["edits"]["items"]["properties"][ + "updated_lines" + ] = updated_lines + self.gpt_prompts = EditBlockFunctionPrompts() super().__init__(*args, **kwargs) @@ -96,8 +118,17 @@ class EditBlockFunctionCoder(Coder): edited = set() for edit in edits: path = get_arg(edit, "path") - original = "\n".join(get_arg(edit, "original_lines")) + "\n" - updated = "\n".join(get_arg(edit, "updated_lines")) + "\n" + original = get_arg(edit, "original_lines") + updated = get_arg(edit, "updated_lines") + + if self.code_format == "list": + original = "\n".join(original) + updated = "\n".join(updated) + + if original and not original.endswith("\n"): + original += "\n" + if updated and not updated.endswith("\n"): + updated += "\n" full_path = self.allowed_to_edit(path) if not full_path: diff --git a/aider/utils.py b/aider/utils.py index b7486cfc9..cd805e7ab 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -19,7 +19,7 @@ def quoted_file(fname, display_fname, fence=("```", "```"), number=False): return prompt -def show_messages(messages, title=None): +def show_messages(messages, title=None, functions=None): if title: print(title.upper(), "*" * 50) @@ -32,3 +32,6 @@ def show_messages(messages, title=None): content = msg.get("function_call") if content: print(role, content) + + if functions: + dump(functions)