gabacode/chatPDF

failed to add API key

Closed this issue · 3 comments

Traceback (most recent call last):
File "/Users/aquaticdwarf/Downloads/chatPDF-main/main.py", line 99, in
ask(file)
File "/Users/aquaticdwarf/Downloads/chatPDF-main/main.py", line 38, in ask
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="text-davinci-003"))
File "pydantic/main.py", line 341, in pydantic.main.BaseModel.init
pydantic.error_wrappers.ValidationError: 1 validation error for OpenAI
root
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)

openai.api_key = os.environ["API_KEY"] = [REDACTED]

Hello @KangtanC,
In order to load your API key from env, you should keep the code as it is and add a new file called .env in the root directory with the following content.

OPENAI_API_KEY=sk-therestofyourapikey

Also, I would suggest you not to publish your API key publicly, so please edit your comment or revoke your key and create a new one with OpenAI.

I hope this helps!

Closing for now, feel free to reopen if needed.

thank you very much, it's very helpful. The API key I've sent has deleted several numbers so it can't be used.