AttributeError: 'ChatGoogleGenerativeAI' object has no attribute 'bind_tools' #19806
-
Checked other resources
Commit to Help
Example Codeimport getpass
import os
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.pydantic_v1 import BaseModel, Field
os.environ["GOOGLE_API_KEY"] = getpass.getpass()
class Multiply(BaseModel):
"""Multiply two integers together."""
a: int = Field(..., description="First integer")
b: int = Field(..., description="Second integer")
llm = ChatGoogleGenerativeAI(model="gemini-pro")
llm_with_tools = llm.bind_tools([Multiply])
llm_with_tools.invoke("what's 3 * 12") DescriptionI was following LangChain docs about Gemini tools, but it tells me that bind_tools does not exist System Infopip install -qU langchain-core langchain-google-genai |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Hey @RicardoRobledo! Nice to see you diving into the depths of LangChain again. How's the coding journey going? Based on the code snippet you provided, it seems like you're trying to use the The If you're trying to bind functions to the Here's an example of how you can use the llm = ChatOpenAI(openai_api_key="xxx",temperature=0.5)
tools = [get_band_packages]
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
system_msg
),
MessagesPlaceholder(variable_name="chat_history"),
("user", "{input}"),
MessagesPlaceholder(variable_name="agent_scratchpad"),
]
)
chat_history = []
functions = [format_tool_to_openai_function(t) for t in tools]
llm_with_tools = llm.bind_functions(functions=functions)
agent = (
{
"input": lambda x: x["input"],
"agent_scratchpad": lambda x: format_to_openai_function_messages(
x["intermediate_steps"]
),
"chat_history": lambda x: x["chat_history"],
}
| prompt
| llm_with_tools
| OpenAIFunctionsAgentOutputParser()
)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
agent_executor.invoke({"input": "xxxxxxx","chat_history":[]}) In this example, the Please try this approach and let me know if it resolves your issue. If you have any further questions or need additional clarification, feel free to ask. Sources
Sources
|
Beta Was this translation helpful? Give feedback.
-
@RicardoRobledo bind_tools() is not (yet) available with |
Beta Was this translation helpful? Give feedback.
-
Awesome, just wanted to be sure that was truly the case. |
Beta Was this translation helpful? Give feedback.
-
Is this still the case? |
Beta Was this translation helpful? Give feedback.
-
This is stilll not there for any of the Gemini models? |
Beta Was this translation helpful? Give feedback.
-
any update for this? |
Beta Was this translation helpful? Give feedback.
@RicardoRobledo bind_tools() is not (yet) available with
ChatGoogleGenerativeAI
. It is available withChatAnthropicExperimental
,ChatCohere
,ChatFireworks
,ChatMistralAI
and of courseChatOpenAI
. Hopefully one of these models would help you in your project.