LlamaIndex LLMs Gemini
raw JSON → 0.6.2 verified Fri May 01 auth: no python
LlamaIndex integration for Google Gemini LLMs. Provides a Gemini class that wraps the Google Generative AI SDK for use within LlamaIndex workflows. Current stable version is 0.6.2, released regularly alongside LlamaIndex ecosystem updates.
pip install llama-index-llms-gemini Common errors
error ModuleNotFoundError: No module named 'llama_index.llms.gemini' ↓
cause The package is not installed or the import path is incorrect.
fix
Run
pip install llama-index-llms-gemini (or switch to llama-index-llms-google) and use from llama_index.llms.gemini import Gemini. error google.api_core.exceptions.PermissionDenied: 403 ↓
cause Invalid or missing API key.
fix
Ensure GOOGLE_API_KEY is set correctly. If using Vertex AI, check your GCP service account permissions.
error ValueError: Model name 'gemini-pro' is not valid ↓
cause Model name must include the 'models/' prefix.
fix
Use model='models/gemini-pro' instead of 'gemini-pro'.
Warnings
breaking In version 0.2.0+, the import path changed from `llama_index.llms.gemini` to `llama_index.llms.google` (for Google AI) or `llama_index.llms.vertex` (for Vertex AI). This package (`llama-index-llms-gemini`) is deprecated in favor of `llama-index-llms-google`. ↓
fix Switch to `pip install llama-index-llms-google` and use `from llama_index.llms.google import Gemini`.
deprecated The `llama-index-llms-gemini` package is deprecated. New projects should use `llama-index-llms-google`. ↓
fix Use `pip install llama-index-llms-google` and import from `llama_index.llms.google`.
gotcha Google API key must be set either via the `api_key` parameter or the `GOOGLE_API_KEY` environment variable. Not setting it results in an authentication error. ↓
fix Set `GOOGLE_API_KEY` environment variable or pass `api_key` to the Gemini constructor.
Imports
- Gemini wrong
from llama_index.llms import Geminicorrectfrom llama_index.llms.gemini import Gemini
Quickstart
import os
from llama_index.llms.gemini import Gemini
api_key = os.environ.get("GOOGLE_API_KEY", "")
llm = Gemini(api_key=api_key, model="models/gemini-pro")
resp = llm.complete("What is the capital of France?")
print(resp)