- Create dedicated _tools.py module for better organization
- Move tool-related functions from _utils.py to _tools.py (not including create_function_tool)
- Rename tool getter functions for clarity:
* get_ollama_tools_name
* get_ollama_tools
* get_ollama_name_async_tools
- Add get_ollama_tool_description for enhanced AI context extraction (it returns a list with name and description, useful for adding to the "content" of the system)
- Fix wrapper function metadata preservation using functools.wraps
- Fix tool registration and lookup bugs found in tests
- Add comprehensive test suite in test_tools.py
- Improve code organization and modularity
- Add proper docstring handling for tool descriptions
This change improves the overall architecture of the tools system
and adds better support for AI context understanding through
proper function metadata and descriptions.
This commit introduces decorators and helper functions to simplify the process of defining and registering synchronous and asynchronous tools in the ollama-python library.
Main changes: - Added `@ollama_tool` and `@ollama_async_tool` decorators to `ollama/_utils.py` to automatically register functions as tools.
New helper functions in `ollama/_utils.py`: - `get_tools()`: Returns a list of all registered tools (synchronous and asynchronous). - `get_tools_name()`: Returns a dictionary mapping tool names to their respective functions.
- `get_name_async_tools()`: Returns an array of asynchronous tool names.
- `ollama/__init__.py` has been updated to export the new decorators and functions.
- `examples/tools.py` has been updated to reflect the changes and simplify the example usage of manually defined tools.
- New example files have been created:
- `examples/tools-decorators.py`: Demonstrates the use of decorators for synchronous and asynchronous tools in a synchronous context.
- `examples/async-tools-decorators.py`: Demonstrates the use of decorators in an asynchronous context with `asyncio`.
- Tests have been added to `tests/test_utils.py` to cover the new decorators and helper functions (`test_tool_and_async_tool_registration`, `test_get_tools_name_and_get_tools`).
These changes aim to make it easier for developers to integrate custom functionality with ollama, reducing the need for boilerplate to define and manage tools.