Skip to content
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

google-common[patch]: adding client-info #5103

Merged
merged 11 commits into from
May 1, 2024

Conversation

tanyaasharma
Copy link
Contributor

Fixes # (issue)

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 15, 2024
Copy link

vercel bot commented Apr 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2024 0:08am
langchainjs-docs ✅ Ready (Inspect) Visit Preview May 1, 2024 0:08am

@dosubot dosubot bot added the auto:improvement Medium size change to existing code to handle new use-cases label Apr 15, 2024
@@ -53,11 +53,28 @@ export abstract class GoogleConnection<

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey team, just wanted to flag the recent change in the PR for your review. The added _getclientInfo function calls getRuntimeEnvironment, which is expected to access or read environment variables or configuration related to the runtime environment. Please take a look and ensure everything is handled correctly. Thanks!

return {
"User-Agent": clientLibraryVersion,
"Client-Info": clientInfo.toString(),

This comment was marked as resolved.

};
}

async _getclientInfo(): Promise<Record<string, string>> {

This comment was marked as resolved.

async _getclientInfo(): Promise<Record<string, string>> {
const userAgent = await this._clientLibraryVersion();
const env = await getRuntimeEnvironment();
const langchainVersion = env?.libraryVersion ?? "0";

This comment was marked as resolved.

async _getclientInfo(): Promise<Record<string, string>> {
const userAgent = await this._clientLibraryVersion();
const env = await getRuntimeEnvironment();
const langchainVersion = env?.libraryVersion ?? "0";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let's be aware that this is currently always "0" because getRuntimeEnvironment() doesn't currently set libraryVersion. (Because this is difficult to do in non-node environments.)

@afirstenberg
Copy link
Contributor

afirstenberg commented Apr 15, 2024

I don't know what the format of Client-Info is supposed to be (is it a standard HTTP header? I can't find a reference if so), but it almost certainly isn't the output toString() provides.

See other inline notes.

Might also be good to have a test to make sure these are in the format expected. See the test in llms.test.ts called "user agent header"

const env = await getRuntimeEnvironment();
const langchainVersion = env?.libraryVersion ?? "0";
const moduleName = await this._moduleName();
let clientLibraryVersion = `${langchainVersion}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I unfortunately don't think this does what you think it does :( we don't currently have a way to extract version at runtime.

@afirstenberg
Copy link
Contributor

I think it looks better after these updates.

Remaining thoughts:

  • As @jacoblee93 and I observed - env?.libraryVersion is undefined at the moment. So this new header may not be giving you what you think. What are you expecting it to be?
  • Run the tests in "chat_models.test.ts", particularly the "user agent header" test to make sure it still passes.
  • Add another test to "chat_models.test.ts" to test the expected outcomes from the Client-Info header.

@jacoblee93
Copy link
Collaborator

Agree with @afirstenberg's comments above - the libraryVersion check looks like an oversight in first place. Could you verify this is doing what you expect?

@@ -64,8 +64,9 @@ export abstract class GoogleConnection<
clientLibraryVersion: string;
}> {
const env = await getRuntimeEnvironment();
const packageJson = require('../package.json');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've discussed this with @jacoblee93 before (who can correct me if I mis-state something).
Unfortunately, while this works in Node, it doesn't work in all environments. Otherwise it would have been done in getRuntimeEnvironment() (which would be the best place to fix it, so it is available to all packages).

require itself is node-specific, but it isn't the only problem here.

@tanyaasharma
Copy link
Contributor Author

Hi @afirstenberg @jacoblee93 ,
I was researching through langchain documentations in order to understand how to get langchain version in the runtime. Unfortunately i am not able to find the same in the docs and in API reference portal here https://api.js.langchain.com/.

For now, i think we can make this hardcoded as we have mentioned in the package.json. Any thoughts?

@jacoblee93 jacoblee93 reopened this Apr 18, 2024
@jacoblee93
Copy link
Collaborator

jacoblee93 commented Apr 18, 2024

The package.json file isn't accessible at runtime (to my knowledge) since it's not exported.

We would want to add some new file with a version string that is auto-updated during our release flow.

It's been on the roadmap for a while!

@holtskinner
Copy link

Hi, I did the original implementation for this tracking in the Python LangChain library. If it's not possible to get the version number for the LangChain JS library, then I think it's fine to just put zeroes in place. This was arbitrarily added by me just so we could track it if it's useful.

@tanyaasharma
Copy link
Contributor Author

tanyaasharma commented Apr 22, 2024

Sure, @holtskinner , I will put it as zero.Thanks a lot for your response.

expect(record.opts.headers["User-Agent"]).toMatch(
/langchain-js\/[0-9.]+-ChatConnection/
);
expect(record.opts.headers["Client-Info"]).toMatch(
/langchain-[a-zA-Z0-9.-]+\/[0-9.]+\/[a-zA-Z0-9.-]+/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the test fails.

const langchain = env?.library ?? "langchain-js";
const langchainVersion = env?.libraryVersion ?? "0";
const langchainVersion = env?.libraryVersion ?? "0";;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run yarn format

@jacoblee93
Copy link
Collaborator

I'm just going to hardcode this to 0 rather than rely on a non-existent parameter.

@afirstenberg
Copy link
Contributor

I'm just going to hardcode this to 0 rather than rely on a non-existent parameter.

I would have said to keep it as env?.libraryVersion ?? "0".
RuntimeEnvironment.libraryVersion is a valid parameter of that type as returned by getRuntimeEnvironment(), so it might be set some day. {:
And the test will catch it if so.

But I'm at the point where it clearly doesn't matter.
LGTM

@tanyaasharma
Copy link
Contributor Author

@jacoblee93 , I have added formatting too, is there anything else I should add or its good to go?

Copy link
Collaborator

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for being patient with us. Will get this merged and included in the next @langchain/google-common release. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases lgtm PRs that are ready to be merged as-is size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants