Closed elie222 closed 6 months ago
Based on the context provided, it seems like there might be a misunderstanding about the bind
method in the ChatAnthropicTools
class. According to the LangChain JS codebase, there is no bind
method in the ChatAnthropicTools
class. This could be the reason why the function call isn't working as expected.
The invoke
method in the ChatAnthropicTools
class is designed to process a message input and generate a response. However, it doesn't inherently support making function calls. Instead, it returns a ChatResult
object that contains plain text content. This could explain why you're seeing plain text content instead of a function call.
The correct way to make function calls using the ChatAnthropicTools
class involves using the invoke
method with a HumanMessage
object that prompts the use of the bound tool. However, in your code, it seems like the tool_choice
argument is being set to force the model to use a specific function. This might not be the correct approach, as the invoke
method doesn't support this functionality.
I recommend revisiting the usage of the ChatAnthropicTools
class and the invoke
method. You might need to adjust your code to align with the expected usage of these components. You can refer to the examples/src/models/chat/anthropic_tools/tool_calling.ts file in the LangChain JS repository for an example of how to use the ChatAnthropicTools
class correctly.
Regarding the issue you found in the LangChain JS repository, it seems to be a different issue that doesn't directly relate to your problem. The issue is about a TypeError when reading properties of undefined in a different part of the codebase.
I hope this helps clarify the situation. If you have any more questions or need further clarification, feel free to ask.
What is the actual logged response?
And could you share the tool schemas?
ChatAnthropicTools is deprecated. Use ChatAnthropic instead. see. https://js.langchain.com/docs/integrations/chat/anthropic/
ChatAnthropicTools is deprecated. Use ChatAnthropic instead. see. js.langchain.com/docs/integrations/chat/anthropic
Thanks. Seems like this also has issues:
Object literal may only specify known properties, and 'tools' does not exist in type 'Partial<BaseLanguageModelCallOptions>'.ts(2353)
Code:
const calculatorSchema = z.object({
operation: z
.enum(["add", "subtract", "multiply", "divide"])
.describe("The type of operation to execute."),
number1: z.number().describe("The first number to operate on."),
number2: z.number().describe("The second number to operate on."),
});
const tool = {
name: "calculator",
description: "A simple calculator tool",
input_schema: zodToJsonSchema(calculatorSchema),
};
const model = new ChatAnthropic({
anthropicApiKey: '',
modelName: "claude-3-haiku-20240307",
}).bind({
tools: [tool],
});
May just be a types issues.
I updated all the dependencies for using new released ChatAnthropic.
Here is mine.
"dependencies": { "@langchain/anthropic": "^0.1.10", "@langchain/community": "^0.0.44", "@langchain/core": "^0.1.54", "@langchain/google-vertexai": "^0.0.2", "langchain": "^0.1.31", "ts-node": "^10.9.2", "zod": "^3.22.4", "zod-to-json-schema": "^3.22.5" }
Working now! Thanks! Think I needed to do a TS restart. Weird because almost certain I did yesterday.
Checked other resources
Example Code
The following code should make a function call but doesn't.
Error Message and Stack Trace (if applicable)
import { ChatAnthropicTools } from "@langchain/anthropic/experimental"; import { HumanMessage } from "@langchain/core/messages"; import { ToolDefinition } from "@langchain/core/language_models/base";
Description
@langchain/anthropic/experimental
to make function calls with LangChaintool_choice
System Info
node v18.19.0 pnpm 8.15.4
"@langchain/anthropic": "^0.1.8", "@langchain/core": "^0.1.48",