Skip to content

Instantly share code, notes, and snippets.

@jhgaylor
Created April 18, 2025 16:12
Show Gist options
  • Save jhgaylor/eb44d29d8de6bffe36bdef8af02b7d30 to your computer and use it in GitHub Desktop.
Save jhgaylor/eb44d29d8de6bffe36bdef8af02b7d30 to your computer and use it in GitHub Desktop.
a super simple ollama tooling example taken from https://ollama.com/blog/functions-as-tools
import ollama
def add_two_numbers(a: int, b: int) -> int:
"""
Add two numbers
Args:
a: The first integer number
b: The second integer number
Returns:
int: The sum of the two numbers
"""
return a + b
response = ollama.chat(
'llama3.2',
messages=[{'role': 'user', 'content': 'What is 10 + 10?'}],
tools=[add_two_numbers], # Actual function reference
)
available_functions = {
'add_two_numbers': add_two_numbers,
}
for tool in response.message.tool_calls or []:
function_to_call = available_functions.get(tool.function.name)
if function_to_call:
print('Function output:', function_to_call(**tool.function.arguments))
else:
print('Function not found:', tool.function.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment