Skip to main content
DeprecatedThis integration is deprecated and will be removed in a future release. Please use GoogleGenerativeAI instead. See the full release notes and migration guide.
You are currently on a page documenting the use of Google Vertex text completion models. Many Google models are chat completion models.You may be looking for this page instead.
Note: This is separate from the Google Generative AI integration, it exposes Vertex AI Generative API on Google Cloud. VertexAI exposes all foundational models available in google cloud. For a full and updated list of available models visit VertexAI documentation

Setup

By default, Google Cloud does not use customer data to train its foundation models as part of Google Cloud’s AI/ML Privacy Commitment. More details about how Google processes data can also be found in Google’s Customer Data Processing Addendum (CDPA). To use Vertex AI Generative AI you must have the langchain-google-vertexai Python package installed and either:
  • Have credentials configured for your environment (gcloud, workload identity, etc…)
  • Store the path to a service account JSON file as the GOOGLE_APPLICATION_CREDENTIALS environment variable
This codebase uses the google.auth library which first looks for the application credentials variable mentioned above, and then looks for system-level auth. For more information, see:

Usage

VertexAI supports all LLM functionality.
We can use the generate method to get back extra metadata like safety attributes and not just text completions.

OPTIONAL : Managing Safety Attributes

  • If your use case requires your to manage thresholds for saftey attributes, you can do so using below snippets
NOTE : We recommend exercising extreme caution when adjusting Safety Attributes thresholds
You can use different foundational models for specialized in different tasks. For an updated list of available models visit VertexAI documentation

Multimodality

With Gemini, you can use LLM in a multimodal mode:
Let’s double-check it’s a cat :)

You can also pass images as bytes:
Please, note that you can also use the image stored in GCS (just point the url to the full GCS path, starting with gs:// instead of a local one). And you can also pass a history of a previous chat to the LLM:
You can also use the public image URL:

Using pdfs with gemini models

Using video with gemini models

Using audio with gemini models

Vertex model garden

Vertex Model Garden exposes open-sourced models that can be deployed and served on Vertex AI. Hundreds popular open-sourced models like Llama, Falcon and are available for One Click Deployment If you have successfully deployed a model from Vertex Model Garden, you can find a corresponding Vertex AI endpoint in the console or via API.
Like all LLMs, we can then compose it with other components:

Llama on vertex model garden

Llama is a family of open weight models developed by Meta that you can fine-tune and deploy on Vertex AI. Llama models are pre-trained and fine-tuned generative text models. You can deploy Llama 2 and Llama 3 models on Vertex AI. Official documentation for more information about Llama on Vertex Model Garden
To use Llama on Vertex Model Garden you must first deploy it to Vertex AI Endpoint
Like all LLMs, we can then compose it with other components:

Falcon on vertex model garden

Falcon is a family of open weight models developed by Falcon that you can fine-tune and deploy on Vertex AI. Falcon models are pre-trained and fine-tuned generative text models.
To use Falcon on Vertex Model Garden you must first deploy it to Vertex AI Endpoint
Like all LLMs, we can then compose it with other components:

Gemma on vertex AI model garden

Gemma is a set of lightweight, generative artificial intelligence (AI) open models. Gemma models are available to run in your applications and on your hardware, mobile devices, or hosted services. You can also customize these models using tuning techniques so that they excel at performing tasks that matter to you and your users. Gemma models are based on Gemini models and are intended for the AI development community to extend and take further.
To use Gemma on Vertex Model Garden you must first deploy it to Vertex AI Endpoint