make the examples part of the chat

This commit is contained in:
Paul Gauthier 2024-04-30 19:17:48 -07:00
parent d38a38f0dd
commit d51cada163
3 changed files with 42 additions and 76 deletions

View file

@ -526,6 +526,13 @@ class Coder:
messages = [ messages = [
dict(role="system", content=main_sys), dict(role="system", content=main_sys),
] ]
for msg in self.gpt_prompts.example_messages:
messages.append(
dict(
role=msg["role"],
content=self.fmt_system_prompt(msg["content"]),
)
)
self.summarize_end() self.summarize_end()
messages += self.done_messages messages += self.done_messages

View file

@ -16,49 +16,17 @@ Once you understand the request you MUST:
2. Think step-by-step and explain the needed changes with a numbered list of short sentences. 2. Think step-by-step and explain the needed changes with a numbered list of short sentences.
3. Describe each change with a *SEARCH/REPLACE block* per the examples below. All changes to files must use this *SEARCH/REPLACE block* format. ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*! 3. Describe each change with a *SEARCH/REPLACE block* per the examples below. All changes to files must use this *SEARCH/REPLACE block* format. ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*!
All changes to files must use the *SEARCH/REPLACE block* format.
"""
# Example conversation: example_messages = [
dict(
## USER: These are the *read-write* files: role="user",
content="Change get_factorial() to use math.factorial",
{fence[0]} ),
mathweb/flask/app.py dict(
from flask import Flask role="assistant",
content="""To make this change we need to modify `mathweb/flask/app.py` to:
app = Flask(__name__)
@app.route('/div/<int:n>/<int:d>')
def divide(n, d):
if d == 0:
return 'Error: Division by zero'
else:
result = n / d
return str(result)
def factorial(n):
"compute factorial"
if n == 0:
return 1
else:
return n * factorial(n-1)
@app.route('/factorial/<int:n>')
def get_factorial(n):
return str(factorial(n))
if __name__ == '__main__':
print("Starting...")
app.run()
{fence[1]}
## ASSISTANT: Ok.
## USER: Change get_factorial() to use math.factorial
## ASSISTANT:
Do make this change we need to modify `mathweb/flask/app.py` to:
1. Import the math package. 1. Import the math package.
2. Remove the existing factorial() function. 2. Remove the existing factorial() function.
@ -99,30 +67,15 @@ mathweb/flask/app.py
return str(math.factorial(n)) return str(math.factorial(n))
>>>>>>> REPLACE >>>>>>> REPLACE
{fence[1]} {fence[1]}
""",
),
# Example conversation: dict(
role="user",
## USER: These are the *read-write* files: content="Refactor hello() into its own file.",
),
{fence[0]} dict(
main.py role="assistant",
def hello(): content="""To make this change we need to modify `main.py` and make a new file `hello.py`:
"print a greeting"
print("hello")
if __name__ == '__main__':
hello()
{fence[1]}
## ASSISTANT: Ok.
## USER: Refactor hello() into its own file.
## ASSISTANT:
Do make this change we need to modify `main.py` and make a new file `hello.py`:
1. Make a new hello.py file with hello() in it. 1. Make a new hello.py file with hello() in it.
2. Remove hello() from main.py and replace it with an import. 2. Remove hello() from main.py and replace it with an import.
@ -151,9 +104,9 @@ def hello():
from hello import hello from hello import hello
>>>>>>> REPLACE >>>>>>> REPLACE
{fence[1]} {fence[1]}
""",
# Rules ),
""" ]
system_reminder = """Every *SEARCH/REPLACE block* must use this format: system_reminder = """Every *SEARCH/REPLACE block* must use this format:
1. The opening fence and code language, eg: {fence[0]} 1. The opening fence and code language, eg: {fence[0]}

View file

@ -14,13 +14,17 @@ Respect and use existing conventions, libraries, etc that are already present in
Take requests for changes to the supplied code. Take requests for changes to the supplied code.
If the request is ambiguous, ask questions. If the request is ambiguous, ask questions.
For each file that needs to be changed, write out the changes similar to a unified diff like `diff -U0` would produce. For example: For each file that needs to be changed, write out the changes similar to a unified diff like `diff -U0` would produce.
"""
# Example conversation 1 example_messages = [
dict(
## USER: Replace is_prime with a call to sympy. role="user",
content="Replace is_prime with a call to sympy.",
## ASSISTANT: Ok, I will: ),
dict(
role="assistant",
content="""Ok, I will:
1. Add an imports of sympy. 1. Add an imports of sympy.
2. Remove the is_prime() function. 2. Remove the is_prime() function.
@ -64,7 +68,9 @@ Here are the diffs for those changes:
+ count += 1 + count += 1
+ return str(num) + return str(num)
``` ```
""" """,
),
]
system_reminder = """# File editing rules: system_reminder = """# File editing rules: