-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(google): consolidate Google packages into unified @langchain/google package #8393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(google): consolidate Google packages into unified @langchain/google package #8393
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
@hntrl let me know what you think. I am not sure if this diverges from the python package too much. If you are ok with the direction I am happy to finish the PR and update remaining docs to use the consolidated package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My primary concern with this is we're making a lot of assumptions about how this dependency gets bundled. These packages are fractured in the way they are because the underlying dependencies we use (google-auth-library and web-auth-library) are unfortunately written in a way that doesn't make them transferable between environments. I liked the way that you approached the passing of the dependency based on the entrypoint, but I don't know if we can say with 100% certainty that downstream users of the package have a picture-perfect bundling/tree-shaking setup that won't try to include the web specific internal dep for a node build target, for example.
These packages are fractured in the way they are for two reasons:
- We want to make a distinction between AI studio and Vertex AI
- We want to make use of the web & node specific deps provided by google
I know there were some developments within one of the google packages specifically that might give us a path to use them interchangeably between node & web, but that requires further investigation.
Also doing a export * from "@langchain/google";
for backwards compat reasons seems especially heavy handed considering our current build pipeline.
Let me start by saying that I am fully in support of the desire behind this, and bravo @christian-bromann for trying to tackle it (and even getting some of the most recent updates incorporated). Two thoughts replying to @hntrl:
This is a historic split, dating from Google's desire to have two packages. I'm not sure this is relevant anymore. Google's official package (which I do not suggest we switch to) now works for both platforms. I don't know if there are reasons LangChain wishes to keep this distinction (and, if so, then a compatibility layer should be provided anyway, which it is).
To be clear, Google only provides the "google-auth-library". The "web-auth-library" is a 3p library that has issues (see #8132). I think we'd love to simplify this - but we also need to support non-node platforms as well as Google's Application Default Credentials. (@jacoblee93 might remember the exact platforms that we need to make sure this runs on. While we call it "web", it included other platforms where the credentials were available in ways besides a file system.) I need to read the entire PR in detail, but some first thoughts:
|
Consolidate @langchain/google-gauth, @langchain/google-webauth, @langchain/google-vertexai, and @langchain/google-vertexai-web into a single @langchain/google package. - Implement environment-based architecture using environment.ts - Create unified auth system supporting both node and web platforms - Add separate entry points for node.ts and web.ts environments - Migrate comprehensive test suites from all source packages - Support VertexAI, AI Studio, and Google Auth across platforms - Maintain backward compatibility through environment detection - Include chat models, embeddings, LLMs, and media handling This consolidation simplifies the Google ecosystem integration while maintaining full functionality across web and Node.js environments through proper environment abstraction.
bf2748f
to
aa484cd
Compare
@hntrl @afirstenberg thanks for the feedback!
I couldn't find any evidence that would state we could use
What are types of downstream packages? Other Node.js libraries that bundle I certainly agree with the fact that we have to ensure ![]() I am using WebdriverIO to open a browser headlessly and run a prompt from e2e, validating that the LLM actually returns a result and no JavaScript errors were logged in the console. I think there is value in having a set of these real browser tests within the codebase. This is a start.
For more clarity we could check the environment and log a message or throw an error, e.g.: // throw or log error if web package is used in Node.js environment in `@langchain/google/web`
if ('process' in globalThis) { ... }
// throw or log error if Node.js package is used in web environment in `@langchain/google`
if ('window' in globalThis) { ... }
Adding e2e tests validates this for us. Making the following change: diff --git a/libs/langchain-google/e2e/src/App.tsx b/libs/langchain-google/e2e/src/App.tsx
index c8e0196ec..9dc3739a0 100644
--- a/libs/langchain-google/e2e/src/App.tsx
+++ b/libs/langchain-google/e2e/src/App.tsx
@@ -1,5 +1,5 @@
import { useState, useRef } from "react";
-import { ChatGoogle } from "@langchain/google/web";
+import { ChatGoogle } from "@langchain/google";
import "./App.css"; Will throw an error with Vite not being able to transpile the package for the browser.
I am happy to include this within this PR, or raise a separate one. It would be good if we can clearly lay out the differences between |
If we think it's high time to revisit it (especially with the advent of -genai), then yeah I'm all for it! I'm mostly basing my assumptions on surface-level intuition, but I trust your judgement more than mine in this matter honestly.
If I had to guess, it's all the platforms tested in the environment tests
I know we've talked about this in private, but (so we can bring it to the public record) is your chief concern that google might switch up on us again with a new package they release? Are there any endemic blockers that the move to -genai untenable for us?
Not just other libraries, but anyone that has our google packages in their dependencies (users and libraries alike!). Probably the easiest way this setup would raise errors is if someone has
I was referring to support of both environments in -genai, not the auth packages. Allen admittedly has a lot more context than I do on this so I could very well be hallucinating.
Love this! This is probably a good thing to have in every package, but that's probably more trouble than its worth right now. (currently we have very surface level environment tests) We're still testing a picture-perfect bundler setup here technically. I have no doubt that this works under lab conditions, but my gut tells me this won't track across a number of existing setups without difficulty (something I'd like to avoid if at all possible). --
import { GoogleAuth } from "google-auth-library";
import { ChatGoogleGenerativeAI } from "@langchain/google";
const auth = new GoogleAuth(...);
const model = new ChatGoogleGenerativeAI({
fetch: auth.fetch,
...
}); To me that gets rid of the deps that don't work across environments entirely since it's escaping into userland. The underlying assumption is that -genai doesn't try to use google-auth-library as standard |
@christian-bromann says:
That is... a non-advised practice since it would expose credentials in the browser. (Not that people seem to care about this, somehow.) But in this particular case I think @hntrl was talking about the
I wouldn't advise this since I don't think the environments are as clear-cut as this. For people using an API Key currently, the current packages "do the right thing" and don't actually use either of the auth libraries. I wouldn't want to force people to use the /web version because they're using an API Key. (Although yes... we could check if they are and bypass these warnings...)
Two references for this:
But I think, going forward, the objective should be to just have one package, leaving the others (at least for a bit) for backwards compatibility. Which leads me to @hntrl saying:
This might be the platform that I had in mind that was "a server-like environment that was not using node, so had to use the web packages". I haven't used it and don't know details - I was mostly going by vague memories of what Jacob said a year or two ago.
The biggest is that it only supports Vertex AI through google-auth-library. A secondary issue is that it only supports the "Gemini API", which does include support for Gemma on AI Studio. It does not, for example, support Anthropic on Vertex AI (which we do support) or other models on Vertex AI (which... is on my todo list...). And supporting all those ends up tied to the auth issue. And yes, I have reservations about their support for the JavaScript library for Gemini. This is the third (or fourth, depending how you count) library for Bard/Gemini that they've published. And they published it significantly later than their Python library. Other AI products from Google do not have JavaScript libraries at all.
My thinking on this is that the best strategy might be something like:
I don't want to do what Google has done - moved to a completely new package with absolutely no migration path and no warning.
Mostly because we should make the most common operations the simplest. Looking at current usage of the various Google packages, about 50% are using -genai, and thus using API Keys. The other 50% are overwhelmingly using -vertexai, and many of these are probably running on Google Cloud, so no authentication key or configuration in the code is specifically needed at all (this is the Application Default Credentials configuration (ADC), that google-auth-library supports). Only a tiny few use -vertex-web. So requiring additional configuration to run in an ADC environment would defeat the purpose.
I think this is my broad concern as well. We have the list of platforms that @hntrl mentioned in the environment tests, and I think if we're addressing those, my concerns are somewhat mitigated. The term "web" was meant as a generic one - not just to talk about browsers. (And I'll admit and apologize that my concerns are based on vague old memories about why the split was done in the first place.) Bottom Line
|
This PR consolidates the multiple Google-related packages into a single, unified
@langchain/google
package that provides automatic environment detection and simplified usage for both Node.js and web environments.📦 Packages Consolidated
@langchain/google-gauth
@langchain/google-vertexai
@langchain/google-vertexai-web
@langchain/google-webauth
🎯 Key Benefits
🏗️ Technical Implementation
"node" | "web"
)/web
export for browsersgoogle-auth-library
(Node.js) andweb-auth-library
(web)📋 Usage Examples
From a user's perspective, the authentication detection is completely transparent. Users simply import from different entry points and the package automatically handles the environment-specific authentication behind the scenes. The type system is configured to ask for the right type in
authOptions
.📋 Node.js Example
🌐 Web/Browser Example
🔄 Migration Path
No migration required! All existing code continues to work:
🧪 Testing
This change significantly improves the developer experience for Google integrations while maintaining full backward compatibility and reducing maintenance overhead.