gpt-engineer icon indicating copy to clipboard operation
gpt-engineer copied to clipboard

.env setup for OpenAI API key

Open OriAshkenazi opened this issue 1 year ago • 8 comments

This pull request adds support for loading environment variables from a .env file in the Makefile of the gpt-engineer project. This is achieved by using the python-dotenv package to read environment variables from a .env file when the make run command is executed. The following changes have been implemented:

  1. Updated the Makefile: Added a new load-env target in the Makefile. This target uses python-dotenv to load the environment variables from a .env file.
  2. Updated the run target: Modified the run target to depend on the load-env target. This ensures that the environment variables are loaded before the run command is executed.
  3. Updated pyproject.toml: Added python-dotenv >= 1.0.0 to the list of project dependencies in pyproject.toml. This ensures that python-dotenv is installed when setting up the project.
  4. Updated README.md: Updated the new setup process to reflect the changes.

These changes allow for better management and confidentiality of environment variables in the gpt-engineer project, particularly when it comes to sensitive information that should not be hard-coded. This method will also help users keep track of their API key between runs.

OriAshkenazi avatar Jul 05 '23 11:07 OriAshkenazi

Thanks @OriAshkenazi !

I like the idea I’m not sure it covers all ways to run it though.

It should be possible to pip install and then only run gpt-engineer. No make.

I thought about this last night though and what I think we want is:

  1. Check if API KEY env variable exist
  2. If it doesn’t, call load_dotenv
  3. Package these two steps in a nice function so it is used in main.py and all scripts etc.

AntonOsika avatar Jul 06 '23 21:07 AntonOsika

What do you think?

AntonOsika avatar Jul 06 '23 21:07 AntonOsika

What do you think?

I'll give it another go on Sunday to make sure it covers the scenario you mentioned! :)

OriAshkenazi avatar Jul 07 '23 15:07 OriAshkenazi

Updated What do you think? I feel like everything is covered now

OriAshkenazi avatar Jul 08 '23 06:07 OriAshkenazi

Great. Appreciate the effort @OriAshkenazi.

Be prepared it often takes a few iterations to make things work exactly as we want them in serious development.

I added some comments since a part of the philosophy is to minimize the LoC.

AntonOsika avatar Jul 08 '23 13:07 AntonOsika

PS:

pytest failing due to that env variable doesn't exist for tests

AntonOsika avatar Jul 08 '23 14:07 AntonOsika

PS:

pytest failing due to that env variable doesn't exist for tests

How can I solve this without giving away an API key to the public? Can you explain to me what can be done? Even a general broad explanation will be good. I'll make sure to attend to the rest of the comments later today.

OriAshkenazi avatar Jul 09 '23 09:07 OriAshkenazi

Hey! I explained the proposed solution in my proposal in the review comments, did you see?

AntonOsika avatar Jul 09 '23 16:07 AntonOsika