ibm-granite-community / pm

Granite Community Project Management
0 stars 0 forks source link

Make LangChain bind_tools work with Granite function calling #130

Open adampingel opened 2 months ago

adampingel commented 2 months ago

While using Replicate Granite model via Langchain Langgraph following error is encountered for agent creation

from langchain_community.llms import Replicate from ibm_granite_community.notebook_utils import set_env_var, get_env_var

llm = Replicate ( model = "ibm-granite/granite-20b-code-instruct-8k", model_kwargs={"temperature": 0.3,} )

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

Research agent and node

research_agent = create_agent( llm, [tavily_tool], system_message="You should provide accurate data for the chart_generator to use.", )

fayvor commented 4 weeks ago

Taking a look at this.

fayvor commented 4 weeks ago

It looks like we can just bypass bind_tools if we want to, when using the Granite models (on Replicate or WatsonX). This PR of the Function_Calling recipe just calls invoke() on the WatsonX llm client, using a properly-constructed prompt.

The same thing works for Replicate; I've tested that.