I have the following python codes:
from llama_index import ( SimpleDirectoryReader, VectorStoreIndex, ) documents = SimpleDirectoryReader("docs").load_data() index = VectorStoreIndex.from_documents(documents) #Why is there openAI exception thrown here? Do i need openai for this? I don't like openai API as i don't want to pay for using it. Message=No API key found for OpenAI. Please set either the OPENAI_API_KEY environment variable or openai.api_key prior to initialization. API keys can be found or created at
Source=D:\MyGit\testAI\demo1\demo1.py StackTrace: File "D:\MyGit\testAI\demo1\demo1.py", line 14, in (Current frame) index = VectorStoreIndex.from_documents(documents) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: No API key found for OpenAI. Please set either the OPENAI_API_KEY environment variable or openai.api_key prior to initialization. API keys can be found or created at
I have tried the above codes and i don't understand why i need openai key!?
2 Answers
Llama_index is built on OpenAI, it uses various GPT models. You can even specify which ones you want to use.
Llama-index (or in general, RAG) requires two components:
- A "retriever" which can communicate with an "index" of embeddings created earlier
- A "response synthesizer" which will augment the responses retrieved by the earlier stage and generate a response
For both the tasks, llama-index uses OpenAI by default. You can configure several other large language models for either tasks - for the Embedding Generation / Indexing / Retrieving, as well as for Response Synthesis.
Once you move to HuggingFace / local models for both these tasks, you will no longer encounter the OpenAI error.