-
Checked other resources
Commit to Help
Example CodeI did see LLMs are slightly different in addition, multiplications or some basic calc function. I am looking this code. Instead of I building one by one, do we have any pre built tools?
https://python.langchain.com/docs/how_to/custom_tools/ DescriptionI noticed that LLMs have slight differences in performing basic calculations like addition and multiplication. I'm looking for some code to handle this. Instead of building these functions one by one, do we have any pre-built tools available? System InfoName: langchain |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, LangChain provides pre-built tools for handling basic calculations like addition and multiplication. You can use the from langchain_core.tools import tool
@tool
def multiply(first_int: int, second_int: int) -> int:
"""Multiply two integers together."""
return first_int * second_int Similarly, an @tool
def add(first_int: int, second_int: int) -> int:
"Add two integers."
return first_int + second_int These tools can be used in chains or agents to perform calculations as part of a larger workflow. Additionally, LangChain supports tool/function calling, allowing a model to respond to a given prompt by generating output that matches a user-defined schema. This feature can be used to bind these tools with a model, enabling the model to call the appropriate tool based on the input query [1][2][3]. |
Beta Was this translation helpful? Give feedback.
Yes, LangChain provides pre-built tools for handling basic calculations like addition and multiplication. You can use the
@tool
decorator to create tools for these operations. For example, themultiply
tool is defined as follows:Similarly, an
add
tool is defined for addition:These tools can be used in chains or agents to perform calculations as part of a larger workflow. Additionally, LangChain supports…