From eddce89e556366f1a3b781e75054d039f4f0e62c Mon Sep 17 00:00:00 2001 From: Tanya Sharma Date: Mon, 15 Apr 2024 23:43:06 +0530 Subject: [PATCH 1/9] adding client-info --- libs/langchain-google-common/src/connection.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libs/langchain-google-common/src/connection.ts b/libs/langchain-google-common/src/connection.ts index 7469326af3e4..942447d848d6 100644 --- a/libs/langchain-google-common/src/connection.ts +++ b/libs/langchain-google-common/src/connection.ts @@ -53,11 +53,28 @@ export abstract class GoogleConnection< async _clientInfoHeaders(): Promise> { const clientLibraryVersion = await this._clientLibraryVersion(); + const clientInfo= await this._getclientInfo(); return { "User-Agent": clientLibraryVersion, + "Client-Info": clientInfo.toString(), }; } + async _getclientInfo(): Promise> { + const userAgent = await this._clientLibraryVersion(); + const env = await getRuntimeEnvironment(); + const langchainVersion = env?.libraryVersion ?? "0"; + const moduleName = await this._moduleName(); + let clientLibraryVersion = `${langchainVersion}`; + if (moduleName && moduleName.length) { + clientLibraryVersion = `${clientLibraryVersion}-${moduleName}`; + } + return { + "User-Agent": userAgent, + "client_library_version": clientLibraryVersion, + }; + } + async _clientLibraryVersion(): Promise { const env = await getRuntimeEnvironment(); const langchain = env?.library ?? "langchain-js"; From 742f55b27962af250ee8cf29633ee76b2412c2d0 Mon Sep 17 00:00:00 2001 From: Tanya Sharma Date: Tue, 16 Apr 2024 21:26:13 +0530 Subject: [PATCH 2/9] changes based on comments --- .../langchain-google-common/src/connection.ts | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/libs/langchain-google-common/src/connection.ts b/libs/langchain-google-common/src/connection.ts index 942447d848d6..7315045a99da 100644 --- a/libs/langchain-google-common/src/connection.ts +++ b/libs/langchain-google-common/src/connection.ts @@ -52,39 +52,29 @@ export abstract class GoogleConnection< abstract buildMethod(): GoogleAbstractedClientOpsMethod; async _clientInfoHeaders(): Promise> { - const clientLibraryVersion = await this._clientLibraryVersion(); - const clientInfo= await this._getclientInfo(); + const { userAgent, clientLibraryVersion } = await this._getClientInfo(); return { - "User-Agent": clientLibraryVersion, - "Client-Info": clientInfo.toString(), + "User-Agent": userAgent, + "Client-Info": clientLibraryVersion, }; } - async _getclientInfo(): Promise> { - const userAgent = await this._clientLibraryVersion(); - const env = await getRuntimeEnvironment(); - const langchainVersion = env?.libraryVersion ?? "0"; - const moduleName = await this._moduleName(); - let clientLibraryVersion = `${langchainVersion}`; - if (moduleName && moduleName.length) { - clientLibraryVersion = `${clientLibraryVersion}-${moduleName}`; - } - return { - "User-Agent": userAgent, - "client_library_version": clientLibraryVersion, - }; - } - - async _clientLibraryVersion(): Promise { + async _getClientInfo(): Promise<{ + userAgent: string; + clientLibraryVersion: string; + }> { const env = await getRuntimeEnvironment(); const langchain = env?.library ?? "langchain-js"; const langchainVersion = env?.libraryVersion ?? "0"; const moduleName = await this._moduleName(); - let ret = `${langchain}/${langchainVersion}`; + let clientLibraryVersion = `${langchain}/${langchainVersion}`; if (moduleName && moduleName.length) { - ret = `${ret}-${moduleName}`; + clientLibraryVersion = `${clientLibraryVersion}-${moduleName}`; } - return ret; + return { + userAgent: clientLibraryVersion, + clientLibraryVersion: `${langchainVersion}`, + }; } async _moduleName(): Promise { From 1101d4366822c0e3e6f21f2d8e742a837ec708d6 Mon Sep 17 00:00:00 2001 From: Tanya Sharma Date: Thu, 18 Apr 2024 00:48:26 +0530 Subject: [PATCH 3/9] adding version --- libs/langchain-google-common/src/connection.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/langchain-google-common/src/connection.ts b/libs/langchain-google-common/src/connection.ts index 16698eac5916..1bed13b0bdb0 100644 --- a/libs/langchain-google-common/src/connection.ts +++ b/libs/langchain-google-common/src/connection.ts @@ -64,8 +64,9 @@ export abstract class GoogleConnection< clientLibraryVersion: string; }> { const env = await getRuntimeEnvironment(); + const packageJson = require('../package.json'); const langchain = env?.library ?? "langchain-js"; - const langchainVersion = env?.libraryVersion ?? "0"; + const langchainVersion = packageJson.dependencies["@langchain/core"] ?? "0"; const moduleName = await this._moduleName(); let clientLibraryVersion = `${langchain}/${langchainVersion}`; if (moduleName && moduleName.length) { From 5dfe10781b66b9a1931713caae97ebb46a9fdef5 Mon Sep 17 00:00:00 2001 From: Tanya Sharma Date: Thu, 18 Apr 2024 16:45:32 +0530 Subject: [PATCH 4/9] adding test cases --- libs/langchain-google-common/src/tests/chat_models.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/langchain-google-common/src/tests/chat_models.test.ts b/libs/langchain-google-common/src/tests/chat_models.test.ts index bd79dee5cf22..46cb1af8b664 100644 --- a/libs/langchain-google-common/src/tests/chat_models.test.ts +++ b/libs/langchain-google-common/src/tests/chat_models.test.ts @@ -80,9 +80,13 @@ describe("Mock ChatGoogle", () => { await model.invoke(messages); expect(record?.opts?.headers).toHaveProperty("User-Agent"); + expect(record?.opts?.headers).toHaveProperty("Client-Info"); 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.-]+/ + ); }); test("platform default", async () => { From efe43898a74b5c56753a19774788cd6e732e24e1 Mon Sep 17 00:00:00 2001 From: Tanya Sharma Date: Mon, 22 Apr 2024 18:37:39 +0530 Subject: [PATCH 5/9] setting library version as zero --- libs/langchain-google-common/src/connection.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/langchain-google-common/src/connection.ts b/libs/langchain-google-common/src/connection.ts index 1bed13b0bdb0..9db927e0dfee 100644 --- a/libs/langchain-google-common/src/connection.ts +++ b/libs/langchain-google-common/src/connection.ts @@ -63,10 +63,9 @@ export abstract class GoogleConnection< userAgent: string; clientLibraryVersion: string; }> { - const env = await getRuntimeEnvironment(); - const packageJson = require('../package.json'); + const env = await getRuntimeEnvironment(); const langchain = env?.library ?? "langchain-js"; - const langchainVersion = packageJson.dependencies["@langchain/core"] ?? "0"; + const langchainVersion = env?.libraryVersion ?? "0";; // Since we are not getting libraryVersion from env right now, it will always be 0 const moduleName = await this._moduleName(); let clientLibraryVersion = `${langchain}/${langchainVersion}`; if (moduleName && moduleName.length) { From c3f1d164775967bd5b4cc5e272e236c2cd7ef469 Mon Sep 17 00:00:00 2001 From: Tanya Sharma Date: Tue, 23 Apr 2024 00:14:40 +0530 Subject: [PATCH 6/9] test updates --- libs/langchain-google-common/src/connection.ts | 4 ++-- libs/langchain-google-common/src/tests/chat_models.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/langchain-google-common/src/connection.ts b/libs/langchain-google-common/src/connection.ts index 9db927e0dfee..c2053d8c5c34 100644 --- a/libs/langchain-google-common/src/connection.ts +++ b/libs/langchain-google-common/src/connection.ts @@ -65,7 +65,7 @@ export abstract class GoogleConnection< }> { const env = await getRuntimeEnvironment(); const langchain = env?.library ?? "langchain-js"; - const langchainVersion = env?.libraryVersion ?? "0";; // Since we are not getting libraryVersion from env right now, it will always be 0 + const langchainVersion = env?.libraryVersion ?? "0";; const moduleName = await this._moduleName(); let clientLibraryVersion = `${langchain}/${langchainVersion}`; if (moduleName && moduleName.length) { @@ -73,7 +73,7 @@ export abstract class GoogleConnection< } return { userAgent: clientLibraryVersion, - clientLibraryVersion: `${langchainVersion}`, + clientLibraryVersion: `${langchainVersion}-${moduleName}`, }; } diff --git a/libs/langchain-google-common/src/tests/chat_models.test.ts b/libs/langchain-google-common/src/tests/chat_models.test.ts index 46cb1af8b664..d4bcc4c09a2c 100644 --- a/libs/langchain-google-common/src/tests/chat_models.test.ts +++ b/libs/langchain-google-common/src/tests/chat_models.test.ts @@ -85,7 +85,7 @@ describe("Mock ChatGoogle", () => { /langchain-js\/[0-9.]+-ChatConnection/ ); expect(record.opts.headers["Client-Info"]).toMatch( - /langchain-[a-zA-Z0-9.-]+\/[0-9.]+\/[a-zA-Z0-9.-]+/ + /\d+(\.\d+)?-ChatConnection/ // Since we are not getting libraryVersion from env right now, it will always be 0 ); }); From d2e3ac07f439734d3cb4778a0cb55af65de1cb53 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Mon, 22 Apr 2024 12:39:14 -0700 Subject: [PATCH 7/9] Update connection.ts --- libs/langchain-google-common/src/connection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langchain-google-common/src/connection.ts b/libs/langchain-google-common/src/connection.ts index c2053d8c5c34..174bebf65329 100644 --- a/libs/langchain-google-common/src/connection.ts +++ b/libs/langchain-google-common/src/connection.ts @@ -65,7 +65,7 @@ export abstract class GoogleConnection< }> { const env = await getRuntimeEnvironment(); const langchain = env?.library ?? "langchain-js"; - const langchainVersion = env?.libraryVersion ?? "0";; + const langchainVersion = env?.libraryVersion ?? "0"; const moduleName = await this._moduleName(); let clientLibraryVersion = `${langchain}/${langchainVersion}`; if (moduleName && moduleName.length) { From 1329717151210d85ce35237788c69f4a673ffe3b Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Mon, 22 Apr 2024 12:41:17 -0700 Subject: [PATCH 8/9] Update connection.ts --- libs/langchain-google-common/src/connection.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/langchain-google-common/src/connection.ts b/libs/langchain-google-common/src/connection.ts index 174bebf65329..369d492bf40a 100644 --- a/libs/langchain-google-common/src/connection.ts +++ b/libs/langchain-google-common/src/connection.ts @@ -65,7 +65,8 @@ export abstract class GoogleConnection< }> { const env = await getRuntimeEnvironment(); const langchain = env?.library ?? "langchain-js"; - const langchainVersion = env?.libraryVersion ?? "0"; + // TODO: Add an API for getting the current LangChain version + const langchainVersion = "0"; const moduleName = await this._moduleName(); let clientLibraryVersion = `${langchain}/${langchainVersion}`; if (moduleName && moduleName.length) { From aba3b12fa233f1273160de33f02237c3443b7fdd Mon Sep 17 00:00:00 2001 From: Tanya Sharma Date: Tue, 23 Apr 2024 21:42:07 +0530 Subject: [PATCH 9/9] formatting --- libs/langchain-google-common/src/connection.ts | 2 +- libs/langchain-google-common/src/tests/chat_models.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/langchain-google-common/src/connection.ts b/libs/langchain-google-common/src/connection.ts index 369d492bf40a..c1ed77df788c 100644 --- a/libs/langchain-google-common/src/connection.ts +++ b/libs/langchain-google-common/src/connection.ts @@ -63,7 +63,7 @@ export abstract class GoogleConnection< userAgent: string; clientLibraryVersion: string; }> { - const env = await getRuntimeEnvironment(); + const env = await getRuntimeEnvironment(); const langchain = env?.library ?? "langchain-js"; // TODO: Add an API for getting the current LangChain version const langchainVersion = "0"; diff --git a/libs/langchain-google-common/src/tests/chat_models.test.ts b/libs/langchain-google-common/src/tests/chat_models.test.ts index d4bcc4c09a2c..c554525010a9 100644 --- a/libs/langchain-google-common/src/tests/chat_models.test.ts +++ b/libs/langchain-google-common/src/tests/chat_models.test.ts @@ -85,8 +85,8 @@ describe("Mock ChatGoogle", () => { /langchain-js\/[0-9.]+-ChatConnection/ ); expect(record.opts.headers["Client-Info"]).toMatch( - /\d+(\.\d+)?-ChatConnection/ // Since we are not getting libraryVersion from env right now, it will always be 0 - ); + /\d+(\.\d+)?-ChatConnection/ // Since we are not getting libraryVersion from env right now, it will always be 0 + ); }); test("platform default", async () => {