llama_index icon indicating copy to clipboard operation
llama_index copied to clipboard

Validation error for OpenAI when using GPTSimpleVectorIndex

Open rshoaib1190 opened this issue 2 years ago • 1 comments

I tried to use the example from the documentation, but I always get the openai key error when using GPTSimpleVectorIndex

import openai 
from gpt_index import SimpleDirectoryReader, GPTSimpleVectorIndex

openai.api_key = "YOUR KEY GOES HERE"

documents = SimpleDirectoryReader('data').load_data()
index = GPTSimpleVectorIndex('documents')

Any idea what's going wrong? It works fine with the key when I use only openai.

Capture

rshoaib1190 avatar Jan 24 '23 21:01 rshoaib1190

you need to explicitly add OPENAI_API_KEY environment variable. You can see the example here https://github.com/jerryjliu/gpt_index/blob/main/examples/paul_graham_essay/TestEssay.ipynb

ihfazhillah avatar Jan 25 '23 15:01 ihfazhillah

Thanks, it worked now :)

rshoaib1190 avatar Jan 25 '23 20:01 rshoaib1190