diff --git a/libs/langchain-cohere/src/chat_models.ts b/libs/langchain-cohere/src/chat_models.ts index eb6887e53dc6..d0dc03703244 100644 --- a/libs/langchain-cohere/src/chat_models.ts +++ b/libs/langchain-cohere/src/chat_models.ts @@ -14,7 +14,6 @@ import { BaseLanguageModelInput, ToolDefinition, isOpenAITool, - type BaseLanguageModelCallOptions, } from "@langchain/core/language_models/base"; import { isStructuredTool } from "@langchain/core/utils/function_calling"; import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager"; @@ -22,6 +21,7 @@ import { type BaseChatModelParams, BaseChatModel, LangSmithParams, + BaseChatModelCallOptions, } from "@langchain/core/language_models/chat_models"; import { ChatGeneration, @@ -84,7 +84,7 @@ interface TokenUsage { } export interface ChatCohereCallOptions - extends BaseLanguageModelCallOptions, + extends BaseChatModelCallOptions, Partial>, Partial>, Pick { @@ -346,6 +346,10 @@ export class ChatCohere< } invocationParams(options: this["ParsedCallOptions"]) { + if (options.tool_choice) { + throw new Error("'tool_choice' call option is not supported by ChatCohere.") + } + const params = { model: this.model, preamble: options.preamble, diff --git a/libs/langchain-community/src/chat_models/bedrock/web.ts b/libs/langchain-community/src/chat_models/bedrock/web.ts index adc42de6bdbf..3aef91ec7da2 100644 --- a/libs/langchain-community/src/chat_models/bedrock/web.ts +++ b/libs/langchain-community/src/chat_models/bedrock/web.ts @@ -378,6 +378,10 @@ export class BedrockChat } override invocationParams(options?: this["ParsedCallOptions"]) { + if (options?.tool_choice) { + throw new Error("'tool_choice' call option is not supported by BedrockChat.") + } + const callOptionTools = formatTools(options?.tools ?? []); return { tools: [...(this._anthropicTools ?? []), ...callOptionTools], diff --git a/libs/langchain-google-common/src/chat_models.ts b/libs/langchain-google-common/src/chat_models.ts index 52a7748f2028..148d844afebf 100644 --- a/libs/langchain-google-common/src/chat_models.ts +++ b/libs/langchain-google-common/src/chat_models.ts @@ -339,6 +339,10 @@ export abstract class ChatGoogleBase * Get the parameters used to invoke the model */ override invocationParams(options?: this["ParsedCallOptions"]) { + if (options?.tool_choice) { + throw new Error(`'tool_choice' call option is not supported by ${this.getName()}.`); + } + return copyAIModelParams(this, options); } diff --git a/libs/langchain-google-common/src/types.ts b/libs/langchain-google-common/src/types.ts index 3fd20669de7c..1d314eb1f5d9 100644 --- a/libs/langchain-google-common/src/types.ts +++ b/libs/langchain-google-common/src/types.ts @@ -1,7 +1,7 @@ import type { BaseLLMParams } from "@langchain/core/language_models/llms"; -import { BaseLanguageModelCallOptions } from "@langchain/core/language_models/base"; import { StructuredToolInterface } from "@langchain/core/tools"; import type { JsonStream } from "./utils/stream.js"; +import type { BaseChatModelCallOptions } from "@langchain/core/language_models/chat_models"; /** * Parameters needed to setup the client connection. @@ -120,7 +120,7 @@ export interface GoogleAIBaseLLMInput GoogleAISafetyParams {} export interface GoogleAIBaseLanguageModelCallOptions - extends BaseLanguageModelCallOptions, + extends BaseChatModelCallOptions, GoogleAIModelRequestParams, GoogleAISafetyParams { /** diff --git a/libs/langchain-google-genai/src/chat_models.ts b/libs/langchain-google-genai/src/chat_models.ts index e9dab61acd86..3b6327951470 100644 --- a/libs/langchain-google-genai/src/chat_models.ts +++ b/libs/langchain-google-genai/src/chat_models.ts @@ -18,12 +18,12 @@ import { ChatGenerationChunk, ChatResult } from "@langchain/core/outputs"; import { getEnvironmentVariable } from "@langchain/core/utils/env"; import { BaseChatModel, - LangSmithParams, + type BaseChatModelCallOptions, + type LangSmithParams, type BaseChatModelParams, } from "@langchain/core/language_models/chat_models"; import { NewTokenIndices } from "@langchain/core/callbacks/base"; import { - BaseLanguageModelCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions, ToolDefinition, @@ -59,7 +59,7 @@ export type BaseMessageExamplePair = { }; export interface GoogleGenerativeAIChatCallOptions - extends BaseLanguageModelCallOptions { + extends BaseChatModelCallOptions { tools?: | StructuredToolInterface[] | GoogleGenerativeAIFunctionDeclarationsTool[]; @@ -364,6 +364,10 @@ export class ChatGoogleGenerativeAI invocationParams( options?: this["ParsedCallOptions"] ): Omit { + if (options?.tool_choice) { + throw new Error("'tool_choice' call option is not supported by ChatGoogleGenerativeAI.") + } + const tools = options?.tools as | GoogleGenerativeAIFunctionDeclarationsTool[] | StructuredToolInterface[]