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

exporting the api key to the environment doesn't work for me

Open Emilprivate opened this issue 1 year ago • 6 comments

I can't get the export command to work, so an alternative solution like using an extern file or hardcoding the api in the code would be a nice solution. I personally created an external json config file and parsed the api key from that to the python script.

So a solution could be:

  1. Make a json file named "config.json"
  2. Inside of ai.py add:
import json

def get_api_key(file_name: str) -> str:
    with open(file_name, 'r') as f:
        config = json.load(f)
    return config['openai_api_key']
  1. Inside of config.json add:
{
    "openai_api_key": "your_api_key"
}
  1. In the init part of the AI class add:
class AI:
    def __init__(self, **kwargs):
        openai.api_key = get_api_key("config.json")
        self.kwargs = kwargs

Emilprivate avatar Jun 13 '23 17:06 Emilprivate

I created a PR where this issue can be resolved using .env variables. Please leave a comment under there if you think that would resolve your issue.

https://github.com/AntonOsika/gpt-engineer/pull/22

ScorchChamp avatar Jun 14 '23 07:06 ScorchChamp

that solved my issue, thanks

MathisTimo avatar Jun 14 '23 10:06 MathisTimo

that solved my issue, thanks

IrmaEdmund avatar Jun 14 '23 12:06 IrmaEdmund

i fixed my problem by using set: OPENAI_API_KEY= instead of export worked for me =)

blue27831 avatar Jun 14 '23 18:06 blue27831

I created a PR where this issue can be resolved using .env variables. Please leave a comment under there if you think that would resolve your issue.

#22

This worked for me on windows 11

Bortus-AI avatar Jun 15 '23 14:06 Bortus-AI

Open discussion about this in #135

patillacode avatar Jun 18 '23 01:06 patillacode

If you wish to reopen the issue please do following the new issue template.

patillacode avatar Jun 21 '23 12:06 patillacode