gabacode / chatPDF

Load a PDF file and ask questions via llama_index and GPT
93 stars 35 forks source link

failed to add API key #2

Closed KangtanC closed 1 year ago

KangtanC commented 1 year ago

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]

gabacode commented 1 year ago

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!

gabacode commented 1 year ago

Closing for now, feel free to reopen if needed.

KangtanC commented 1 year ago

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