A complementary library to ollama-python to register your tools
Project description
ollama-tool-register
A simple library to register your python functions as tools to be used by supported Ollama LLM models.
Status
This is a hobby project for now, consider all the interfaces to be alpha quality and subject to backwards breaking change until version 1.0.
Pull Requests welcome - use ruff check && ruff format tools and add/run tests with pytest.
Todos
- more functionality, as I discover needs in my own use
- more tests, more developer setup docs if others show interest
Table of Contents
Installation
pip install ollama-tool-register
Example
@ollama.annotated_tool
def some_tool_function(
expr_1: t.Annotated[str, "first simple str value"],
expr_2: t.Annotated[str, "second simple str value"],
req_int_arg: t.Annotated[int, "a required integer"],
req_float_arg: t.Annotated[float, "any real number"],
req_list_arg_1: t.Annotated[list, "any builtin list"],
req_list_arg_2: t.Annotated[t.List[t.Any], "any typed List"],
req_enum_1: t.Annotated[ExampleEnum, "required foo bar or baz"],
opt_arg_1: t.Annotated[t.Optional[str], "an optional string"] = None,
opt_enum_1: t.Annotated[t.Optional[ExampleEnum], "optional foo bar or baz"] = None,
opt_enum_2: ExampleEnum = ExampleEnum.FOO,
opt_builtin_str_1: str = "foobar",
opt_builtin_int_1: int = 1e6,
opt_builtin_float_1: float = 1.0,
opt_builtin_list_1: list = None,
):
"""a test case for Annotating a tool function's parameters.
the docstring of the function is the Function.description."""
return None
The above some_tool_function.tool_schema would provide this, usable as an item in Ollama Python's tools= list
{
"type": "function",
"function": {
"name": "example_1",
"description": "a test case for Annotating a tool function's parameters.\n the docstring of the function is the Function.description.",
"parameters": {
"type": "object",
"required": [
"expr_2",
"expr_1",
"req_int_arg",
"req_list_arg_2",
"req_enum_1",
"req_float_arg",
"req_list_arg_1"
],
"properties": {
"expr_1": {
"type": "string",
"description": "first simple str value",
"is_optional": false,
"enum": null
},
"expr_2": {
"type": "string",
"description": "second simple str value",
"is_optional": false,
"enum": null
},
"req_int_arg": {
"type": "integer",
"description": "a required integer",
"is_optional": false,
"enum": null
},
"req_float_arg": {
"type": "number",
"description": "any real number",
"is_optional": false,
"enum": null
},
"req_list_arg_1": {
"type": "array",
"description": "any builtin list",
"is_optional": false,
"enum": null
},
"req_list_arg_2": {
"type": "array",
"description": "any typed List",
"is_optional": false,
"enum": null
},
"req_enum_1": {
"type": "string",
"description": "required foo bar or baz",
"is_optional": false,
"enum": [
"foo",
"bar",
"baz"
]
},
"opt_arg_1": {
"type": "string",
"description": "an optional string",
"is_optional": true,
"enum": null
},
"opt_enum_1": {
"type": "string",
"description": "optional foo bar or baz",
"is_optional": true,
"enum": [
"foo",
"bar",
"baz"
]
},
"opt_enum_2": {
"type": "string",
"description": "opt enum 2",
"is_optional": true,
"enum": [
"foo",
"bar",
"baz"
]
},
"opt_builtin_str_1": {
"type": "string",
"description": "opt builtin str 1",
"is_optional": true,
"enum": null
},
"opt_builtin_int_1": {
"type": "integer",
"description": "opt builtin int 1",
"is_optional": true,
"enum": null
},
"opt_builtin_float_1": {
"type": "number",
"description": "opt builtin float 1",
"is_optional": true,
"enum": null
},
"opt_builtin_list_1": {
"type": "array",
"description": "opt builtin list 1",
"is_optional": true,
"enum": null
}
}
}
}
}
License
ollama-tool-register is distributed under the terms of the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ollama_tool_register-0.0.1.tar.gz.
File metadata
- Download URL: ollama_tool_register-0.0.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31faa18f470e387d62a05ffe7a8f4d46ff49f9cd8adc35cf50417be5b1866644
|
|
| MD5 |
6d2f405fc5ea4e64340e047a7e9366e2
|
|
| BLAKE2b-256 |
1d6226e89d82ac7c268e2da35c3c22f26caac87b0f36628ae93c6bbb5a43bd43
|
File details
Details for the file ollama_tool_register-0.0.1-py3-none-any.whl.
File metadata
- Download URL: ollama_tool_register-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f12c44668caa9ce514e95fcd41aa80496fcc51ce766645c95746eecad9abf0b
|
|
| MD5 |
c89a02f23e60a2532460c027afc6eb60
|
|
| BLAKE2b-256 |
9b1ef49749b95d45e13b2ea13e68b77b1cefc3d44aa8342c081a7166ad10bf57
|