本页还没有译文
本页 36 段还没译成简体中文,下面显示的是英文原文。ChatVertexAI integration
还没翻译译自英文(docs.langchain.com)本页 36 段都还没译
Danger
Deprecated
This integration is deprecated and will be removed in a future release. Please use ChatGoogleGenerativeAI instead. See the full release notes and migration guide.
Gemini Enterprise Agent Platform exposes all foundational models available in Google Cloud, like gemini-3.1-pro-preview, gemini-3.7-flash, etc. For a full and updated list of available models visit Gemini Enterprise Agent Platform documentation.
Info
Gemini Enterprise Agent Platform vs. Gemini API
The Gemini Enterprise Agent Platform integration is separate from the Google Gemini API. This page showcases an enterprise version of Gemini through Google Cloud Platform (GCP).
Tip
API Reference
For detailed documentation of all features and configuration options, head to the ChatVertexAI API reference.
Overview
Integration details
| Class | Package | Serializable | JS support | Downloads | Version |
|---|---|---|---|---|---|
ChatVertexAI | langchain-google-vertexai | beta | ✅ |
Model features
| Tool calling | Structured output | Image input | Audio input | Video input | Token-level streaming | Native async | Token usage | Logprobs |
|---|---|---|---|---|---|---|---|---|
| ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Setup
To access Gemini Enterprise Agent Platform models you'll need to create a Google Cloud Platform account, set up credentials, and install the langchain-google-vertexai integration package.
Credentials
To use the integration you must either:
- Have credentials configured for your environment (gcloud, workload identity, etc...)
- Store the path to a service account JSON file as the
GOOGLE_APPLICATION_CREDENTIALSenvironment 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 the google.auth API reference.
To enable automated tracing of your model calls, set your LangSmith API key:
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
os.environ["LANGSMITH_TRACING"] = "true"Installation
The LangChain Gemini Enterprise Agent Platform integration lives in the langchain-google-vertexai package:
pip install -qU langchain-google-vertexaiInstantiation
Now we can instantiate our model object and generate chat completions:
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(
model="gemini-3.7-flash",
temperature=0,
max_tokens=None,
max_retries=6,
stop=None,
# other params...
)Invocation
messages = [
(
"system",
"You are a helpful assistant that translates English to French. Translate the user sentence.",
),
("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msgAIMessage(content="J'adore programmer. \n", response_metadata={'is_blocked': False, 'safety_ratings': [{'category': 'HARM_CATEGORY_HATE_SPEECH', 'probability_label': 'NEGLIGIBLE', 'blocked': False}, {'category': 'HARM_CATEGORY_DANGEROUS_CONTENT', 'probability_label': 'NEGLIGIBLE', 'blocked': False}, {'category': 'HARM_CATEGORY_HARASSMENT', 'probability_label': 'NEGLIGIBLE', 'blocked': False}, {'category': 'HARM_CATEGORY_SEXUALLY_EXPLICIT', 'probability_label': 'NEGLIGIBLE', 'blocked': False}], 'usage_metadata': {'prompt_token_count': 20, 'candidates_token_count': 7, 'total_token_count': 27}}, id='run-7032733c-d05c-4f0c-a17a-6c575fdd1ae0-0', usage_metadata={'input_tokens': 20, 'output_tokens': 7, 'total_tokens': 27})print(ai_msg.content)J'adore programmer.Built-in tools
Gemini supports a range of tools that are executed server-side.
Google search
Info
Requires langchain-google-vertexai>=2.0.11
Gemini can execute a Google search and use the results to ground its responses:
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model="gemini-3.7-flash").bind_tools([{"google_search": {}}])
response = llm.invoke("What is today's news?")Code execution
Info
Requires langchain-google-vertexai>=2.0.25
Gemini can generate and execute Python code:
from langchain_google_vertexai import ChatVertexAI
llm = ChatVertexAI(model="gemini-3.7-flash").bind_tools([{"code_execution": {}}])
response = llm.invoke("What is 3^3?")API reference
For detailed documentation of all features and configuration options, head to the ChatVertexAI API reference.