diff --git a/gpt_engineer/main.py b/gpt_engineer/main.py index 123df6a51b..0897f6de33 100644 --- a/gpt_engineer/main.py +++ b/gpt_engineer/main.py @@ -20,6 +20,9 @@ def load_env_if_needed(): if os.getenv("OPENAI_API_KEY") is None: load_dotenv() + if os.getenv("OPENAI_API_KEY") is None: + # if there is no .env file, try to load from the current working directory + load_dotenv(dotenv_path=os.path.join(os.getcwd(), ".env")) openai.api_key = os.getenv("OPENAI_API_KEY") @@ -50,6 +53,12 @@ def main( help="""Endpoint for your Azure OpenAI Service (https://xx.openai.azure.com). In that case, the given model is the deployment name chosen in the Azure AI Studio.""", ), + use_project_preprompts: bool = typer.Option( + False, + "--use-project-preprompts", + help="""Use the project's preprompts instead of the default ones. + Copies all original preprompts to the project's workspace if they don't exist there.""", + ), verbose: bool = typer.Option(False, "--verbose", "-v"), ): logging.basicConfig(level=logging.DEBUG if verbose else logging.INFO) @@ -80,13 +89,24 @@ def main( project_metadata_path = input_path / ".gpteng" memory_path = project_metadata_path / "memory" archive_path = project_metadata_path / "archive" + preprompts_path = Path(__file__).parent / "preprompts" + + if use_project_preprompts: + project_preprompts_path = input_path / "preprompts" + if not project_preprompts_path.exists(): + project_preprompts_path.mkdir() + + for file in preprompts_path.glob("*"): + if not (project_preprompts_path / file.name).exists(): + (project_preprompts_path / file.name).write_text(file.read_text()) + preprompts_path = project_preprompts_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"), + preprompts=DB(preprompts_path), archive=DB(archive_path), project_metadata=DB(project_metadata_path), )