Skip to content

Commit

Permalink
Merge pull request #100 from AntonOsika/follgad/unit_tests
Browse files Browse the repository at this point in the history
Add steps for unit_tests and specification
  • Loading branch information
AntonOsika authored Jun 17, 2023
2 parents d12b32f + e2e0942 commit 8409c25
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
37 changes: 34 additions & 3 deletions gpt_engineer/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,43 @@ def clarify(ai: AI, dbs: DBs):
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.fuser(f"Instructions: {dbs.input['main_prompt']}"), ai.fuser(f"Specification:\n\n{dbs.memory['specification']}")]

messages = ai.next(messages, dbs.identity['unit_tests'])

dbs.memory['unit_tests'] = messages[-1]['content']
to_files(dbs.memory['unit_tests'], dbs.workspace)

return messages


def run_clarified(ai: AI, dbs: DBs):
# get the messages from previous step
messages = json.loads(dbs.logs[clarify.__name__])

messages = [
ai.fsystem(setup_sys_prompt(dbs)),
] + messages[1:]
ai.fuser(f"Instructions: {dbs.input['main_prompt']}"),
ai.fuser(f"Specification:\n\n{dbs.memory['specification']}"),
ai.fuser(f"Unit tests:\n\n{dbs.memory['unit_tests']}"),
]
messages = ai.next(messages, dbs.identity['use_qa'])
to_files(messages[-1]['content'], dbs.workspace)
return messages
Expand All @@ -65,11 +95,12 @@ def run_clarified(ai: AI, dbs: DBs):
# Different configs of what steps to run
STEPS = {
'default': [run],
'unit_tests': [gen_spec, pre_unit_tests, run_clarified],
'clarify': [clarify, run_clarified],
}

# Future steps that can be added:
# improve_files,
# add_tests
# run_tests_and_fix_files,
# improve_based_on_in_file_feedback_comments
# improve_based_on_in_file_feedback_comments
8 changes: 8 additions & 0 deletions identity/respec
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
You are a pragmatic principal engineer at Google. 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 changes: 8 additions & 0 deletions identity/spec
Original file line number Diff line number Diff line change
@@ -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 changes: 3 additions & 0 deletions identity/unit_tests
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions identity/use_qa
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.)
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.

File syntax:

```file.py/ts/html
```filename.py/ts/html
[ADD YOUR CODE HERE]
```

0 comments on commit 8409c25

Please sign in to comment.