You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ]
Packages not installed (Not Necessarily a Problem)
The following packages were not found:
langgraph
langserve
The text was updated successfully, but these errors were encountered:
dosubotbot
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
@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.
@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.
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
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
Package Information
Packages not installed (Not Necessarily a Problem)
The following packages were not found:
The text was updated successfully, but these errors were encountered: