Update ChatAnthropic
class langchain-anthropic with new function calling features available in Anthropic API
#21871
Replies: 4 comments 10 replies
-
@ccurme It looks like you are the most active developer for langchain-anthropic. Any idea about when this will be implemented? |
Beta Was this translation helpful? Give feedback.
-
Hi @tommasodelorenzo, thanks for the ping on this.
Can you clarify what you mean by vision inputs? If you mean a model calling tools in response to an image input, this should be supported: import base64
from typing import Literal
import httpx
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import HumanMessage
from langchain_core.tools import tool
image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
@tool
def weather_tool(weather: Literal["sunny", "cloudy", "rainy"]) -> None:
"""Describe the weather"""
pass
image_data = base64.b64encode(httpx.get(image_url).content).decode("utf-8")
model = ChatAnthropic(model="claude-3-sonnet-20240229").bind_tools([weather_tool])
message = HumanMessage(
content=[
{"type": "text", "text": "describe the weather in this image"},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": image_data,
},
},
],
)
response = model.invoke([message])
print(response.tool_calls) If you mean processing images as the result of a tool call, there's an open PR for that that should be merged shortly. |
Beta Was this translation helpful? Give feedback.
-
It works for me! |
Beta Was this translation helpful? Give feedback.
-
I have some issues with the current version as well (langchain = "0.2.7", langchain-anthropic = "0.1.20"). I use different models, and when using Anthropic with tool calling, the output of the Is this behaviour expected? I expected that LangChain handles it so that the LLMs are interchangeable. |
Beta Was this translation helpful? Give feedback.
-
Checked
Feature request
Update the
ChatAnthropic
class to work with the newest function calling features. Notably streaming, force tool use and vision inputs.Motivation
Streaming and force tool use were a long waited feature for agents based on tools calling with Anthropic models.
Proposal (If applicable)
I tried setting
default_headers = {"anthropic-beta": "tools-2024-05-16"}
but it does not seem to work.Beta Was this translation helpful? Give feedback.
All reactions