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; diff --git a/libs/langchain-groq/src/tests/chat_models.test.ts b/libs/langchain-groq/src/tests/chat_models.test.ts index b1ed1988d647..8f6b06f13edb 100644 --- a/libs/langchain-groq/src/tests/chat_models.test.ts +++ b/libs/langchain-groq/src/tests/chat_models.test.ts @@ -10,3 +10,11 @@ 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", () => { + 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"]}}}` + ); +});