Skip to content

Commit aec125c

Browse files
ddbitParthSareen
andauthored
examples: update tools.py to handle type casting from tool arguments (#443)
--------- Co-authored-by: Parth Sareen <[email protected]>
1 parent 8d0d0e4 commit aec125c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

examples/tools.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ def add_two_numbers(a: int, b: int) -> int:
1212
Returns:
1313
int: The sum of the two numbers
1414
"""
15-
return a + b
15+
16+
# The cast is necessary as returned tool call arguments don't always conform exactly to schema
17+
# E.g. this would prevent "what is 30 + 12" to produce '3012' instead of 42
18+
return int(a) + int(b)
1619

1720

1821
def subtract_two_numbers(a: int, b: int) -> int:
1922
"""
2023
Subtract two numbers
2124
"""
22-
return a - b
25+
26+
# The cast is necessary as returned tool call arguments don't always conform exactly to schema
27+
return int(a) - int(b)
2328

2429

2530
# Tools can still be manually defined and passed into chat

0 commit comments

Comments
 (0)