From 6fce3ff7ad302d48bcd205f41aeba623690d15be Mon Sep 17 00:00:00 2001 From: ddbit <33932368+ddbit@users.noreply.github.com> Date: Thu, 13 Feb 2025 12:50:18 +0100 Subject: [PATCH 1/3] Update tools.py to manage numbers instead of concat strings --- examples/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tools.py b/examples/tools.py index 32a20128..9836825b 100644 --- a/examples/tools.py +++ b/examples/tools.py @@ -12,14 +12,14 @@ def add_two_numbers(a: int, b: int) -> int: Returns: int: The sum of the two numbers """ - return a + b + return int(a) + int(b) def subtract_two_numbers(a: int, b: int) -> int: """ Subtract two numbers """ - return a - b + return int(a) - int(b) # Tools can still be manually defined and passed into chat From 6f29dfd5acf96452d749f14f6f0cdfd240c4d9cb Mon Sep 17 00:00:00 2001 From: ddbit <33932368+ddbit@users.noreply.github.com> Date: Fri, 14 Feb 2025 12:43:33 +0100 Subject: [PATCH 2/3] Update tools.py with some more explainatory comments about casting --- examples/tools.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/tools.py b/examples/tools.py index 9836825b..66cb59bc 100644 --- a/examples/tools.py +++ b/examples/tools.py @@ -12,6 +12,9 @@ def add_two_numbers(a: int, b: int) -> int: Returns: int: The sum of the two numbers """ + + # The cast is necessary because LLM tool use doesn't always conform exactly to schema + # E.g. this would prevent "what is 30 + 12" to produce '3012' instead of 42 return int(a) + int(b) @@ -19,6 +22,8 @@ def subtract_two_numbers(a: int, b: int) -> int: """ Subtract two numbers """ + + # The cast is necessary because LLM tool use doesn't always conform exactly to schema return int(a) - int(b) From 3bbabe46612a7e2e8314a1e03d8a2f3d8e4c9136 Mon Sep 17 00:00:00 2001 From: Parth Sareen Date: Fri, 14 Feb 2025 09:49:57 -0800 Subject: [PATCH 3/3] update comments in examples/tools.py --- examples/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tools.py b/examples/tools.py index 66cb59bc..d6f3fcf2 100644 --- a/examples/tools.py +++ b/examples/tools.py @@ -13,7 +13,7 @@ def add_two_numbers(a: int, b: int) -> int: int: The sum of the two numbers """ - # The cast is necessary because LLM tool use doesn't always conform exactly to schema + # The cast is necessary as returned tool call arguments don't always conform exactly to schema # E.g. this would prevent "what is 30 + 12" to produce '3012' instead of 42 return int(a) + int(b) @@ -23,7 +23,7 @@ def subtract_two_numbers(a: int, b: int) -> int: Subtract two numbers """ - # The cast is necessary because LLM tool use doesn't always conform exactly to schema + # The cast is necessary as returned tool call arguments don't always conform exactly to schema return int(a) - int(b)