Skip to content

Commit

Permalink
Make gpt-engineer pip installable/runnable (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeadie authored Jun 16, 2023
1 parent 12cb93f commit 6f8e976
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GPT Engineer is made to be easy to adapt, extend, and make your agent learn how
**Run**:
- Create a new empty folder with a `main_prompt` file (or copy the example folder `cp -r example/ my-new-project`)
- Fill in the `main_prompt` in your new folder
- run `python main.py my-new-project`
- Run `python main.py my-new-project`

**Results**:
- Check the generated files in my-new-project/workspace
Expand Down
4 changes: 2 additions & 2 deletions ai.py → gpt_engineer/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def next(self, messages: list[dict[str, str]], prompt=None):

chat = []
for chunk in response:
delta = chunk['choices'][0]['delta']
msg = delta.get('content', '')
delta = chunk["choices"][0]["delta"]
msg = delta.get("content", "")
print(msg, end="")
chat.append(msg)
return messages + [{"role": "assistant", "content": "".join(chat)}]
2 changes: 1 addition & 1 deletion chat_to_files.py → gpt_engineer/chat_to_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parse_chat(chat): # -> List[Tuple[str, str]]:


def to_files(chat, workspace):
workspace['all_output.txt'] = chat
workspace["all_output.txt"] = chat

files = parse_chat(chat)
for file_name, file_content in files:
Expand Down
11 changes: 8 additions & 3 deletions db.py → gpt_engineer/db.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os

from dataclasses import dataclass
import os
from pathlib import Path


class DB:
"""A simple key-value store, where keys are filenames and values are file contents."""

def __init__(self, path):
self.path = Path(path).absolute()
os.makedirs(self.path, exist_ok=True)
Expand All @@ -17,10 +18,14 @@ def __setitem__(self, key, val):
with open(self.path / key, 'w', encoding='utf-8') as f:
f.write(val)

def __contains__(self, key):
return (self.path / key).exists()


# dataclass for all dbs:
@dataclass
class DBs:
"""A dataclass for all dbs"""

memory: DB
logs: DB
identity: DB
Expand Down
26 changes: 15 additions & 11 deletions main.py → gpt_engineer/main.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import os
import json
import pathlib

import typer

from ai import AI
from db import DB, DBs
from steps import STEPS
from gpt_engineer.chat_to_files import to_files
from gpt_engineer.ai import AI
from gpt_engineer.steps import STEPS
from gpt_engineer.db import DB, DBs


app = typer.Typer()


@app.command()
def chat(
project_path: str = typer.Argument(None, help="path"),
project_path: str = typer.Argument(str(pathlib.Path(os.path.curdir) / "example"), help="path"),
run_prefix: str = typer.Option(
"",
help="run prefix, if you want to run multiple variants of the same project and later compare them",
),
model: str = "gpt-4",
temperature: float = 0.1,
):
if project_path is None:
project_path = str(pathlib.Path(__file__).parent / "example")

app_dir = pathlib.Path(os.path.curdir)
input_path = project_path
memory_path = pathlib.Path(project_path) / (run_prefix + "memory")
workspace_path = pathlib.Path(project_path) / (run_prefix + "workspace")
Expand All @@ -34,16 +34,20 @@ def chat(

dbs = DBs(
memory=DB(memory_path),
logs=DB(pathlib.Path(memory_path) / "logs"),
logs=DB(memory_path / "logs"),
input=DB(input_path),
workspace=DB(workspace_path),
identity=DB(pathlib.Path(__file__).parent / "identity"),
identity=DB(app_dir / "identity"),
)

for step in STEPS:
messages = step(ai, dbs)
dbs.logs[step.__name__] = json.dumps(messages)


if __name__ == "__main__":
def execute():
app()


if __name__ == "__main__":
execute()
8 changes: 4 additions & 4 deletions steps.py → gpt_engineer/steps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json

from ai import AI
from chat_to_files import to_files
from db import DBs
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):
Expand Down Expand Up @@ -68,4 +68,4 @@ def run_clarified(ai: AI, dbs: DBs):
# improve_files,
# add_tests
# run_tests_and_fix_files,
# improve_based_on_in_file_feedback_comments
# improve_based_on_in_file_feedback_comments
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
[build-system]
requires = ["setuptools", "wheel"]

[project]
name = "gpt-engineer"
version = "0.0.1"
description = "Specify what you want it to build, the AI asks for clarification, and then builds it."
readme = "README.md"
requires-python = ">=3"
dependencies = [
'black == 23.3.0',
'openai == 0.27.8',
'ruff == 0.0.272',
'typer == 0.9.0'
]

[project.scripts]
gpt-engineer = 'gpt_engineer.main:execute'

[tool.setuptools]
packages = ["gpt_engineer"]

# https://beta.ruff.rs/docs/configuration/#using-rufftoml
[tool.ruff]
select = ["F", "E", "W", "I001"]
Expand All @@ -23,6 +45,11 @@ exclude = [
"venv",
]

[project.urls]
"Homepage" = "https://github.com/AntonOsika/gpt-engineer"
"Bug Tracker" = "https://github.com/AntonOsika/gpt-engineer/issues"


[tool.ruff.isort]
known-first-party = []
known-third-party = []
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black==23.3.0
openai==0.27.8
ruff==0.0.272
typer==0.9.0
typer==0.9.0

0 comments on commit 6f8e976

Please sign in to comment.