From e79be7e10591e5dd391a0000ef6a3ece79b35221 Mon Sep 17 00:00:00 2001 From: Bagatur Date: Mon, 23 Sep 2024 12:19:26 -0700 Subject: [PATCH 1/3] groq[patch]: set api key attr --- libs/langchain-groq/src/chat_models.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/langchain-groq/src/chat_models.ts b/libs/langchain-groq/src/chat_models.ts index 524782a6e49e..49bba333c6de 100644 --- a/libs/langchain-groq/src/chat_models.ts +++ b/libs/langchain-groq/src/chat_models.ts @@ -660,6 +660,8 @@ export class ChatGroq extends BaseChatModel< streaming = false; + apiKey?: string; + static lc_name() { return "ChatGroq"; } @@ -690,6 +692,7 @@ export class ChatGroq extends BaseChatModel< apiKey, dangerouslyAllowBrowser: true, }); + this.apiKey = apiKey; this.temperature = fields?.temperature ?? this.temperature; this.modelName = fields?.model ?? fields?.modelName ?? this.model; this.model = this.modelName; From 3b00f592a3f5d1a1a18cb017cb5cd0b97522a049 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Mon, 23 Sep 2024 13:07:43 -0700 Subject: [PATCH 2/3] Add test --- libs/langchain-groq/src/tests/chat_models.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libs/langchain-groq/src/tests/chat_models.test.ts b/libs/langchain-groq/src/tests/chat_models.test.ts index b1ed1988d647..f27ce4cb6bf3 100644 --- a/libs/langchain-groq/src/tests/chat_models.test.ts +++ b/libs/langchain-groq/src/tests/chat_models.test.ts @@ -10,3 +10,10 @@ test("Serialization", () => { `{"lc":1,"type":"constructor","id":["langchain","chat_models","groq","ChatGroq"],"kwargs":{"api_key":{"lc":1,"type":"secret","id":["GROQ_API_KEY"]}}}` ); }); + +test("Serialization with no params", () => { + const model = new ChatGroq(); + expect(JSON.stringify(model)).toEqual( + `{"lc":1,"type":"constructor","id":["langchain","chat_models","groq","ChatGroq"],"kwargs":{"api_key":{"lc":1,"type":"secret","id":["GROQ_API_KEY"]}}}` + ); +}); From b839bf4932adecb226b4c6d19ed1104b84f5c023 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Mon, 23 Sep 2024 13:26:14 -0700 Subject: [PATCH 3/3] Fix --- libs/langchain-groq/src/tests/chat_models.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/langchain-groq/src/tests/chat_models.test.ts b/libs/langchain-groq/src/tests/chat_models.test.ts index f27ce4cb6bf3..8f6b06f13edb 100644 --- a/libs/langchain-groq/src/tests/chat_models.test.ts +++ b/libs/langchain-groq/src/tests/chat_models.test.ts @@ -12,6 +12,7 @@ test("Serialization", () => { }); test("Serialization with no params", () => { + process.env.GROQ_API_KEY = "foo"; const model = new ChatGroq(); expect(JSON.stringify(model)).toEqual( `{"lc":1,"type":"constructor","id":["langchain","chat_models","groq","ChatGroq"],"kwargs":{"api_key":{"lc":1,"type":"secret","id":["GROQ_API_KEY"]}}}`