This code above need to call both addition and multiplication but instead calling only multiplication.I also tried with various tools and functions.But only one tool is getting invoked.
Ok now i get.Its not possible for the llm to make the multiple tool call because of the query contains only 3 params and it will not calculate the result of first part and apply it in second part
But consider query = “what is 2 multiplied to 3 and what is 5 added to 4”
content=‘The tool calls for these operations can be made in parallel as follows:\n\njson\n[\n {\n "function": "functions.multiply",\n "args": {\n "a": 2,\n "b": 3\n },\n "instance": "1"\n },\n {\n "function": "functions.add",\n "args": {\n "a": 5,\n "b": 4\n },\n "instance": "2"\n }\n]\n\n\nIn this case, the “multiply” tool call is used to multiply 2 and 3, and the “add” tool call is used to add 5 and 4. These calls are made in parallel, indicated by the different instance numbers.’ response_metadata={‘finish_reason’: ‘stop’, ‘model_name’: ‘gpt-4-32k’} id=‘run-f80b3be2-7be1-429f-8c79-64cc8473a982-0’
well, you could just parse that, no? but you may need to specifically instruct the model to actually call the tools/functions at the end of the thinking if you’re set on using functions.
thank you for your suggestion but i just wanted to try the code on langchain but still not able to get the output as it is given in the documentation in langchain.
from langchain_core.tools import tool
@tool
def add(a: int, b: int) → int:
“”"Adds a and b.
Args:
a: first int
b: second int
"""
return a + b
@tool
def multiply(a: int, b: int) → int:
“”"Multiplies a and b.
Yeah frameworks like langchain can actually make tasks more complicated - stick to first principles and write stuff yourself with just a bare bones client library?
Consider using a (safe) language interpreter instead, e.g a local process that can safely evaluate JavaScript, python or Ruby expressions in a sandbox, giving the LLM more flexibility to perform this in one shot.
I understand that it can be done using the single tool “Calculate”.But i want it to be done using multi-tools(add and multiply) .Iam trying this to learn about multi-tool calling.