Skip to content

Commit

Permalink
Merge pull request gpt-engineer-org#320 from AntonOsika/ao/fix-pip
Browse files Browse the repository at this point in the history
Dont require to be in the same folder as the repo to run, v0.0.5
  • Loading branch information
AntonOsika authored Jun 22, 2023
2 parents ffd3aca + 8062d90 commit a36e299
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 14 deletions.
5 changes: 4 additions & 1 deletion gpt_engineer/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def __init__(self, path):

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

Expand All @@ -35,6 +38,6 @@ def __setitem__(self, key, val):
class DBs:
memory: DB
logs: DB
identity: DB
preprompts: DB
input: DB
workspace: DB
3 changes: 1 addition & 2 deletions gpt_engineer/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import logging
import os
import shutil

from pathlib import Path
Expand Down Expand Up @@ -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]:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 16 additions & 10 deletions gpt_engineer/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
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
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):
Expand All @@ -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)
Expand Down Expand Up @@ -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"]

Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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) "
Expand All @@ -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)
Expand All @@ -204,7 +210,7 @@ def fix_code(ai: AI, dbs: DBs):
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.fsystem(dbs.preprompts["fix_code"]),
]
messages = ai.next(messages, "Please fix any errors in the code above.")
to_files(messages[-1]["content"], dbs.workspace)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a36e299

Please sign in to comment.