From aec125c77345b30d53309f5726226b5473159219 Mon Sep 17 00:00:00 2001 From: ddbit <33932368+ddbit@users.noreply.github.com> Date: Fri, 14 Feb 2025 18:50:47 +0100 Subject: [PATCH] examples: update tools.py to handle type casting from tool arguments (#443) --------- Co-authored-by: Parth Sareen --- examples/tools.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/tools.py b/examples/tools.py index 32a2012..d6f3fcf 100644 --- a/examples/tools.py +++ b/examples/tools.py @@ -12,14 +12,19 @@ def add_two_numbers(a: int, b: int) -> int: Returns: int: The sum of the two numbers """ - return a + b + + # 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) def subtract_two_numbers(a: int, b: int) -> int: """ Subtract two numbers """ - return a - b + + # The cast is necessary as returned tool call arguments don't always conform exactly to schema + return int(a) - int(b) # Tools can still be manually defined and passed into chat