Merge branch 'main' of github.com:AntonOsika/gpt-engineer

* 'main' of github.com:AntonOsika/gpt-engineer:
  Mark test as failed because it requires OpenAI API access currently
  `black`
  Create test_ai.py
  fix to_files
  execute_workspace -> gen_entrypoint; execute_entrypoint
  Ignore my-new-project/
  Added CODE_OF_CONDUCT.md to the .github directory (#147)
  make pre commit pass in the whole codebase (#149)
  Create ci.yaml
  Fix linting
  Add support for directory paths in filenames and improve code splitting - Enforce an explicit markdown code block format - Add a token to split the output to clearly detect when the code blocks start - Save all non-code output to a `README.md` file - Update RegEx to extract and strip text more reliably and clean up the output - Update the identify prompts appropriately
  Enhance philosophy to include supporting documents - Create instructions for running/compiling the project - Create any package manager files
  Generate instructions for all platforms - Update prompt to create instructions for all 3 major OS platforms - Fix small typo
  Add support for directory creation and binary files - Use the `Path` module instead of `os` - Add ability to create any amount of missing directories for a given file - Add ability to save both text and binary files to save images (or other file types) later
  Add cleanup & move `projects` to their own directory - Add optional argument to clean and delete the working directories of the project before running the prompt - Add `.gitignore` entry to ignore all possible projects - Update readme
This commit is contained in:
Anton Osika
2023-06-18 15:13:34 +02:00
17 changed files with 355 additions and 117 deletions

View File

@@ -2,9 +2,8 @@ import json
import subprocess
from gpt_engineer.ai import AI
from gpt_engineer.chat_to_files import to_files
from gpt_engineer.chat_to_files import parse_chat, to_files
from gpt_engineer.db import DBs
from gpt_engineer.chat_to_files import parse_chat
def setup_sys_prompt(dbs):
@@ -54,7 +53,8 @@ def clarify(ai: AI, dbs: DBs):
def gen_spec(ai: AI, dbs: DBs):
"""
Generate a spec from the main prompt + clarifications and save the results to the workspace
Generate a spec from the main prompt + clarifications and save the results to
the workspace
"""
messages = [
ai.fsystem(setup_sys_prompt(dbs)),
@@ -67,6 +67,7 @@ def gen_spec(ai: AI, dbs: DBs):
return messages
def respec(ai: AI, dbs: DBs):
messages = dbs.logs[gen_spec.__name__]
messages += [ai.fsystem(dbs.identity["respec"])]
@@ -75,10 +76,13 @@ def respec(ai: AI, dbs: DBs):
messages = ai.next(
messages,
(
'Based on the conversation so far, please reiterate the specification for the program. '
'If there are things that can be improved, please incorporate the improvements. '
"If you are satisfied with the specification, just write out the specification word by word again."
)
"Based on the conversation so far, please reiterate the specification for "
"the program. "
"If there are things that can be improved, please incorporate the "
"improvements. "
"If you are satisfied with the specification, just write out the "
"specification word by word again."
),
)
dbs.memory["specification"] = messages[-1]["content"]
@@ -116,6 +120,7 @@ def gen_clarified_code(ai: AI, dbs: DBs):
to_files(messages[-1]["content"], dbs.workspace)
return messages
def gen_code(ai: AI, dbs: DBs):
# get the messages from previous step
@@ -130,12 +135,6 @@ def gen_code(ai: AI, dbs: DBs):
return messages
def execute_workspace(ai: AI, dbs: DBs):
messages = gen_entrypoint(ai, dbs)
execute_entrypoint(ai, dbs)
return messages
def execute_entrypoint(ai, dbs):
command = dbs.workspace["run.sh"]
@@ -157,8 +156,10 @@ def execute_entrypoint(ai, dbs):
def gen_entrypoint(ai, dbs):
messages = ai.start(
system=(
f"You will get information about a codebase that is currently on disk in the current folder.\n"
"From this you will answer with one code block that includes all the necessary macos terminal commands to "
"You will get information about a codebase that is currently on disk in "
f"the folder {dbs.workspace.path}.\n"
"From this you will answer with code blocks that includes all the necessary "
"Windows, MacOS, and Linux terminal commands to "
"a) install dependencies "
"b) run all necessary parts of the codebase (in parallell if necessary).\n"
"Do not install globally. Do not use sudo.\n"
@@ -170,11 +171,16 @@ def gen_entrypoint(ai, dbs):
blocks = parse_chat(messages[-1]["content"])
for lang, _ in blocks:
assert lang in ["", "bash", "sh"], "Generated entrypoint command that was not bash"
assert lang in [
"",
"bash",
"sh",
], "Generated entrypoint command that was not bash"
dbs.workspace["run.sh"] = "\n".join(block for lang, block in blocks)
return messages
def use_feedback(ai: AI, dbs: DBs):
messages = [
ai.fsystem(setup_sys_prompt(dbs)),
@@ -182,18 +188,25 @@ def use_feedback(ai: AI, dbs: DBs):
ai.fassistant(dbs.workspace["all_output.txt"]),
ai.fsystem(dbs.identity["use_feedback"]),
]
messages = ai.next(messages, dbs.memory['feedback'])
messages = ai.next(messages, dbs.memory["feedback"])
to_files(messages[-1]["content"], dbs.workspace)
return messages
# Different configs of what steps to run
STEPS = {
"default": [gen_spec, gen_unit_tests, gen_code, execute_workspace],
"default": [gen_spec, gen_unit_tests, gen_code, gen_entrypoint, execute_entrypoint],
"benchmark": [gen_spec, gen_unit_tests, gen_code, gen_entrypoint],
"simple": [simple_gen, execute_workspace],
"clarify": [clarify, gen_clarified_code, execute_workspace],
"respec": [gen_spec, respec, gen_unit_tests, gen_code, execute_workspace],
"simple": [simple_gen, gen_entrypoint, execute_entrypoint],
"clarify": [clarify, gen_clarified_code, gen_entrypoint, execute_entrypoint],
"respec": [
gen_spec,
respec,
gen_unit_tests,
gen_code,
gen_entrypoint,
execute_entrypoint,
],
"execute_only": [execute_entrypoint],
"use_feedback": [use_feedback],
}