import json import logging import os from pathlib import Path import typer from gpt_engineer import steps from gpt_engineer.ai import AI, fallback_model from gpt_engineer.collect import collect_learnings from gpt_engineer.db import DB, DBs from gpt_engineer.steps import STEPS app = typer.Typer() @app.command() def main( project_path: str = typer.Argument("example", help="path"), model: str = typer.Argument("gpt-4", help="model id string"), temperature: float = 0.1, steps_config: steps.Config = typer.Option( steps.Config.DEFAULT, "--steps", "-s", help="decide which steps to run" ), verbose: bool = typer.Option(False, "--verbose", "-v"), run_prefix: str = typer.Option( "", help=( "run prefix, if you want to run multiple variants of the same project and " "later compare them" ), ), ): logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) 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] for step in steps: messages = step(ai, dbs) dbs.logs[step.__name__] = json.dumps(messages) collect_learnings(model, temperature, steps, dbs) if __name__ == "__main__": app()