mirror of
https://github.com/ollama/ollama-python.git
synced 2026-01-13 21:57:16 +08:00
examples: update tools.py to handle type casting from tool arguments (#443)
--------- Co-authored-by: Parth Sareen <parth.sareen@ollama.com>
This commit is contained in:
parent
8d0d0e483d
commit
aec125c773
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user