From ed1a7da296a55d2fdca5ec7cb795a2eee95f0136 Mon Sep 17 00:00:00 2001 From: Anton Osika Date: Thu, 22 Jun 2023 10:42:35 +0200 Subject: [PATCH 1/2] Dont require to be in the same folder as the repo to run, v0.0.5 --- gpt_engineer/db.py | 5 +++- gpt_engineer/main.py | 3 +- .../preprompts}/fix_code | 0 .../preprompts}/generate | 0 .../preprompts}/philosophy | 0 {identity => gpt_engineer/preprompts}/qa | 0 {identity => gpt_engineer/preprompts}/respec | 0 {identity => gpt_engineer/preprompts}/spec | 0 .../preprompts}/unit_tests | 0 .../preprompts}/use_feedback | 0 {identity => gpt_engineer/preprompts}/use_qa | 0 gpt_engineer/steps.py | 30 +++++++++++-------- pyproject.toml | 2 +- 13 files changed, 24 insertions(+), 16 deletions(-) rename {identity => gpt_engineer/preprompts}/fix_code (100%) rename {identity => gpt_engineer/preprompts}/generate (100%) rename {identity => gpt_engineer/preprompts}/philosophy (100%) rename {identity => gpt_engineer/preprompts}/qa (100%) rename {identity => gpt_engineer/preprompts}/respec (100%) rename {identity => gpt_engineer/preprompts}/spec (100%) rename {identity => gpt_engineer/preprompts}/unit_tests (100%) rename {identity => gpt_engineer/preprompts}/use_feedback (100%) rename {identity => gpt_engineer/preprompts}/use_qa (100%) diff --git a/gpt_engineer/db.py b/gpt_engineer/db.py index 13eef83..6bfee18 100644 --- a/gpt_engineer/db.py +++ b/gpt_engineer/db.py @@ -11,6 +11,9 @@ class DB: self.path.mkdir(parents=True, exist_ok=True) + def __contains__(self, key): + return (self.path / key).is_file() + def __getitem__(self, key): full_path = self.path / key @@ -35,6 +38,6 @@ class DB: class DBs: memory: DB logs: DB - identity: DB + preprompts: DB input: DB workspace: DB diff --git a/gpt_engineer/main.py b/gpt_engineer/main.py index cface53..1faa229 100644 --- a/gpt_engineer/main.py +++ b/gpt_engineer/main.py @@ -1,6 +1,5 @@ import json import logging -import os import shutil from pathlib import Path @@ -54,7 +53,7 @@ def main( logs=DB(memory_path / "logs"), input=DB(input_path), workspace=DB(workspace_path), - identity=DB(Path(os.path.curdir) / "identity"), + preprompts=DB(Path(__file__).parent / "preprompts"), ) for step in STEPS[steps_config]: diff --git a/identity/fix_code b/gpt_engineer/preprompts/fix_code similarity index 100% rename from identity/fix_code rename to gpt_engineer/preprompts/fix_code diff --git a/identity/generate b/gpt_engineer/preprompts/generate similarity index 100% rename from identity/generate rename to gpt_engineer/preprompts/generate diff --git a/identity/philosophy b/gpt_engineer/preprompts/philosophy similarity index 100% rename from identity/philosophy rename to gpt_engineer/preprompts/philosophy diff --git a/identity/qa b/gpt_engineer/preprompts/qa similarity index 100% rename from identity/qa rename to gpt_engineer/preprompts/qa diff --git a/identity/respec b/gpt_engineer/preprompts/respec similarity index 100% rename from identity/respec rename to gpt_engineer/preprompts/respec diff --git a/identity/spec b/gpt_engineer/preprompts/spec similarity index 100% rename from identity/spec rename to gpt_engineer/preprompts/spec diff --git a/identity/unit_tests b/gpt_engineer/preprompts/unit_tests similarity index 100% rename from identity/unit_tests rename to gpt_engineer/preprompts/unit_tests diff --git a/identity/use_feedback b/gpt_engineer/preprompts/use_feedback similarity index 100% rename from identity/use_feedback rename to gpt_engineer/preprompts/use_feedback diff --git a/identity/use_qa b/gpt_engineer/preprompts/use_qa similarity index 100% rename from identity/use_qa rename to gpt_engineer/preprompts/use_qa diff --git a/gpt_engineer/steps.py b/gpt_engineer/steps.py index 97b890e..d781bfd 100644 --- a/gpt_engineer/steps.py +++ b/gpt_engineer/steps.py @@ -3,6 +3,7 @@ import re import subprocess from enum import Enum +from typing import Callable, TypeVar from gpt_engineer.ai import AI from gpt_engineer.chat_to_files import to_files @@ -10,7 +11,12 @@ from gpt_engineer.db import DBs def setup_sys_prompt(dbs): - return dbs.identity["generate"] + "\nUseful to know:\n" + dbs.identity["philosophy"] + return ( + dbs.preprompts["generate"] + "\nUseful to know:\n" + dbs.preprompts["philosophy"] + ) + + +Step = TypeVar("Step", bound=Callable[[AI, DBs], list[dict]]) def simple_gen(ai: AI, dbs: DBs): @@ -27,7 +33,7 @@ def clarify(ai: AI, dbs: DBs): """ Ask the user if they want to clarify anything and save the results to the workspace """ - messages = [ai.fsystem(dbs.identity["qa"])] + messages = [ai.fsystem(dbs.preprompts["qa"])] user = dbs.input["main_prompt"] while True: messages = ai.next(messages, user) @@ -64,7 +70,7 @@ def gen_spec(ai: AI, dbs: DBs): ai.fsystem(f"Instructions: {dbs.input['main_prompt']}"), ] - messages = ai.next(messages, dbs.identity["spec"]) + messages = ai.next(messages, dbs.preprompts["spec"]) dbs.memory["specification"] = messages[-1]["content"] @@ -73,7 +79,7 @@ def gen_spec(ai: AI, dbs: DBs): def respec(ai: AI, dbs: DBs): messages = json.loads(dbs.logs[gen_spec.__name__]) - messages += [ai.fsystem(dbs.identity["respec"])] + messages += [ai.fsystem(dbs.preprompts["respec"])] messages = ai.next(messages) messages = ai.next( @@ -102,7 +108,7 @@ def gen_unit_tests(ai: AI, dbs: DBs): ai.fuser(f"Specification:\n\n{dbs.memory['specification']}"), ] - messages = ai.next(messages, dbs.identity["unit_tests"]) + messages = ai.next(messages, dbs.preprompts["unit_tests"]) dbs.memory["unit_tests"] = messages[-1]["content"] to_files(dbs.memory["unit_tests"], dbs.workspace) @@ -118,7 +124,7 @@ def gen_clarified_code(ai: AI, dbs: DBs): messages = [ ai.fsystem(setup_sys_prompt(dbs)), ] + messages[1:] - messages = ai.next(messages, dbs.identity["use_qa"]) + messages = ai.next(messages, dbs.preprompts["use_qa"]) to_files(messages[-1]["content"], dbs.workspace) return messages @@ -133,7 +139,7 @@ def gen_code(ai: AI, dbs: DBs): 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"]) + messages = ai.next(messages, dbs.preprompts["use_qa"]) to_files(messages[-1]["content"], dbs.workspace) return messages @@ -170,7 +176,7 @@ def gen_entrypoint(ai, dbs): "From this you will answer with code blocks that includes all the necessary " "unix terminal commands to " "a) install dependencies " - "b) run all necessary parts of the codebase (in parallel if necessary).\n" + "b) run all necessary parts of the codebase (in parallell if necessary).\n" "Do not install globally. Do not use sudo.\n" "Do not explain the code, just give the commands.\n" "Do not use placeholders, use example values (like . for a folder argument) " @@ -191,7 +197,7 @@ def use_feedback(ai: AI, dbs: DBs): ai.fsystem(setup_sys_prompt(dbs)), ai.fuser(f"Instructions: {dbs.input['main_prompt']}"), ai.fassistant(dbs.workspace["all_output.txt"]), - ai.fsystem(dbs.identity["use_feedback"]), + ai.fsystem(dbs.preprompts["use_feedback"]), ] messages = ai.next(messages, dbs.input["feedback"]) to_files(messages[-1]["content"], dbs.workspace) @@ -199,12 +205,12 @@ def use_feedback(ai: AI, dbs: DBs): def fix_code(ai: AI, dbs: DBs): - code_output = json.loads(dbs.logs[gen_code.__name__])[-1]["content"] + code_ouput = json.loads(dbs.logs[gen_code.__name__])[-1]["content"] messages = [ ai.fsystem(setup_sys_prompt(dbs)), ai.fuser(f"Instructions: {dbs.input['main_prompt']}"), - ai.fuser(code_output), - ai.fsystem(dbs.identity["fix_code"]), + ai.fuser(code_ouput), + ai.fsystem(dbs.preprompts["fix_code"]), ] messages = ai.next(messages, "Please fix any errors in the code above.") to_files(messages[-1]["content"], dbs.workspace) diff --git a/pyproject.toml b/pyproject.toml index c1ca348..241ea09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools", "wheel"] [project] name = "gpt-engineer" -version = "0.0.4" +version = "0.0.5" description = "Specify what you want it to build, the AI asks for clarification, and then builds it." readme = "README.md" requires-python = ">=3" From 8062d901d145d5d192728a96672fb196f5af0625 Mon Sep 17 00:00:00 2001 From: Anton Osika Date: Thu, 22 Jun 2023 10:44:34 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- gpt_engineer/steps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gpt_engineer/steps.py b/gpt_engineer/steps.py index d781bfd..b8611e6 100644 --- a/gpt_engineer/steps.py +++ b/gpt_engineer/steps.py @@ -205,11 +205,11 @@ def use_feedback(ai: AI, dbs: DBs): def fix_code(ai: AI, dbs: DBs): - code_ouput = json.loads(dbs.logs[gen_code.__name__])[-1]["content"] + code_output = json.loads(dbs.logs[gen_code.__name__])[-1]["content"] messages = [ ai.fsystem(setup_sys_prompt(dbs)), ai.fuser(f"Instructions: {dbs.input['main_prompt']}"), - ai.fuser(code_ouput), + ai.fuser(code_output), ai.fsystem(dbs.preprompts["fix_code"]), ] messages = ai.next(messages, "Please fix any errors in the code above.")