This commit is contained in:
Paul Gauthier 2023-06-21 13:57:42 -07:00
parent 3465bd57d1
commit 2fce31209c
2 changed files with 87 additions and 9 deletions

View file

@ -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:
@ -481,11 +546,18 @@ class Coder:
if chunk.choices[0].finish_reason not in (None, "stop"):
assert False, "Exceeded context window!"
try:
func = chunk.choices[0].delta.function_call
dump(func)
except AttributeError:
pass
try:
text = chunk.choices[0].delta.content
if text:
self.resp += text
except AttributeError:
continue
pass
if silent:
continue

View file

@ -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"
)