visual-chatgpt
visual-chatgpt copied to clipboard
Display can't find openai_api_key.
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. (type=value_error)
how to solve it?
Did you run:
# prepare your private openAI private key
export OPENAI_API_KEY={Your_Private_Openai_Key}
If you did run it and restarted your pc/terminal or something then you might have to do it again
Did you run:
# prepare your private openAI private key export OPENAI_API_KEY={Your_Private_Openai_Key}If you did run it and restarted your pc/terminal or something then you might have to do it again
If you run it on Windows, use set instead of export, and your openai api key can be found here.
I added this to the visual_chatgpt.py file (line 11): os.environ["OPENAI_API_KEY"] = "INSERT_YOUR_KEY_HERE" (replace with your key and save the file)
i tried both “set OPENAI_API_KEY=sk-xxxx” and “set OPENAI_API_KEY={sk-xxxx}” still not work,could anyone help?
I have the same problem in PyCharm on Linux, and I have tried all the remedies above plus setting the environment variable in the IDE.
However, when I run the program using the same API key from the terminal, it instead complains about that the (newly generated) API key is Incorrect...
i tried both “set OPENAI_API_KEY=sk-xxxx” and “set OPENAI_API_KEY={sk-xxxx}” still not work,could anyone help?
hello, try removing the {} : “set OPENAI_API_KEY=sk-xxxx”, works for me
i tried both “set OPENAI_API_KEY=sk-xxxx” and “set OPENAI_API_KEY={sk-xxxx}” still not work,could anyone help?
I provide a direct solution: enter System and Environmental Variables, and write the key and value to both System and User
I have the same problem before and I solve it by deactivate and then activate the virtual env after set the env variable. Something like below:
conda env config vars set OPENAI_API_KEY=sky
conda deactivate env_name
conda activate env_name
Hope this help you.
For testing you can edit visual_chatgpt.py file at line 2 after import os put: os.environ['OPENAI_API_KEY'] = 'your key'
I added this to the visual_chatgpt.py file (line 11): os.environ["OPENAI_API_KEY"] = "INSERT_YOUR_KEY_HERE" (replace with your key and save the file)
It is work for me by adding that.
my computer system : Mac M1 using pipenv
I solved it by the fix below.
self.llm = OpenAI(temperature=0, openai_api_key="sk-xxx")
If you are using windows.
- Create .env file in the same folder as your python program.
- OPENAI_API_KEY="xxx" in the .env file
pip install python-dotenvIn your code, declare
from dotenv import load_dotenv
# Load environment variables from the .env file
load_dotenv()
Context: I am reading my token from a config file and this did not work:
llm = OpenAI(openai_api_key=str(api_key_input))
llm = OpenAI(temperature=0.9)
But this did: llm = OpenAI(temperature=0.9, openai_api_key=str(api_key_input))
thanks @hjw21century
If you are using -> Jupiter Try this
%env OPENAI_API_KEY="sk-*****"