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**:
|
||||
- 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
|
||||
|
||||
@@ -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)}]
|
||||
@@ -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:
|
||||
@@ -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
|
||||
@@ -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()
|
||||
@@ -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
|
||||
@@ -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 = []
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
black==23.3.0
|
||||
openai==0.27.8
|
||||
ruff==0.0.272
|
||||
typer==0.9.0
|
||||
typer==0.9.0
|
||||
Reference in New Issue
Block a user