Find answers from the community

Updated 6 months ago

Does llamaindex πŸ¦™ support google Gemini

At a glance

The post asks if the llamaindex library supports the Google Gemini API instead of the OpenAI API. Community members confirm that llamaindex does support Gemini, and provide a link to an example notebook. They then discuss how to pass the Gemini LLM to the query engine, including sharing code snippets. However, the community members encounter an import error when trying to use the Gemini LLM, and work through troubleshooting steps to resolve the issue.

Useful resources
Does llamaindex πŸ¦™ support google Gemini api instead of OpenAI api ?
L
C
W
12 comments
how can i pass the new llm which is the gemini to the query_engin:
from llama_index.core.llms import Gemini from dotenv import load_dotenv import os import pandas as pd from llama_index.core.query_engine import PandasQueryEngine from prompts import new_prompt, instruction_str from llama_index.llms.gemini import Gemini GOOGLE_API_KEY = "my-api-is-here"; os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY data_path = os.path.join('data', 'data-info.csv'); data_df = pd.read_csv(data_path); data_query_engin = PandasQueryEngine(df=data_df, verbose=True, instruction_str=instruction_str); data_query_engin.update_prompts({'pandas_prompt': new_prompt}); data_query_engin.query("what is the second surah and what is about?")
@Logan M can you help i want to pass the dat_query_engin that i am using gemini to i want to pass llm=llm but i dont know to defind the llm varible to gemini can you help me i did readed the link you send me but so far no progess?
do you think this will work:
i pass gemini to the llm:
from llama_index.core.llms import Gemini from dotenv import load_dotenv import os import pandas as pd from llama_index.core.query_engine import PandasQueryEngine from prompts import new_prompt, instruction_str from llama_index.llms.gemini import Gemini GOOGLE_API_KEY = "api-here"; os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY llm = Gemini() data_path = os.path.join('data', 'data-info.csv'); data_df = pd.read_csv(data_path); data_query_engin = PandasQueryEngine(df=data_df, verbose=True, instruction_str=instruction_str,llm=llm); data_query_engin.update_prompts({'pandas_prompt': new_prompt}); data_query_engin.query("what is the second surah and what is about?")
that should work yes. It doesnt?
yes it saying cant find gemini import:
ImportError: cannot import name 'Gemini' from 'llama_index.core.llms' (/Users/ahmednadiir/Desktop/agency/localEvir/lib/python3.11/site-packages/llama_index/core/llms/__init__.py)

my code:
from llama_index.core.llms import Gemini from dotenv import load_dotenv import os import pandas as pd from llama_index.core.query_engine import PandasQueryEngine from prompts import new_prompt, instruction_str from llama_index.llms.gemini import Gemini GOOGLE_API_KEY = "api-is-here"; os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY llm = Gemini() data_path = os.path.join('data', 'data-info.csv'); data_df = pd.read_csv(data_path); data_query_engin = PandasQueryEngine(df=data_df, verbose=True, instruction_str=instruction_str,llm=llm); data_query_engin.update_prompts({'pandas_prompt': new_prompt}); data_query_engin.query("what is the second surah and what is about?")
@Logan M i install it like this install llama-index-llms-gemini and also like this pip install -q llama-index google-generativeai but somehow still getting this error: ImportError: cannot import name 'Gemini' from 'llama_index.core.llms' (/Users/ahmednadiir/Desktop/agency/localEvir/lib/python3.11/site-packages/llama_index/core/llms/__init__.py)
You will have to comment the first import
That is causing you the import error
Plain Text
from dotenv import load_dotenv
import os
import pandas as pd
from llama_index.core.query_engine import PandasQueryEngine
from prompts import new_prompt, instruction_str
from llama_index.llms.gemini import Gemini

GOOGLE_API_KEY = "api-is-here";
os.environ["GOOGLE_API_KEY"] = GOOGLE_API_KEY
llm = Gemini()

data_path = os.path.join('data', 'data-info.csv');
data_df = pd.read_csv(data_path);

data_query_engin = PandasQueryEngine(df=data_df, verbose=True, instruction_str=instruction_str,llm=llm);
data_query_engin.update_prompts({'pandas_prompt': new_prompt});
data_query_engin.query("what is the second surah and what is about?")
what a selly misake thannk you so much man you ar legend
Add a reply
Sign up and join the conversation on Discord