add unit_tests and spec/respec

This commit is contained in:
Emil Ahlbäck
2023-06-17 13:37:45 +02:00
parent 03d8fff5d2
commit fa1df72bf3
5 changed files with 54 additions and 5 deletions

View File

@@ -50,13 +50,42 @@ def clarify(ai: AI, dbs: DBs):
return messages return messages
def gen_spec(ai: AI, dbs: DBs):
'''
Generate a spec from the main prompt + clarifications and save the results to the workspace
'''
messages = [ai.fsystem(setup_sys_prompt(dbs)), ai.fsystem(f"Main prompt: {dbs.input['main_prompt']}")]
messages = ai.next(messages, dbs.identity['spec'])
messages = ai.next(messages, dbs.identity['respec'])
messages = ai.next(messages, dbs.identity['spec'])
dbs.memory['specification'] = messages[-1]['content']
return messages
def pre_unit_tests(ai: AI, dbs: DBs):
'''
Generate unit tests based on the specification, that should work.
'''
messages = [ai.fsystem(setup_sys_prompt(dbs)), ai.fsystem(f"Main prompt: {dbs.input['main_prompt']}"), ai.fsystem(f"Specification:\n\n{dbs.memory['specification']}")]
messages = ai.next(messages, dbs.identity['unit_tests'])
dbs.memory['unit_tests'] = messages[-1]['content']
return messages
def run_clarified(ai: AI, dbs: DBs): def run_clarified(ai: AI, dbs: DBs):
# get the messages from previous step # get the messages from previous step
messages = json.loads(dbs.logs[clarify.__name__])
messages = [ messages = [
ai.fsystem(setup_sys_prompt(dbs)), ai.fsystem(setup_sys_prompt(dbs)),
] + messages[1:] ai.fsystem(f"Main prompt: {dbs.input['main_prompt']}"),
ai.fsystem(f"Specification:\n\n{dbs.memory['specification']}"),
ai.fsystem(f"Unit tests:\n\n{dbs.memory['unit_tests']}"),
]
messages = ai.next(messages, dbs.identity['use_qa']) messages = ai.next(messages, dbs.identity['use_qa'])
to_files(messages[-1]['content'], dbs.workspace) to_files(messages[-1]['content'], dbs.workspace)
return messages return messages
@@ -65,6 +94,7 @@ def run_clarified(ai: AI, dbs: DBs):
# Different configs of what steps to run # Different configs of what steps to run
STEPS = { STEPS = {
'default': [run], 'default': [run],
'unit_tests': [gen_spec, pre_unit_tests, run_clarified],
'clarify': [clarify, run_clarified], 'clarify': [clarify, run_clarified],
} }

8
identity/respec Normal file
View File

@@ -0,0 +1,8 @@
You are a GPT-Engineer, an AI developed to write programs. You have been asked to review a specification for a new feature.
You have been asked to give feedback on the following:
- Is there anything that might not work the way the user expects?
- Is there anything missing for the program to fully work?
- Is there anything that can be simplified without decreasing quality?
You are asked to make educated assumptions for each unclear item. For each of these, communicate which assumptions you'll make when implementing the feature.

8
identity/spec Normal file
View File

@@ -0,0 +1,8 @@
You are a GPT-Engineer, an AI developed to write programs. You have been asked to make a specification for a program.
Please generate a specification based on the given input. First, be super explicit about what the program should do, which features it should have and give details about anything that might be unclear. **Don't leave anything unclear or undefined.**
Second, lay out the names of the core classes, functions, methods that will be necessary, As well as a quick comment on their purpose.
Then write out which non-standard dependencies you'll have to use.
This specification will be used later as the basis for your implementation.

3
identity/unit_tests Normal file
View File

@@ -0,0 +1,3 @@
You are a GPT-Engineer, an AI developed to use Test Driven Development to write tests according to a specification.
Please generate tests based on the above specification. The tests should be as simple as possible, but still cover all the functionality.

View File

@@ -3,11 +3,11 @@ Please now remember the steps:
First lay out the names of the core classes, functions, methods that will be necessary, As well as a quick comment on their purpose. First lay out the names of the core classes, functions, methods that will be necessary, As well as a quick comment on their purpose.
Then output the content of each file, with syntax below. Then output the content of each file, with syntax below.
(You will start with the "entrypoint" file, then go to the ones that are imported by that file, and so on.) (You will start with the "entrypoint" file, then go to the ones that are imported by that file, and so on.)
Make sure that files contain all imports, types etc. The code should be fully functional. Make sure that code in different files are compatible with each other. Make sure that files contain all imports, types, variables etc. The code should be fully functional. If anything is unclear, just make assumptions. Make sure that code in different files are compatible with each other.
Before you finish, double check that all parts of the architecture is present in the files. Before you finish, double check that all parts of the architecture is present in the files.
File syntax: File syntax:
```file.py/ts/html ```filename.py/ts/html
[ADD YOUR CODE HERE] [ADD YOUR CODE HERE]
``` ```