最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ollama - langchain allways calls tools if it is binded - Stack Overflow

programmeradmin4浏览0评论

I have an ollama server running in background.

Here is my simple python code to test tool calling.

code:

from langchain_ollama import ChatOllama
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_core.messages import HumanMessage
from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent

from langchain.chat_models import init_chat_model
model = init_chat_model("llama3.2:3b", model_provider="ollama")

search = TavilySearchResults(max_results=2)
tools = [search]

model_with_tools = model.bind_tools(tools)
response = model_with_tools.invoke([HumanMessage(content="Hi!")])
print(f"ContentString: {response.content}")
print(f"ToolCalls: {response.tool_calls}")

response:

ContentString: 
ToolCalls: [{'name': 'tavily_search_results_json', 'args': {'query': 'Hi!'}, 'id': '6855ae48-c278-47ee-8637-d6e1c284dfd9', 'type': 'tool_call'}]

I expected a response from the model itself like Hello! It's nice to meet you. Is there something I can help you with or would you like to chat? and an empty [] for the ToolCalls

But unfortunately, the model did not answer me, it just suggested to use the tools (tavily) with 'Hi!' query.

I do not understand why it happened. Can someone explain me what went wrong?

发布评论

评论列表(0)

  1. 暂无评论