@langchain/google 包提供了与 Google AI Studio 和 Gemini Enterprise Agent Platform 的集成。
查找旧的
@langchain/google-genai 或 @langchain/google-vertexai 包?它们在 长期支持 下进行维护,但不再推荐用于新项目。对话模型
ChatGoogle 类是访问 Gemini 模型(如 gemini-2.5-pro、gemini-2.5-flash 和 gemini-3.1-pro-preview)以及类似 Gemma 的开源模型推荐方式。它通过单一接口支持 Google AI Studio 和 Gemini Enterprise Agent Platform。
ChatGoogle 支持工具调用、结构化输出、多模态输入(图像、音频、视频)、推理/思考、图像生成、文本转语音,以及 Gemini 特定的原生工具,如 Google 搜索基础和代码执行。
ChatGoogle
完整的对话模型文档,包括设置、调用、流式输出、结构化输出等。
Gemini 原生工具
Google 搜索、代码执行、URL 上下文、Google 地图、文件搜索、计算机使用和 MCP 服务器。
Gemini Enterprise Agent Platform 上的第三方模型
Anthropic Claude 模型也通过 Gemini Enterprise Agent Platform 平台提供。有关启用模型访问和使用的模型名称的更多信息,请参阅 在 Gemini Enterprise Agent Platform 上使用 Claude。Postgres 向量存储(Cloud SQL)
PostgresVectorStore 模块来自@langchain/google-cloud-sql-pg 包,提供了使用 CloudSQL for PostgreSQL 存储向量嵌入的方式。
旧版包
以下包为现有用户提供长期支持。新项目应使用@langchain/google。
@langchain/google-genai
@langchain/google-genai 包提供了 ChatGoogleGenerativeAI 和 GoogleGenerativeAIEmbeddings,用于通过 Google AI Studio 访问 Gemini 模型。该包基于已弃用的 Google SDK 构建,将不会获得新功能。
@langchain/google-vertexai
@langchain/google-vertexai 包提供了 ChatVertexAI、VertexAIEmbeddings 和 VertexAI,用于 Node.js 上的 Gemini Enterprise Agent Platform。它依赖于 @langchain/google-gauth 进行身份验证。该包已被 @langchain/google 中为对话构建的 Gemini Enterprise Agent Platform 支持所取代。
@langchain/google-vertexai-web
@langchain/google-vertexai-web 包为浏览器和 Edge 运行时提供了相同的 Gemini Enterprise Agent Platform 对话、嵌入和 LLM 类。在 Web 环境中运行时,请安装此包(而不是 @langchain/google-vertexai)。它依赖于 @langchain/google-webauth。
GOOGLE_WEB_CREDENTIALS 和 Web 导入路径。
@langchain/google-webauth
@langchain/google-webauth 包为旧版 Gemini Enterprise Agent Platform 集成提供了浏览器和 Edge 身份验证。它与 @langchain/google-vertexai-web 自动安装——不要与 @langchain/google-gauth 一起安装。
在 GOOGLE_WEB_CREDENTIALS(或已弃用的 GOOGLE_VERTEX_AI_WEB_CREDENTIALS)中设置服务账户 JSON。您也可以将 apiKey 或 authOptions 传递给模型构造函数,或设置 API_KEY 环境变量。
@langchain/google-gauth
@langchain/google-gauth 包为基于 @langchain/google-common 构建的旧版 Google 集成提供了 Node.js 身份验证。当您添加 @langchain/google-vertexai 时,它会自动安装——通常您不直接安装或导入 @langchain/google-gauth。
在 Node.js 上,凭据按以下顺序解析:
- 传递给模型构造函数的
apiKey - 传递给模型构造函数的
authOptions API_KEY环境变量GOOGLE_APPLICATION_CREDENTIALS路径中的服务账户 JSON- 应用默认凭据(例如在
gcloud auth application-default login之后,或在 Google Cloud 上)
@langchain/google-gauth 和 @langchain/google-webauth。
统一的 @langchain/google 包直接使用 google-auth-library,并且不需要 @langchain/google-gauth 或 @langchain/google-webauth。
@langchain/google-cloud-sql-pg
@langchain/google-cloud-sql-pg 包提供了 PostgresVectorStore 和 PostgresLoader,用于 Cloud SQL for PostgreSQL。它与上面提到的 Gemini 对话包是分开的。
@langchain/google-common
@langchain/google-common 包为旧版集成(如 @langchain/google-vertexai)提供了共享的 Gemini 客户端抽象。它不包括授权代码,并且不是一个独立的包——不要直接安装或导入它。
官方原文:src/oss/javascript/integrations/providers/google.mdx · 非官方翻译,译文由 AI 生成,以英文原文为准。