mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-17 12:45:26 +01:00
Make gpt-engineer pip installable/runnable (#60)
This commit is contained in:
@@ -24,7 +24,7 @@ GPT Engineer is made to be easy to adapt, extend, and make your agent learn how
|
|||||||
**Run**:
|
**Run**:
|
||||||
- Create a new empty folder with a `main_prompt` file (or copy the example folder `cp -r example/ my-new-project`)
|
- 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
|
- Fill in the `main_prompt` in your new folder
|
||||||
- run `python main.py my-new-project`
|
- Run `python main.py my-new-project`
|
||||||
|
|
||||||
**Results**:
|
**Results**:
|
||||||
- Check the generated files in my-new-project/workspace
|
- Check the generated files in my-new-project/workspace
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ class AI:
|
|||||||
|
|
||||||
chat = []
|
chat = []
|
||||||
for chunk in response:
|
for chunk in response:
|
||||||
delta = chunk['choices'][0]['delta']
|
delta = chunk["choices"][0]["delta"]
|
||||||
msg = delta.get('content', '')
|
msg = delta.get("content", "")
|
||||||
print(msg, end="")
|
print(msg, end="")
|
||||||
chat.append(msg)
|
chat.append(msg)
|
||||||
return messages + [{"role": "assistant", "content": "".join(chat)}]
|
return messages + [{"role": "assistant", "content": "".join(chat)}]
|
||||||
@@ -20,7 +20,7 @@ def parse_chat(chat): # -> List[Tuple[str, str]]:
|
|||||||
|
|
||||||
|
|
||||||
def to_files(chat, workspace):
|
def to_files(chat, workspace):
|
||||||
workspace['all_output.txt'] = chat
|
workspace["all_output.txt"] = chat
|
||||||
|
|
||||||
files = parse_chat(chat)
|
files = parse_chat(chat)
|
||||||
for file_name, file_content in files:
|
for file_name, file_content in files:
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class DB:
|
class DB:
|
||||||
|
"""A simple key-value store, where keys are filenames and values are file contents."""
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = Path(path).absolute()
|
self.path = Path(path).absolute()
|
||||||
os.makedirs(self.path, exist_ok=True)
|
os.makedirs(self.path, exist_ok=True)
|
||||||
@@ -17,10 +18,14 @@ class DB:
|
|||||||
with open(self.path / key, 'w', encoding='utf-8') as f:
|
with open(self.path / key, 'w', encoding='utf-8') as f:
|
||||||
f.write(val)
|
f.write(val)
|
||||||
|
|
||||||
|
def __contains__(self, key):
|
||||||
|
return (self.path / key).exists()
|
||||||
|
|
||||||
|
|
||||||
# dataclass for all dbs:
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DBs:
|
class DBs:
|
||||||
|
"""A dataclass for all dbs"""
|
||||||
|
|
||||||
memory: DB
|
memory: DB
|
||||||
logs: DB
|
logs: DB
|
||||||
identity: DB
|
identity: DB
|
||||||
@@ -1,18 +1,20 @@
|
|||||||
|
import os
|
||||||
import json
|
import json
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
from ai import AI
|
from gpt_engineer.chat_to_files import to_files
|
||||||
from db import DB, DBs
|
from gpt_engineer.ai import AI
|
||||||
from steps import STEPS
|
from gpt_engineer.steps import STEPS
|
||||||
|
from gpt_engineer.db import DB, DBs
|
||||||
|
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
|
||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def chat(
|
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(
|
run_prefix: str = typer.Option(
|
||||||
"",
|
"",
|
||||||
help="run prefix, if you want to run multiple variants of the same project and later compare them",
|
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",
|
model: str = "gpt-4",
|
||||||
temperature: float = 0.1,
|
temperature: float = 0.1,
|
||||||
):
|
):
|
||||||
if project_path is None:
|
app_dir = pathlib.Path(os.path.curdir)
|
||||||
project_path = str(pathlib.Path(__file__).parent / "example")
|
|
||||||
|
|
||||||
input_path = project_path
|
input_path = project_path
|
||||||
memory_path = pathlib.Path(project_path) / (run_prefix + "memory")
|
memory_path = pathlib.Path(project_path) / (run_prefix + "memory")
|
||||||
workspace_path = pathlib.Path(project_path) / (run_prefix + "workspace")
|
workspace_path = pathlib.Path(project_path) / (run_prefix + "workspace")
|
||||||
@@ -34,10 +34,10 @@ def chat(
|
|||||||
|
|
||||||
dbs = DBs(
|
dbs = DBs(
|
||||||
memory=DB(memory_path),
|
memory=DB(memory_path),
|
||||||
logs=DB(pathlib.Path(memory_path) / "logs"),
|
logs=DB(memory_path / "logs"),
|
||||||
input=DB(input_path),
|
input=DB(input_path),
|
||||||
workspace=DB(workspace_path),
|
workspace=DB(workspace_path),
|
||||||
identity=DB(pathlib.Path(__file__).parent / "identity"),
|
identity=DB(app_dir / "identity"),
|
||||||
)
|
)
|
||||||
|
|
||||||
for step in STEPS:
|
for step in STEPS:
|
||||||
@@ -45,5 +45,9 @@ def chat(
|
|||||||
dbs.logs[step.__name__] = json.dumps(messages)
|
dbs.logs[step.__name__] = json.dumps(messages)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def execute():
|
||||||
app()
|
app()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
execute()
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from ai import AI
|
from gpt_engineer.ai import AI
|
||||||
from chat_to_files import to_files
|
from gpt_engineer.chat_to_files import to_files
|
||||||
from db import DBs
|
from gpt_engineer.db import DBs
|
||||||
|
|
||||||
|
|
||||||
def setup_sys_prompt(dbs):
|
def setup_sys_prompt(dbs):
|
||||||
@@ -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
|
# https://beta.ruff.rs/docs/configuration/#using-rufftoml
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
select = ["F", "E", "W", "I001"]
|
select = ["F", "E", "W", "I001"]
|
||||||
@@ -23,6 +45,11 @@ exclude = [
|
|||||||
"venv",
|
"venv",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
"Homepage" = "https://github.com/AntonOsika/gpt-engineer"
|
||||||
|
"Bug Tracker" = "https://github.com/AntonOsika/gpt-engineer/issues"
|
||||||
|
|
||||||
|
|
||||||
[tool.ruff.isort]
|
[tool.ruff.isort]
|
||||||
known-first-party = []
|
known-first-party = []
|
||||||
known-third-party = []
|
known-third-party = []
|
||||||
|
|||||||
Reference in New Issue
Block a user