@@ -143,16 +143,18 @@ const DEFAULT_FACTORY: ModelFactory = (name, opts) =>
143143
144144export function getChatModel (
145145 modelName : string = DEFAULT_MODEL ,
146- streaming : boolean = false
146+ streaming : boolean = false ,
147+ providerOverride ?: string ,
147148) : BaseChatModel {
148149 const opts : ModelOpts = { streaming } ;
149- const provider = resolveProvider ( modelName ) ;
150+ const provider = resolveProvider ( modelName , providerOverride ) ;
150151 const factory = MODEL_FACTORIES [ provider . id ] ?? DEFAULT_FACTORY ;
151152 return factory ( modelName , opts ) ;
152153}
153154
154155interface CallLlmOptions {
155156 model ?: string ;
157+ modelProvider ?: string ;
156158 systemPrompt ?: string ;
157159 outputSchema ?: z . ZodType < unknown > ;
158160 tools ?: StructuredToolInterface [ ] ;
@@ -213,10 +215,10 @@ function buildAnthropicMessages(systemPrompt: string, userPrompt: string) {
213215}
214216
215217export async function callLlm ( prompt : string , options : CallLlmOptions = { } ) : Promise < LlmResult > {
216- const { model = DEFAULT_MODEL , systemPrompt, outputSchema, tools, signal } = options ;
218+ const { model = DEFAULT_MODEL , modelProvider , systemPrompt, outputSchema, tools, signal } = options ;
217219 const finalSystemPrompt = systemPrompt || DEFAULT_SYSTEM_PROMPT ;
218220
219- const llm = getChatModel ( model , false ) ;
221+ const llm = getChatModel ( model , false , modelProvider ) ;
220222
221223 // eslint-disable-next-line @typescript-eslint/no-explicit-any
222224 let runnable : Runnable < any , any > = llm ;
@@ -228,7 +230,7 @@ export async function callLlm(prompt: string, options: CallLlmOptions = {}): Pro
228230 }
229231
230232 const invokeOpts = signal ? { signal } : undefined ;
231- const provider = resolveProvider ( model ) ;
233+ const provider = resolveProvider ( model , modelProvider ) ;
232234 let result ;
233235
234236 if ( provider . id === 'anthropic' ) {
@@ -287,6 +289,7 @@ function annotateSystemMessageForCaching(messages: BaseMessage[]): BaseMessage[]
287289
288290interface CallLlmWithMessagesOptions {
289291 model ?: string ;
292+ modelProvider ?: string ;
290293 tools ?: StructuredToolInterface [ ] ;
291294 signal ?: AbortSignal ;
292295}
@@ -306,9 +309,9 @@ export async function callLlmWithMessages(
306309 messages : BaseMessage [ ] ,
307310 options : CallLlmWithMessagesOptions = { } ,
308311) : Promise < LlmResult > {
309- const { model = DEFAULT_MODEL , tools, signal } = options ;
312+ const { model = DEFAULT_MODEL , modelProvider , tools, signal } = options ;
310313
311- const llm = getChatModel ( model , false ) ;
314+ const llm = getChatModel ( model , false , modelProvider ) ;
312315
313316 // eslint-disable-next-line @typescript-eslint/no-explicit-any
314317 let runnable : Runnable < any , any > = llm ;
@@ -318,7 +321,7 @@ export async function callLlmWithMessages(
318321 }
319322
320323 const invokeOpts = signal ? { signal } : undefined ;
321- const provider = resolveProvider ( model ) ;
324+ const provider = resolveProvider ( model , modelProvider ) ;
322325
323326 // For Anthropic: annotate SystemMessage with cache_control for prompt caching
324327 const finalMessages = provider . id === 'anthropic'
@@ -349,9 +352,9 @@ export async function* streamLlmWithMessages(
349352 messages : BaseMessage [ ] ,
350353 options : CallLlmWithMessagesOptions = { } ,
351354) : AsyncGenerator < AIMessageChunk , void > {
352- const { model = DEFAULT_MODEL , tools, signal } = options ;
355+ const { model = DEFAULT_MODEL , modelProvider , tools, signal } = options ;
353356
354- const llm = getChatModel ( model , true ) ;
357+ const llm = getChatModel ( model , true , modelProvider ) ;
355358
356359 // eslint-disable-next-line @typescript-eslint/no-explicit-any
357360 let runnable : Runnable < any , any > = llm ;
@@ -361,7 +364,7 @@ export async function* streamLlmWithMessages(
361364 }
362365
363366 const invokeOpts = signal ? { signal } : undefined ;
364- const provider = resolveProvider ( model ) ;
367+ const provider = resolveProvider ( model , modelProvider ) ;
365368
366369 const finalMessages = provider . id === 'anthropic'
367370 ? annotateSystemMessageForCaching ( messages )
0 commit comments