In this guide, you send a text prompt request and a multimodal prompt and image request to the Vertex AI Gemini API and view the responses.
Prerequisites
To complete this guide, you must have a Google Cloud project with the Vertex AI API enabled. Follow the Vertex AI setup guide to complete these steps.
Add the Vertex AI client library as a dependency
The Vertex AI client library includes many features. To speed up compilation, enable only the features that you need:
cargo add google-cloud-aiplatform-v1 --no-default-features --features prediction-service
Send a prompt to the Vertex AI Gemini API
- Initialize the client using the default settings:
- Build the model name. This example receives the project ID as an argument,
uses a fixed location (
global), and sets the model to a specific version of Gemini:
If you run this function in your own code, pass the project ID (without any
projects/ prefix) of the project that you selected in the prerequisites.
- Send the request:
- Print the response. You can use the
:#?format specifier to format the nested response objects:
Text prompt: complete code
Send a prompt and an image to the Vertex AI Gemini API
- Initialize the client using the default settings:
- Build the model name:
- Create the image part of the request:
- Create the text prompt part of the request:
- Send the full request:
- Print the full response: