langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
92.83k stars 14.88k forks source link

'BedrockChat' object has no attribute 'bind_tools' #19162

Open evandrofranco opened 6 months ago

evandrofranco commented 6 months ago

Checked other resources

Example Code

import boto3
import json
from langchain_community.chat_models import BedrockChat
from langchain.agents import tool
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder

boto3_bedrock = boto3.client('bedrock-runtime')
modelId = "anthropic.claude-3-sonnet-20240229-v1:0"

llm = BedrockChat(
    model_id=modelId, 
    client = boto3_bedrock
)

@tool
def get_word_length(word: str) -> int:
    """Returns the length of a word."""
    return len(word)

#get_word_length.invoke("abc")

tools = [get_word_length]

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "system",
            "You are very powerful assistant, but don't know current events",
        ),
        ("user", "{input}"),
        MessagesPlaceholder(variable_name="agent_scratchpad"),
    ]
)

llm_with_tools = llm.bind_tools(tools)

Error Message and Stack Trace (if applicable)

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[7], line 1
----> 1 llm_with_tools = llm.bind_tools(tools)

AttributeError: 'BedrockChat' object has no attribute 'bind_tools'

Description

I am trying to follow this guide with Bedrock and it's throwing this error.

System Info

langchain==0.1.12 langchain-community==0.0.28 langchain-core==0.1.32 langchain-text-splitters==0.0.1

Zedmor commented 6 months ago

That functionality is simply not implemented. If you will find implementation pleas update this thread.

fmg-tomdifulvio commented 5 months ago

any updates on when/if this is going to be implemented?

Neet-Nestor commented 3 months ago

Any update? Clearly Bedrock API is currently supporting this but LangChain has not updated yet.

Tool Calling

rajidhamon31 commented 2 months ago

I am also facing the same issue, is it updated?

cipher982 commented 2 months ago

I just updated langchain and tried again. It appears tool call are now working with 0.2.6