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
API_KEY = "api-is-here"
import os
from llama_index.core import StorageContext, VectorStoreIndex, load_index_from_storage
from llama_index.readers.file import PDFReader
from dotenv import load_dotenv
from llama_index.core import Settings
from llama_index.llms.gemini import Gemini
Settings.llm = Gemini()
load_dotenv()
def get_index(data, index_name):
index = None
if not os.path.exists(index_name):
print("building index", index_name)
index = VectorStoreIndex.from_documents(data, show_progress=True)
index.storage_context.persist(persist_dir=index_name)
else:
index = load_index_from_storage(
StorageContext.from_defaults(persist_dir=index_name)
)
return index
pdf_path = os.path.join("data", "the-tafsir-of-the-quran.pdf")
canada_pdf = PDFReader().load_data(file=pdf_path)
canada_index = get_index(canada_pdf, "canada")
canada_engine = canada_index.as_query_engine()
from llama_index.llms.gemini import Gemini
GOOGLE_API_KEY = "api-here-";
os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY
llm = Gemini()
pip install llama-index-embeddings-gemini
from llama_index.embeddings.gemini import GeminiEmbedding Settings.embed_model = GeminiEmbedding()
API_KEY = "api-here"
or i have to hard code itSettings.llm = Gemini()
GOOGLE_API_KEY = "api-here";
os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY
Settings.embed_model = GeminiEmbedding()