Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ChatOllama' object has no attribute 'bind_tools' #20439

Open
5 tasks done
natecard opened this issue Apr 14, 2024 · 5 comments
Open
5 tasks done

'ChatOllama' object has no attribute 'bind_tools' #20439

natecard opened this issue Apr 14, 2024 · 5 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: models Related to LLMs or chat model modules

Comments

@natecard
Copy link

natecard commented Apr 14, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from dotenv import load_dotenv
from langchain_community.chat_models import ChatOllama
from langchain_community.tools import DuckDuckGoSearchRun
from langchain_community.utilities import DuckDuckGoSearchAPIWrapper
from transformers import AutoTokenizer
from langchain.tools import Tool

load_dotenv()
hf_token = os.environ.get("HF_TOKEN")
llm = ChatOllama(model="qwen:14b")
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen1.5-14B", token=hf_token)
search_wrapper = DuckDuckGoSearchAPIWrapper(region="en-us", max_results=5)
# Set up the DuckDuckGo search tool
search_tool = DuckDuckGoSearchRun(verbose=True, api_wrapper=search_wrapper)

# Set up the search tools list
search_tools = [
    Tool(
        name="Search",
        func=search_tool.run,
        description="Use the DuckDuckGo search engine to find information",
    ),
]

llm_with_tools = llm.bind_tools(tools=search_tools)

Error Message and Stack Trace (if applicable)

AttributeError                            Traceback (most recent call last)
Cell In[1], [line 26](vscode-notebook-cell:?execution_count=1&line=26)
     [17](vscode-notebook-cell:?execution_count=1&line=17) # Set up the search tools list
     [18](vscode-notebook-cell:?execution_count=1&line=18) search_tools = [
     [19](vscode-notebook-cell:?execution_count=1&line=19)     Tool(
     [20](vscode-notebook-cell:?execution_count=1&line=20)         name="Search",
   (...)
     [23](vscode-notebook-cell:?execution_count=1&line=23)     ),
     [24](vscode-notebook-cell:?execution_count=1&line=24) ]
---> [26](vscode-notebook-cell:?execution_count=1&line=26) llm_with_tools = llm.bind_tools(tools=search_tools)

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

Description

In the docs for ChatOllama it says there is the method bind_tools() here. When I attempt to run the Ollama instance and bind the search tool it throws the AttributeError saying it has no attribute 'bind_tools'

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
Python Version: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:54:21) [Clang 16.0.6 ]

Package Information

langchain_core: 0.1.40
langchain: 0.1.14
langchain_community: 0.0.31
langsmith: 0.1.38
langchain_experimental: 0.0.56
langchain_text_splitters: 0.0.1

Packages not installed (Not Necessarily a Problem)

The following packages were not found:

langgraph
langserve

@dosubot dosubot bot added Ɑ: models Related to LLMs or chat model modules 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Apr 14, 2024
@liugddx
Copy link
Contributor

liugddx commented Apr 15, 2024

You can refer to this
https://python.langchain.com/docs/integrations/chat/

@sepiatone
Copy link
Contributor

@natecard The documentation is out of sync with the code.
The addition of the the bind_tools interface (#20360) to the BaseChatModel (which ChatOllama subclasses) was merged after the last release of langchain-core (#20332). With the next release of langchain-core you should see a slightly more informative "Not Implemented" message.

All of which is to say that please check the page sent by @liugddx - hopefully one of the models that supports the bind_tools interface right now is available to you and can be used in your project.

@lalanikarim
Copy link
Contributor

@natecard ChatOllama or its underlying base class _OllamaCommon don't yet implement bind_tools.
While implementing this function is pretty straight forward, using this code as reference, that alone won't be sufficient for the purposes of tool calling as neither the ChatOllama not the Ollama classes within langchain_community support tool calling directly at this time. There is an implementation within langchain_experimental.llms for OllamaFunctions which is a somewhat outdated implementation of tool calling and needs to be brought up to date if the intent is to use OpenAI style function calling. Worth checking out.

@lalanikarim
Copy link
Contributor

Posted a PR to add bind_tools to OllamaFunctions
#20881

@surya-apty
Copy link

surya-apty commented May 27, 2024

reference for javascript implementation for bindtool? cc @natecard @lalanikarim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: models Related to LLMs or chat model modules
Projects
None yet
Development

No branches or pull requests

5 participants