@@ -73,50 +73,51 @@ async function _initChatModelHelper(
7373 `Unable to infer model provider for { model: ${ model } }, please specify modelProvider directly.`
7474 ) ;
7575 }
76+ const { modelProvider : _unused , ...passedParams } = params ;
7677
7778 try {
7879 switch ( modelProviderCopy ) {
7980 case "openai" : {
8081 const { ChatOpenAI } = await import ( "@langchain/openai" ) ;
81- return new ChatOpenAI ( { model, ...params } ) ;
82+ return new ChatOpenAI ( { model, ...passedParams } ) ;
8283 }
8384 case "anthropic" : {
8485 const { ChatAnthropic } = await import ( "@langchain/anthropic" ) ;
85- return new ChatAnthropic ( { model, ...params } ) ;
86+ return new ChatAnthropic ( { model, ...passedParams } ) ;
8687 }
8788 case "azure_openai" : {
8889 const { AzureChatOpenAI } = await import ( "@langchain/openai" ) ;
89- return new AzureChatOpenAI ( { model, ...params } ) ;
90+ return new AzureChatOpenAI ( { model, ...passedParams } ) ;
9091 }
9192 case "cohere" : {
9293 const { ChatCohere } = await import ( "@langchain/cohere" ) ;
93- return new ChatCohere ( { model, ...params } ) ;
94+ return new ChatCohere ( { model, ...passedParams } ) ;
9495 }
9596 case "google-vertexai" : {
9697 const { ChatVertexAI } = await import ( "@langchain/google-vertexai" ) ;
97- return new ChatVertexAI ( { model, ...params } ) ;
98+ return new ChatVertexAI ( { model, ...passedParams } ) ;
9899 }
99100 case "google-genai" : {
100101 const { ChatGoogleGenerativeAI } = await import (
101102 "@langchain/google-genai"
102103 ) ;
103- return new ChatGoogleGenerativeAI ( { model, ...params } ) ;
104+ return new ChatGoogleGenerativeAI ( { model, ...passedParams } ) ;
104105 }
105106 case "ollama" : {
106107 const { ChatOllama } = await import ( "@langchain/ollama" ) ;
107- return new ChatOllama ( { model, ...params } ) ;
108+ return new ChatOllama ( { model, ...passedParams } ) ;
108109 }
109110 case "mistralai" : {
110111 const { ChatMistralAI } = await import ( "@langchain/mistralai" ) ;
111- return new ChatMistralAI ( { model, ...params } ) ;
112+ return new ChatMistralAI ( { model, ...passedParams } ) ;
112113 }
113114 case "groq" : {
114115 const { ChatGroq } = await import ( "@langchain/groq" ) ;
115- return new ChatGroq ( { model, ...params } ) ;
116+ return new ChatGroq ( { model, ...passedParams } ) ;
116117 }
117118 case "bedrock" : {
118119 const { ChatBedrockConverse } = await import ( "@langchain/aws" ) ;
119- return new ChatBedrockConverse ( { model, ...params } ) ;
120+ return new ChatBedrockConverse ( { model, ...passedParams } ) ;
120121 }
121122 case "fireworks" : {
122123 const { ChatFireworks } = await import (
@@ -127,7 +128,7 @@ async function _initChatModelHelper(
127128 // @ts -ignore - Can not install as a proper dependency due to circular dependency
128129 "@langchain/community/chat_models/fireworks"
129130 ) ;
130- return new ChatFireworks ( { model, ...params } ) ;
131+ return new ChatFireworks ( { model, ...passedParams } ) ;
131132 }
132133 case "together" : {
133134 const { ChatTogetherAI } = await import (
@@ -138,7 +139,7 @@ async function _initChatModelHelper(
138139 // @ts -ignore - Can not install as a proper dependency due to circular dependency
139140 "@langchain/community/chat_models/togetherai"
140141 ) ;
141- return new ChatTogetherAI ( { model, ...params } ) ;
142+ return new ChatTogetherAI ( { model, ...passedParams } ) ;
142143 }
143144 default : {
144145 const supported = _SUPPORTED_PROVIDERS . join ( ", " ) ;
@@ -247,7 +248,10 @@ class _ConfigurableModel<
247248 if ( fields . configurableFields === "any" ) {
248249 this . _configurableFields = "any" ;
249250 } else {
250- this . _configurableFields = fields . configurableFields ?? "any" ;
251+ this . _configurableFields = fields . configurableFields ?? [
252+ "model" ,
253+ "modelProvider" ,
254+ ] ;
251255 }
252256
253257 if ( fields . configPrefix ) {
@@ -786,12 +790,14 @@ export async function initChatModel<
786790 configPrefix : "" ,
787791 ...( fields ?? { } ) ,
788792 } ;
789- let configurableFieldsCopy = configurableFields ;
793+ let configurableFieldsCopy = Array . isArray ( configurableFields )
794+ ? [ ...configurableFields ]
795+ : configurableFields ;
790796
791- if ( ! model && ! configurableFieldsCopy ) {
797+ if ( ! model && configurableFieldsCopy === undefined ) {
792798 configurableFieldsCopy = [ "model" , "modelProvider" ] ;
793799 }
794- if ( configPrefix && ! configurableFieldsCopy ) {
800+ if ( configPrefix && configurableFieldsCopy === undefined ) {
795801 console . warn (
796802 `{ configPrefix: ${ configPrefix } } has been set but no fields are configurable. Set ` +
797803 `{ configurableFields: [...] } to specify the model params that are ` +
@@ -802,7 +808,7 @@ export async function initChatModel<
802808 // eslint-disable-next-line @typescript-eslint/no-explicit-any
803809 const paramsCopy : Record < string , any > = { ...params } ;
804810
805- if ( ! configurableFieldsCopy ) {
811+ if ( configurableFieldsCopy === undefined ) {
806812 return new _ConfigurableModel < RunInput , CallOptions > ( {
807813 defaultConfig : {
808814 ...paramsCopy ,
0 commit comments