Find answers from the community

Updated 3 months ago

newbie here. I tried to follow the

newbie here. I tried to follow the sample in the starter tutorial: https://docs.llamaindex.ai/en/stable/getting_started/starter_example/
keep getting the following error, even after I have set the OPENAI_API_KEY environment variable or in the code:
Traceback (most recent call last):
File "c:\LlamaIndex\Start.py", line 9, in <module>
index = VectorStoreIndex.from_documents(documents)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python312\Lib\site-packages\llama_index\core\indices\base.py", line 145, in from_documents
return cls(
^^^^
File "C:\Python\Python312\Lib\site-packages\llama_index\core\indices\vector_store\base.py", line 71, in init
else embed_model_from_settings_or_context(Settings, service_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python312\Lib\site-packages\llama_index\core\settings.py", line 274, in embed_model_from_settings_or_context
return settings.embed_model
^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python312\Lib\site-packages\llama_index\core\settings.py", line 67, in embed_model
self._embed_model = resolve_embed_model("default")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python\Python312\Lib\site-packages\llama_index\core\embeddings\utils.py", line 66, in resolve_embed_model
raise ValueError(
ValueError:
**
Could not load OpenAI embedding model. If you intended to use OpenAI, please check your OPENAI_API_KEY.
Original error:
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 https://platform.openai.com/account/api-keys

Consider using embed_model='local'.
Visit our documentation for more embedding options: https://docs.llamaindex.ai/en/stable/module_guides/models/embeddings.html#modules
**
n
1 comment
Try
pip install openai

from dotenv import load_dotenv
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")

Also can you pls share your code?
Add a reply
Sign up and join the conversation on Discord