All functionality related to Google Cloud Platform and other Google
products.
Integration packages for Gemini models and the VertexAI platform are maintained in the langchain-google repository. You can find a host of LangChain integrations with other Google APIs in the googleapis Github organization.
Chat models
We recommend individual developers to start with Gemini API (langchain-google-genai
) and move to Vertex AI (langchain-google-vertexai
) when they need access to commercial support and higher rate limits. If you’re already Cloud-friendly or Cloud-native, then you can get started in Vertex AI straight away.
Please see here for more information.
Google Generative AI
Access GoogleAI Gemini
models such as gemini-pro
and gemini-pro-vision
through the ChatGoogleGenerativeAI
class.
pip install -U langchain-google-genai
Configure your API key.
export GOOGLE_API_KEY=your-api-key
from langchain_google_genai import ChatGoogleGenerativeAI
llm = ChatGoogleGenerativeAI(model="gemini-pro")
llm.invoke("Sing a ballad of LangChain.")
Gemini vision model supports image inputs when providing a single chat message.
from langchain_core.messages import HumanMessage
from langchain_google_genai import ChatGoogleGenerativeAI
llm = ChatGoogleGenerativeAI(model="gemini-pro-vision")
message = HumanMessage(
content=[
{
"type": "text",
"text": "What's in this image?",
}, # You can optionally provide text parts
{"type": "image_url", "image_url": "https://picsum.photos/seed/picsum/200/300"},
]
)
llm.invoke([message])
The value of image_url can be any of the following:
- A public image URL
- A gcs file (e.g., "gcs://path/to/file.png")
- A local file path
- A base64 encoded image (e.g., data:image/png;base64,abcd124)
- A PIL image
Vertex AI
Access chat models like Gemini
via Google Cloud.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
See a usage example.
from langchain_google_vertexai import ChatVertexAI
Anthropic on Vertex AI Model Garden
See a usage example.
from langchain_google_vertexai.model_garden import ChatAnthropicVertex
Llama on Vertex AI Model Garden
from langchain_google_vertexai.model_garden_maas.llama import VertexModelGardenLlama
Mistral on Vertex AI Model Garden
from langchain_google_vertexai.model_garden_maas.mistral import VertexModelGardenMistral
Gemma local from Hugging Face
Local
Gemma
model loaded fromHuggingFace
.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaChatLocalHF
Gemma local from Kaggle
Local
Gemma
model loaded fromKaggle
.
We need to install langchain-google-vertexai
python package.
pip install langchain-google-vertexai
from langchain_google_vertexai.gemma import GemmaChatLocalKaggle