diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index f26cc4f0d..61a1953bb 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -444,12 +444,77 @@ class Coder: on_backoff=lambda details: print(f"Retry in {details['wait']} seconds."), ) def send_with_retries(self, model, messages): - return openai.ChatCompletion.create( + _functions = [ + dict( + name="replace_lines", + description="replace a block of contiguous lines with a new set of lines", + parameters=dict( + type="object", + required=["file_path", "original_lines", "updated_lines"], + properties=dict( + file_path=dict( + type="string", + description="path of file to edit", + ), + original_lines=dict( + type="string", + description=( + "block of contiguous lines from the file (including newlines)" + ), + ), + updated_lines=dict( + type="string", + description=( + "block of contiguous lines from the file (including newlines)" + ), + ), + ), + ), + ), + ] + functions = [ + dict( + name="write_file", + description="create or update a file", + parameters=dict( + type="object", + required=["explanation", "file_path", "file_content"], + properties=dict( + explanation=dict( + type="string", + description=( + "Explanation of the changes to be made to the code (markdown" + " format)" + ), + ), + file_path=dict( + type="string", + description="Path of file to write", + ), + file_content=dict( + type="string", + description="Content to write to the file", + ), + ), + ), + ), + ] + dump(functions) + + res = openai.ChatCompletion.create( model=model, messages=messages, temperature=0, - stream=True, + stream=False, + functions=functions, ) + dump(res) + msg = res.choices[0].message + dump(msg) + print(msg.content) + print(msg.function_call.arguments) + sys.exit() + return res def send(self, messages, model=None, silent=False): if not model: @@ -482,10 +547,17 @@ class Coder: assert False, "Exceeded context window!" try: - text = chunk.choices[0].delta.content - self.resp += text + func = chunk.choices[0].delta.function_call + dump(func) except AttributeError: - continue + pass + + try: + text = chunk.choices[0].delta.content + if text: + self.resp += text + except AttributeError: + pass if silent: continue diff --git a/aider/coders/func_prompts.py b/aider/coders/func_prompts.py index c4a37ff68..0e3ea62bc 100644 --- a/aider/coders/func_prompts.py +++ b/aider/coders/func_prompts.py @@ -8,14 +8,20 @@ class FunctionPrompts(EditorPrompts): Take requests for changes to the supplied code. If the request is ambiguous, ask questions. -Once you understand the request you MUST: -1. Explain any needed changes. -2. Call functions to edit the code to make the needed changes. +Once you understand the request you MUST use the `write_file` function to edit the files to make the needed changes. """ - system_reminder = "" + system_reminder = """ +ONLY return code using the `write_file` function. +NEVER return code outside the `write_file` function. +""" files_content_prefix = "Here is the current content of the files:\n" files_no_full_files = "I am not sharing any files yet." redacted_edit_message = "No changes are needed." + + repo_content_prefix = ( + "Below here are summaries of other files! Do not propose changes to these *read-only*" + " files without asking me first.\n" + )