diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 61a1953bb..48bd2ddd3 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -444,70 +444,18 @@ class Coder: on_backoff=lambda details: print(f"Retry in {details['wait']} seconds."), ) def send_with_retries(self, model, messages): - _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( + kwargs = dict( model=model, messages=messages, temperature=0, - stream=False, - functions=functions, + stream=True, ) + if self.functions: + kwargs["functions"] = self.functions + + res = openai.ChatCompletion.create(**kwargs) + return res + dump(res) msg = res.choices[0].message dump(msg) @@ -543,12 +491,13 @@ class Coder: live.start() for chunk in completion: - if chunk.choices[0].finish_reason not in (None, "stop"): + dump(chunk) + if chunk.choices[0].finish_reason not in (None, "stop", "function_call"): assert False, "Exceeded context window!" try: func = chunk.choices[0].delta.function_call - dump(func) + print(func) except AttributeError: pass diff --git a/aider/coders/func_coder.py b/aider/coders/func_coder.py index 732f961ef..72bc914b5 100644 --- a/aider/coders/func_coder.py +++ b/aider/coders/func_coder.py @@ -8,6 +8,33 @@ from .func_prompts import FunctionPrompts class FunctionCoder(Coder): + 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", + ), + ), + ), + ), + ] + def __init__(self, *args, **kwargs): self.gpt_prompts = FunctionPrompts() super().__init__(*args, **kwargs)