diff --git a/README.md b/README.md index d73e55f..b23b365 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/ai.py b/gpt_engineer/ai.py similarity index 93% rename from ai.py rename to gpt_engineer/ai.py index 4f8e963..10351a6 100644 --- a/ai.py +++ b/gpt_engineer/ai.py @@ -37,8 +37,8 @@ class AI: 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)}] diff --git a/chat_to_files.py b/gpt_engineer/chat_to_files.py similarity index 93% rename from chat_to_files.py rename to gpt_engineer/chat_to_files.py index 7a247a6..890ba33 100644 --- a/chat_to_files.py +++ b/gpt_engineer/chat_to_files.py @@ -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: diff --git a/db.py b/gpt_engineer/db.py similarity index 73% rename from db.py rename to gpt_engineer/db.py index 5b5f68f..aa35494 100644 --- a/db.py +++ b/gpt_engineer/db.py @@ -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) @@ -17,10 +18,14 @@ class DB: 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 diff --git a/main.py b/gpt_engineer/main.py similarity index 66% rename from main.py rename to gpt_engineer/main.py index ffd246f..2ca6551 100644 --- a/main.py +++ b/gpt_engineer/main.py @@ -1,18 +1,20 @@ +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", @@ -20,9 +22,7 @@ def chat( 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") @@ -34,10 +34,10 @@ 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: @@ -45,5 +45,9 @@ def chat( dbs.logs[step.__name__] = json.dumps(messages) -if __name__ == "__main__": +def execute(): app() + + +if __name__ == "__main__": + execute() \ No newline at end of file diff --git a/steps.py b/gpt_engineer/steps.py similarity index 91% rename from steps.py rename to gpt_engineer/steps.py index 08c73f6..bfa1bb1 100644 --- a/steps.py +++ b/gpt_engineer/steps.py @@ -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): @@ -68,4 +68,4 @@ STEPS = [clarify, run_clarified] # improve_files, # add_tests # run_tests_and_fix_files, -# improve_based_on_in_file_feedback_comments +# improve_based_on_in_file_feedback_comments \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index be74db4..405b5b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] @@ -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 = [] diff --git a/requirements.txt b/requirements.txt index cffa528..90d441b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ black==23.3.0 openai==0.27.8 ruff==0.0.272 -typer==0.9.0 +typer==0.9.0 \ No newline at end of file