How to use PandasQueryEngine with Gemini model via Vertex AI? #14571
Replies: 10 comments 5 replies
-
Yes, Gemini support has been added to the PandasQueryEngine via Vertex AI. You can use the Gemini models with the from llama_index.llms.vertex import Vertex
from google.oauth2 import service_account
# Load your service account credentials
filename = "vertex-407108-37495ce6c303.json"
credentials: service_account.Credentials = (
service_account.Credentials.from_service_account_file(filename)
)
# Initialize the Vertex instance with the Gemini Pro model
llm = Vertex(
model="gemini-pro",
project=credentials.project_id,
credentials=credentials
)
# Make a completion call
response = llm.complete("Hello Gemini")
print(response.text) For the Gemini Pro Vision model, you can use the following example: from llama_index.llms.vertex import Vertex
from llama_index.core.llms import ChatMessage
# Load your service account credentials
filename = "vertex-407108-37495ce6c303.json"
credentials: service_account.Credentials = (
service_account.Credentials.from_service_account_file(filename)
)
# Define the chat history with an image URL
history = [
ChatMessage(
role="user",
content=[
{"type": "text", "text": "Explain what is in the image below:"},
{
"type": "image_url",
"image_url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBUWFRgWFhYVGRgaGRoZHBwZGBwaGBkcGhgZGRgYGBocIS4lHB4rIRgYJjgmKy8xNTU1GiQ7QDs0Py40NTEBDAwMEA8QGhIRHDEhISE0NDQ0NDQxNDQ0NDE0NDQ0NDQ0NDQ0MTQ0NDExNDQ1NDQ0NDE0NDQ0NDQxMTE0P//AABEIALcBEwMBIgACEQEDEQH/xAAbAAABBQEBAAAAAAAAAAAAAAACAAEDBAUGB//EAD8QAAEDAgIHBQYEBQQCAwAAAAEAAhEDITFBBAUSUWFxkSIyUoGhBhNCscHRFWLh8BRygpLxM1OisiPSBxZj/8QAGQEBAQEBAQEAAAAAAAAAAAAAAAECAwUE/8QAJhEBAQACAgICAAYDAAAAAAAAAAECEQMhBDESQVFhgZGhsRQVIv/aAAwDAQACEQMRAD8A847fFOHVOKvbKdrbrbipB9TikX1NxWhspwEGf72ruPRO2tVGR6LQRNKCh/FVt3onGl1fD6LSbgiDVBmfxtXw+if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FdY6Co9Jg3CNKdMAy112uEEcCuB1jojqdR7LdlxgnNuIPRd84XXF//IemNo1KTy1x94wiQ6LsIx/uUqVl7Th+gsjJMLAd7RN8D/7v0UbNftHwOP8AUEY26AuO/wBUDisM6/b4Hf3D7Jfj7cqZ6hBqlxJtjxUhbaCsU6+bjsOB5j7JHX4OLHf3D7INgTEeqNtPeVi//YB4Hebv0QHXrfAf7v0QbVO0xCIvGV1gjXY8B/u/RO3XsYM9UG85yRe4boWF+PZ7B6j7Jvx38hP9VkNtvbO5JYf"
},
],
),
]
# Initialize the Vertex instance with the Gemini Pro Vision model
llm = Vertex(
model="gemini-pro-vision",
project=credentials.project_id,
credentials=credentials,
)
# Make a chat call
response = llm.chat(history)
print(response.message.content) These examples demonstrate how to use the Gemini models with the |
Beta Was this translation helpful? Give feedback.
-
@dosu ok, can you provide sample code where I use Gemini model from Vertex AI in PandasQueryEngine, to query database such as a csv file? |
Beta Was this translation helpful? Give feedback.
-
@dosu I don't see PandasQueryEngine is being used in your codes above? your code above seems to use embeddings and semantic search and is therefore not suitable for database csv, while PandasQueryEngine uses pandas library to do precise database query |
Beta Was this translation helpful? Give feedback.
-
@dosu ok what lib should I install to run the code |
Beta Was this translation helpful? Give feedback.
-
@dosu I received this error: ModuleNotFoundError: No module named 'llama_index.llms.vertex' |
Beta Was this translation helpful? Give feedback.
-
still not working. Anyone can help here? |
Beta Was this translation helpful? Give feedback.
-
My code and error:
and error message: |
Beta Was this translation helpful? Give feedback.
-
@dosu I am getting this error ``` Could not load OpenAI model. If you intended to use OpenAI, please check your OPENAI_API_KEY. To disable the LLM entirely, set llm=None.
|
Beta Was this translation helpful? Give feedback.
-
@dosu its throwing an error TypeError: Vertex.init() got an unexpected keyword argument 'llm' |
Beta Was this translation helpful? Give feedback.
-
I changed default llm llamaindex uses globaly using settings
|
Beta Was this translation helpful? Give feedback.
-
is Gemini support added to it?
Beta Was this translation helpful? Give feedback.
All reactions