richardyc / Chrome-GPT

An AutoGPT agent that controls Chrome on your desktop
GNU General Public License v3.0
1.68k stars 207 forks source link

Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass `openai_api_key` as a named parameter. #5

Closed BaseInfinity closed 1 year ago

BaseInfinity commented 1 year ago

I've exported the API key and still am having issues getting it to read: Screen Shot 2023-05-03 at 12 57 40 PM

I also searched the REPO for use case of both OPENAI_API_KEY and openai_api_key and found nothing so I'm a bit confused

NickR23 commented 1 year ago

Seems to be a bug with getting environment variables from the calling bash shell in poetry.

A quick work around that works is to just pass the api key in chromegpt/agent/zeroshot.py:

 43 class ZeroShotAgent(ChromeGPTAgent):
 44     def __init__(self, model: str = "gpt-3.5-turbo", verbose: bool = False) -> None:
 45         """Initialize the ZeroShotAgent."""
 46         self.model = model
 47         self.agent = get_zeroshot_agent(
 48             llm=ChatOpenAI(model_name=model, temperature=0, openai_api_key='{YOUR_API_KEY_HERE}'),  # type: ignore
 49             verbose=verbose,
 50         )

Replace YOUR_API_KEY_HERE with your key.

BaseInfinity commented 1 year ago

Seems to be a bug with getting environment variables from the calling bash shell in poetry.

A quick work around that works is to just pass the api key in chromegpt/agent/zeroshot.py:

 43 class ZeroShotAgent(ChromeGPTAgent):
 44     def __init__(self, model: str = "gpt-3.5-turbo", verbose: bool = False) -> None:
 45         """Initialize the ZeroShotAgent."""
 46         self.model = model
 47         self.agent = get_zeroshot_agent(
 48             llm=ChatOpenAI(model_name=model, temperature=0, openai_api_key='{YOUR_API_KEY_HERE}'),  # type: ignore
 49             verbose=verbose,
 50         )

Replace YOUR_API_KEY_HERE with your key.

Ahh okay, I'll try that tomorrow and give it another whirl

NickR23 commented 1 year ago

Side note There's different functions that use the api key for each agent so make sure you read the error logs for the right line to change

For example:

{...}
  File "/Users/nr/chromegpt/Chrome-GPT/chromegpt/agent/autogpt/autogpt.py", line 25, in __init__
    llm=ChatOpenAI(model_name=model, temperature=0),  # type: ignore
{...}

Would mean you should change that line to: llm=ChatOpenAI(model_name=model, temperature=0, openai_api_key='{YOUR_API_KEY_HERE}'), # type: ignore

Just in case anyone else has this problem :)

BaseInfinity commented 1 year ago

This appears to be fixed in the latest version but ty for the quick response!