Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load env variable handling & Project preprompt enhancement #740

Merged
merged 5 commits into from
Sep 25, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion gpt_engineer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.getcwd() + "/.env")
saschalalala marked this conversation as resolved.
Show resolved Hide resolved
openai.api_key = os.getenv("OPENAI_API_KEY")


Expand Down Expand Up @@ -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",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--use-custom-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)
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you create a separate function for this? πŸ™

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do


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),
)
Expand Down