fix(Anthropic Chat Model Node): Fix LmChatAnthropic node to work when both thinking is enabled and tools used (#16010)

This commit is contained in:
Yiorgis Gozadinos
2025-06-05 13:33:51 +02:00
committed by GitHub
parent 0bea193814
commit e662998c67
7 changed files with 177 additions and 141 deletions

View File

@@ -1,4 +1,4 @@
import type { StructuredTool } from '@langchain/core/tools';
import type { Tool } from '@langchain/core/tools';
import type { OpenAIClient } from '@langchain/openai';
import { zodToJsonSchema } from 'zod-to-json-schema';
@@ -6,13 +6,13 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
// since these functions are not exported
/**
* Formats a `StructuredTool` instance into a format that is compatible
* Formats a `Tool` instance into a format that is compatible
* with OpenAI's ChatCompletionFunctions. It uses the `zodToJsonSchema`
* function to convert the schema of the `StructuredTool` into a JSON
* function to convert the schema of the tool into a JSON
* schema, which is then used as the parameters for the OpenAI function.
*/
export function formatToOpenAIFunction(
tool: StructuredTool,
tool: Tool,
): OpenAIClient.Chat.ChatCompletionCreateParams.Function {
return {
name: tool.name,
@@ -21,7 +21,7 @@ export function formatToOpenAIFunction(
};
}
export function formatToOpenAITool(tool: StructuredTool): OpenAIClient.Chat.ChatCompletionTool {
export function formatToOpenAITool(tool: Tool): OpenAIClient.Chat.ChatCompletionTool {
const schema = zodToJsonSchema(tool.schema);
return {
type: 'function',
@@ -33,7 +33,7 @@ export function formatToOpenAITool(tool: StructuredTool): OpenAIClient.Chat.Chat
};
}
export function formatToOpenAIAssistantTool(tool: StructuredTool): OpenAIClient.Beta.AssistantTool {
export function formatToOpenAIAssistantTool(tool: Tool): OpenAIClient.Beta.AssistantTool {
return {
type: 'function',
function: {