mirror of
https://github.com/aljazceru/gpt-engineer.git
synced 2025-12-18 13:15:00 +01:00
Remove delete_existing option; Introduce archive (#409)
* Remove `delete_existing` option; Introduce archive * Update gpt_engineer/db.py * Update gpt_engineer/main.py * Update gpt_engineer/main.py * Update gpt_engineer/steps.py * Update gpt_engineer/steps.py --------- Co-authored-by: Anton Osika <anton.osika@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
|
||||
# This class represents a simple database that stores its data as files in a directory.
|
||||
@@ -47,3 +48,4 @@ class DBs:
|
||||
preprompts: DB
|
||||
input: DB
|
||||
workspace: DB
|
||||
archive: DB
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
import logging
|
||||
import shutil
|
||||
import os
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
@@ -18,7 +18,6 @@ app = typer.Typer()
|
||||
@app.command()
|
||||
def main(
|
||||
project_path: str = typer.Argument("example", help="path"),
|
||||
delete_existing: bool = typer.Argument(False, help="delete existing files"),
|
||||
model: str = typer.Argument("gpt-4", help="model id string"),
|
||||
temperature: float = 0.1,
|
||||
steps_config: steps.Config = typer.Option(
|
||||
@@ -35,28 +34,25 @@ def main(
|
||||
):
|
||||
logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO)
|
||||
|
||||
input_path = Path(project_path).absolute()
|
||||
memory_path = input_path / f"{run_prefix}memory"
|
||||
workspace_path = input_path / f"{run_prefix}workspace"
|
||||
|
||||
if delete_existing:
|
||||
# Delete files and subdirectories in paths
|
||||
shutil.rmtree(memory_path, ignore_errors=True)
|
||||
shutil.rmtree(workspace_path, ignore_errors=True)
|
||||
|
||||
model = fallback_model(model)
|
||||
|
||||
ai = AI(
|
||||
model=model,
|
||||
temperature=temperature,
|
||||
)
|
||||
|
||||
input_path = Path(project_path).absolute()
|
||||
memory_path = input_path / f"{run_prefix}memory"
|
||||
workspace_path = input_path / f"{run_prefix}workspace"
|
||||
archive_path = input_path / f"{run_prefix}archive"
|
||||
|
||||
initial_run = not os.path.exists(memory_path) and not os.path.exists(workspace_path)
|
||||
dbs = DBs(
|
||||
memory=DB(memory_path),
|
||||
logs=DB(memory_path / "logs"),
|
||||
input=DB(input_path),
|
||||
workspace=DB(workspace_path),
|
||||
preprompts=DB(Path(__file__).parent / "preprompts"),
|
||||
archive=None if initial_run else DB(archive_path),
|
||||
)
|
||||
|
||||
steps = STEPS[steps_config]
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import datetime
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from enum import Enum
|
||||
@@ -258,6 +261,16 @@ def fix_code(ai: AI, dbs: DBs):
|
||||
return messages
|
||||
|
||||
|
||||
def archive(ai: AI, dbs: DBs):
|
||||
os.makedirs(dbs.archive.path, exist_ok=True)
|
||||
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
shutil.move(dbs.memory.path, dbs.archive.path / timestamp / dbs.memory.path.name)
|
||||
shutil.move(
|
||||
dbs.workspace.path, dbs.archive.path / timestamp / dbs.workspace.path.name
|
||||
)
|
||||
return []
|
||||
|
||||
|
||||
def human_review(ai: AI, dbs: DBs):
|
||||
review = human_input()
|
||||
dbs.memory["review"] = review.to_json() # type: ignore
|
||||
@@ -280,15 +293,17 @@ class Config(str, Enum):
|
||||
# Different configs of what steps to run
|
||||
STEPS = {
|
||||
Config.DEFAULT: [
|
||||
archive,
|
||||
clarify,
|
||||
gen_clarified_code,
|
||||
gen_entrypoint,
|
||||
execute_entrypoint,
|
||||
human_review,
|
||||
],
|
||||
Config.BENCHMARK: [simple_gen, gen_entrypoint],
|
||||
Config.SIMPLE: [simple_gen, gen_entrypoint, execute_entrypoint],
|
||||
Config.BENCHMARK: [archive, simple_gen, gen_entrypoint],
|
||||
Config.SIMPLE: [archive, simple_gen, gen_entrypoint, execute_entrypoint],
|
||||
Config.TDD: [
|
||||
archive,
|
||||
gen_spec,
|
||||
gen_unit_tests,
|
||||
gen_code,
|
||||
@@ -297,6 +312,7 @@ STEPS = {
|
||||
human_review,
|
||||
],
|
||||
Config.TDD_PLUS: [
|
||||
archive,
|
||||
gen_spec,
|
||||
gen_unit_tests,
|
||||
gen_code,
|
||||
@@ -306,6 +322,7 @@ STEPS = {
|
||||
human_review,
|
||||
],
|
||||
Config.CLARIFY: [
|
||||
archive,
|
||||
clarify,
|
||||
gen_clarified_code,
|
||||
gen_entrypoint,
|
||||
@@ -313,6 +330,7 @@ STEPS = {
|
||||
human_review,
|
||||
],
|
||||
Config.RESPEC: [
|
||||
archive,
|
||||
gen_spec,
|
||||
respec,
|
||||
gen_unit_tests,
|
||||
|
||||
Reference in New Issue
Block a user