opentool-python 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opentool_python-0.1.0/LICENSE +21 -0
- opentool_python-0.1.0/PKG-INFO +180 -0
- opentool_python-0.1.0/README.md +163 -0
- opentool_python-0.1.0/pyproject.toml +30 -0
- opentool_python-0.1.0/setup.cfg +4 -0
- opentool_python-0.1.0/src/opentool_python/__init__.py +62 -0
- opentool_python-0.1.0/src/opentool_python/client/__init__.py +18 -0
- opentool_python-0.1.0/src/opentool_python/client/exceptions.py +48 -0
- opentool_python-0.1.0/src/opentool_python/client/opentool_client.py +238 -0
- opentool_python-0.1.0/src/opentool_python/dto.py +124 -0
- opentool_python-0.1.0/src/opentool_python/json_loader.py +23 -0
- opentool_python-0.1.0/src/opentool_python/llm/__init__.py +3 -0
- opentool_python-0.1.0/src/opentool_python/llm/model.py +35 -0
- opentool_python-0.1.0/src/opentool_python/model/__init__.py +23 -0
- opentool_python-0.1.0/src/opentool_python/model/data_type.py +8 -0
- opentool_python-0.1.0/src/opentool_python/model/function_model.py +66 -0
- opentool_python-0.1.0/src/opentool_python/model/info.py +25 -0
- opentool_python-0.1.0/src/opentool_python/model/opentool.py +59 -0
- opentool_python-0.1.0/src/opentool_python/model/parameter.py +36 -0
- opentool_python-0.1.0/src/opentool_python/model/return_model.py +27 -0
- opentool_python-0.1.0/src/opentool_python/model/schema.py +251 -0
- opentool_python-0.1.0/src/opentool_python/model/server.py +20 -0
- opentool_python-0.1.0/src/opentool_python/opentool_client.py +24 -0
- opentool_python-0.1.0/src/opentool_python/opentool_schema.py +27 -0
- opentool_python-0.1.0/src/opentool_python/opentool_server.py +17 -0
- opentool_python-0.1.0/src/opentool_python/server/__init__.py +5 -0
- opentool_python-0.1.0/src/opentool_python/server/cli_arguments.py +41 -0
- opentool_python-0.1.0/src/opentool_python/server/cli_tool.py +10 -0
- opentool_python-0.1.0/src/opentool_python/server/exceptions.py +31 -0
- opentool_python-0.1.0/src/opentool_python/server/opentool_server.py +310 -0
- opentool_python-0.1.0/src/opentool_python/tool/__init__.py +18 -0
- opentool_python-0.1.0/src/opentool_python/tool/exceptions.py +61 -0
- opentool_python-0.1.0/src/opentool_python/tool/model.py +24 -0
- opentool_python-0.1.0/src/opentool_python/tool/tool.py +30 -0
- opentool_python-0.1.0/src/opentool_python.egg-info/PKG-INFO +180 -0
- opentool_python-0.1.0/src/opentool_python.egg-info/SOURCES.txt +37 -0
- opentool_python-0.1.0/src/opentool_python.egg-info/dependency_links.txt +1 -0
- opentool_python-0.1.0/src/opentool_python.egg-info/requires.txt +2 -0
- opentool_python-0.1.0/src/opentool_python.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenTool Hub
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: opentool-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for OpenTool-compatible clients and servers
|
|
5
|
+
Author: OpenTool Hub
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/opentool-hub/opentool-python
|
|
8
|
+
Project-URL: Issues, https://github.com/opentool-hub/opentool-python/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.10
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: jsonschema[format]<5,>=4.22
|
|
15
|
+
Requires-Dist: referencing<1,>=0.30
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# OpenTool SDK for Python
|
|
19
|
+
|
|
20
|
+
English | [中文](README-zh_CN.md)
|
|
21
|
+
|
|
22
|
+
OpenTool SDK for Python provides the core building blocks to host or consume OpenTool-compatible tools in Python: an HTTP/JSON-RPC server runtime, an HTTP client with unary + SSE streaming calls, and a JSON schema loader. This project is designed to align with [opentool-dart](https://github.com/opentool-hub/opentool-dart) so multi-language SDK behavior stays consistent.
|
|
23
|
+
|
|
24
|
+
## Library Entrypoints
|
|
25
|
+
|
|
26
|
+
- `opentool_python.opentool_server` - server runtime, CLI argument helper, and Tool base class.
|
|
27
|
+
- `opentool_python.opentool_client` - HTTP/JSON-RPC client plus DTO/LLM models.
|
|
28
|
+
- `opentool_python.opentool_schema` - JSON specification models and loader.
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- `OpenToolServer` mounts `/opentool` JSON-RPC endpoints backed by your `Tool` implementation, with optional Bearer API-key auth.
|
|
33
|
+
- `OpenToolClient` supports version lookup, unary `call`, SSE `stream_call`, metadata `load`, and remote `stop`.
|
|
34
|
+
- `OpenToolJsonLoader` parses OpenTool JSON specs and resolves `$ref` schema references.
|
|
35
|
+
- End-to-end examples in `example/server.py` and `example/client.py` demonstrate CRUD + streaming usage.
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
|
|
39
|
+
- Python `>=3.10`
|
|
40
|
+
- Schema validation uses `jsonschema` and `referencing`, installed with the SDK.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
Install from PyPI:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
python -m pip install opentool-python
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Install as editable package in local development:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
pip install -e .
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Or install with source path from another project:
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
pip install /absolute/path/to/opentool-python
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
### Implement a Tool
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from pathlib import Path
|
|
68
|
+
from opentool_python.json_loader import OpenToolJsonLoader
|
|
69
|
+
from opentool_python.opentool_server import (
|
|
70
|
+
CliTool,
|
|
71
|
+
EventType,
|
|
72
|
+
FunctionNotSupportedException,
|
|
73
|
+
OpenTool,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class MockTool(CliTool):
|
|
78
|
+
def call(self, name, arguments):
|
|
79
|
+
if name == "count":
|
|
80
|
+
return {"count": 1}
|
|
81
|
+
return FunctionNotSupportedException(function_name=name).to_json()
|
|
82
|
+
|
|
83
|
+
def stream_call(self, name, arguments, on_event):
|
|
84
|
+
if name == "sequentiallyRead":
|
|
85
|
+
on_event(EventType.DATA, {"data": "Hello"})
|
|
86
|
+
else:
|
|
87
|
+
on_event(
|
|
88
|
+
EventType.ERROR,
|
|
89
|
+
FunctionNotSupportedException(function_name=name).to_json(),
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
def load(self) -> OpenTool | None:
|
|
93
|
+
return OpenToolJsonLoader().load_from_file(
|
|
94
|
+
str(Path("example/mock_tool.json"))
|
|
95
|
+
)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Launch the server
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
PYTHONPATH=src python example/server.py
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`CliArguments` can pass built-in and custom CLI switches into your `CliTool.init_args`, so you can preload state before handlers accept requests.
|
|
105
|
+
|
|
106
|
+
### Call the tool from Python
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from opentool_python.opentool_client import FunctionCall, HostType, OpenToolClient
|
|
110
|
+
|
|
111
|
+
client = OpenToolClient(
|
|
112
|
+
tool_host=HostType.LOCALHOST,
|
|
113
|
+
tool_port=17002,
|
|
114
|
+
tool_api_key="your-key",
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
print(client.version().to_json())
|
|
118
|
+
print(client.call(FunctionCall(id="call-0", name="count", arguments={})).to_json())
|
|
119
|
+
|
|
120
|
+
client.stream_call(
|
|
121
|
+
FunctionCall(id="call-1", name="sequentiallyRead", arguments={}),
|
|
122
|
+
lambda event, tool_return: print(event, tool_return.result),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
print(client.load().to_json())
|
|
126
|
+
print(client.stop().to_json())
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## CLI and HTTP Reference
|
|
130
|
+
|
|
131
|
+
- Base path defaults to `/opentool`.
|
|
132
|
+
- Endpoints:
|
|
133
|
+
- `GET /version`
|
|
134
|
+
- `POST /call`
|
|
135
|
+
- `POST /streamCall`
|
|
136
|
+
- `GET /load` returns HTTP 404 with code `TOOL_NOT_FOUND` when metadata is unavailable.
|
|
137
|
+
- `POST /stop`
|
|
138
|
+
- Built-in CLI flags (via `CliArguments`):
|
|
139
|
+
- `--opentoolServerTag`
|
|
140
|
+
- `--opentoolServerHost`
|
|
141
|
+
- `--opentoolServerPort`
|
|
142
|
+
- repeatable `--opentoolServerApiKeys`
|
|
143
|
+
- Streaming protocol is Server-Sent Events with event names `start`, `data`, `error`, and `done`.
|
|
144
|
+
|
|
145
|
+
## JSON Specification Loader
|
|
146
|
+
|
|
147
|
+
- Import `opentool_python.opentool_schema` if you only need spec models and parsing.
|
|
148
|
+
- `OpenToolJsonLoader().load_from_file(path)` loads local files and resolves `$ref` entries under `#/schemas/*`.
|
|
149
|
+
- `OpenToolJsonLoader().load(json_string)` loads from raw JSON strings.
|
|
150
|
+
- Specification reference: [OpenTool Spec](https://github.com/opentool-hub/opentool-spec).
|
|
151
|
+
|
|
152
|
+
Schemas default to JSON Schema Draft 2020-12. A recognized `$schema` selects its declared draft. `Schema.to_json()` returns a dictionary or boolean and preserves references, annotations, and extension keywords. Named `#/schemas/...` references are scoped to each OpenTool document, including documents loaded over HTTP.
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from opentool_python.opentool_schema import Schema
|
|
156
|
+
|
|
157
|
+
schema = Schema.from_json({"type": "string", "minLength": 3})
|
|
158
|
+
result = schema.validate("ab")
|
|
159
|
+
print(result.is_valid, result.errors)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Use `validate_formats=True` to assert formats. To supply external schemas, pass a synchronous `schema_reference_resolver` callback to `OpenTool.from_json`, `OpenToolJsonLoader`, or `OpenToolClient`. The callback receives the resource URI and returns an object, a boolean, or `None` if unavailable.
|
|
163
|
+
|
|
164
|
+
## Examples and Development
|
|
165
|
+
|
|
166
|
+
- Example files:
|
|
167
|
+
- `example/server.py`
|
|
168
|
+
- `example/client.py`
|
|
169
|
+
- `example/mock_tool.json`
|
|
170
|
+
- Common local workflow:
|
|
171
|
+
|
|
172
|
+
```sh
|
|
173
|
+
python -m compileall src example
|
|
174
|
+
PYTHONPATH=src python example/server.py
|
|
175
|
+
PYTHONPATH=src python example/client.py
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Compatibility Note
|
|
179
|
+
|
|
180
|
+
This Python SDK is currently a baseline implementation focused on API shape and protocol compatibility with `opentool-dart`.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# OpenTool SDK for Python
|
|
2
|
+
|
|
3
|
+
English | [中文](README-zh_CN.md)
|
|
4
|
+
|
|
5
|
+
OpenTool SDK for Python provides the core building blocks to host or consume OpenTool-compatible tools in Python: an HTTP/JSON-RPC server runtime, an HTTP client with unary + SSE streaming calls, and a JSON schema loader. This project is designed to align with [opentool-dart](https://github.com/opentool-hub/opentool-dart) so multi-language SDK behavior stays consistent.
|
|
6
|
+
|
|
7
|
+
## Library Entrypoints
|
|
8
|
+
|
|
9
|
+
- `opentool_python.opentool_server` - server runtime, CLI argument helper, and Tool base class.
|
|
10
|
+
- `opentool_python.opentool_client` - HTTP/JSON-RPC client plus DTO/LLM models.
|
|
11
|
+
- `opentool_python.opentool_schema` - JSON specification models and loader.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- `OpenToolServer` mounts `/opentool` JSON-RPC endpoints backed by your `Tool` implementation, with optional Bearer API-key auth.
|
|
16
|
+
- `OpenToolClient` supports version lookup, unary `call`, SSE `stream_call`, metadata `load`, and remote `stop`.
|
|
17
|
+
- `OpenToolJsonLoader` parses OpenTool JSON specs and resolves `$ref` schema references.
|
|
18
|
+
- End-to-end examples in `example/server.py` and `example/client.py` demonstrate CRUD + streaming usage.
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
- Python `>=3.10`
|
|
23
|
+
- Schema validation uses `jsonschema` and `referencing`, installed with the SDK.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Install from PyPI:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
python -m pip install opentool-python
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Install as editable package in local development:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
pip install -e .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or install with source path from another project:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pip install /absolute/path/to/opentool-python
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
### Implement a Tool
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from pathlib import Path
|
|
51
|
+
from opentool_python.json_loader import OpenToolJsonLoader
|
|
52
|
+
from opentool_python.opentool_server import (
|
|
53
|
+
CliTool,
|
|
54
|
+
EventType,
|
|
55
|
+
FunctionNotSupportedException,
|
|
56
|
+
OpenTool,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class MockTool(CliTool):
|
|
61
|
+
def call(self, name, arguments):
|
|
62
|
+
if name == "count":
|
|
63
|
+
return {"count": 1}
|
|
64
|
+
return FunctionNotSupportedException(function_name=name).to_json()
|
|
65
|
+
|
|
66
|
+
def stream_call(self, name, arguments, on_event):
|
|
67
|
+
if name == "sequentiallyRead":
|
|
68
|
+
on_event(EventType.DATA, {"data": "Hello"})
|
|
69
|
+
else:
|
|
70
|
+
on_event(
|
|
71
|
+
EventType.ERROR,
|
|
72
|
+
FunctionNotSupportedException(function_name=name).to_json(),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
def load(self) -> OpenTool | None:
|
|
76
|
+
return OpenToolJsonLoader().load_from_file(
|
|
77
|
+
str(Path("example/mock_tool.json"))
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Launch the server
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
PYTHONPATH=src python example/server.py
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`CliArguments` can pass built-in and custom CLI switches into your `CliTool.init_args`, so you can preload state before handlers accept requests.
|
|
88
|
+
|
|
89
|
+
### Call the tool from Python
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from opentool_python.opentool_client import FunctionCall, HostType, OpenToolClient
|
|
93
|
+
|
|
94
|
+
client = OpenToolClient(
|
|
95
|
+
tool_host=HostType.LOCALHOST,
|
|
96
|
+
tool_port=17002,
|
|
97
|
+
tool_api_key="your-key",
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
print(client.version().to_json())
|
|
101
|
+
print(client.call(FunctionCall(id="call-0", name="count", arguments={})).to_json())
|
|
102
|
+
|
|
103
|
+
client.stream_call(
|
|
104
|
+
FunctionCall(id="call-1", name="sequentiallyRead", arguments={}),
|
|
105
|
+
lambda event, tool_return: print(event, tool_return.result),
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
print(client.load().to_json())
|
|
109
|
+
print(client.stop().to_json())
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## CLI and HTTP Reference
|
|
113
|
+
|
|
114
|
+
- Base path defaults to `/opentool`.
|
|
115
|
+
- Endpoints:
|
|
116
|
+
- `GET /version`
|
|
117
|
+
- `POST /call`
|
|
118
|
+
- `POST /streamCall`
|
|
119
|
+
- `GET /load` returns HTTP 404 with code `TOOL_NOT_FOUND` when metadata is unavailable.
|
|
120
|
+
- `POST /stop`
|
|
121
|
+
- Built-in CLI flags (via `CliArguments`):
|
|
122
|
+
- `--opentoolServerTag`
|
|
123
|
+
- `--opentoolServerHost`
|
|
124
|
+
- `--opentoolServerPort`
|
|
125
|
+
- repeatable `--opentoolServerApiKeys`
|
|
126
|
+
- Streaming protocol is Server-Sent Events with event names `start`, `data`, `error`, and `done`.
|
|
127
|
+
|
|
128
|
+
## JSON Specification Loader
|
|
129
|
+
|
|
130
|
+
- Import `opentool_python.opentool_schema` if you only need spec models and parsing.
|
|
131
|
+
- `OpenToolJsonLoader().load_from_file(path)` loads local files and resolves `$ref` entries under `#/schemas/*`.
|
|
132
|
+
- `OpenToolJsonLoader().load(json_string)` loads from raw JSON strings.
|
|
133
|
+
- Specification reference: [OpenTool Spec](https://github.com/opentool-hub/opentool-spec).
|
|
134
|
+
|
|
135
|
+
Schemas default to JSON Schema Draft 2020-12. A recognized `$schema` selects its declared draft. `Schema.to_json()` returns a dictionary or boolean and preserves references, annotations, and extension keywords. Named `#/schemas/...` references are scoped to each OpenTool document, including documents loaded over HTTP.
|
|
136
|
+
|
|
137
|
+
```python
|
|
138
|
+
from opentool_python.opentool_schema import Schema
|
|
139
|
+
|
|
140
|
+
schema = Schema.from_json({"type": "string", "minLength": 3})
|
|
141
|
+
result = schema.validate("ab")
|
|
142
|
+
print(result.is_valid, result.errors)
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Use `validate_formats=True` to assert formats. To supply external schemas, pass a synchronous `schema_reference_resolver` callback to `OpenTool.from_json`, `OpenToolJsonLoader`, or `OpenToolClient`. The callback receives the resource URI and returns an object, a boolean, or `None` if unavailable.
|
|
146
|
+
|
|
147
|
+
## Examples and Development
|
|
148
|
+
|
|
149
|
+
- Example files:
|
|
150
|
+
- `example/server.py`
|
|
151
|
+
- `example/client.py`
|
|
152
|
+
- `example/mock_tool.json`
|
|
153
|
+
- Common local workflow:
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
python -m compileall src example
|
|
157
|
+
PYTHONPATH=src python example/server.py
|
|
158
|
+
PYTHONPATH=src python example/client.py
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Compatibility Note
|
|
162
|
+
|
|
163
|
+
This Python SDK is currently a baseline implementation focused on API shape and protocol compatibility with `opentool-dart`.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "opentool-python"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python SDK for OpenTool-compatible clients and servers"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "OpenTool Hub" }
|
|
13
|
+
]
|
|
14
|
+
license = "MIT"
|
|
15
|
+
license-files = ["LICENSE"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Operating System :: OS Independent"
|
|
19
|
+
]
|
|
20
|
+
dependencies = ["jsonschema[format]>=4.22,<5", "referencing>=0.30,<1"]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Repository = "https://github.com/opentool-hub/opentool-python"
|
|
24
|
+
Issues = "https://github.com/opentool-hub/opentool-python/issues"
|
|
25
|
+
|
|
26
|
+
[tool.setuptools]
|
|
27
|
+
package-dir = {"" = "src"}
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""OpenTool SDK for Python."""
|
|
2
|
+
|
|
3
|
+
from .dto import (
|
|
4
|
+
CLI_ARGUMENT_APIKEYS,
|
|
5
|
+
CLI_ARGUMENT_HOST,
|
|
6
|
+
CLI_ARGUMENT_PORT,
|
|
7
|
+
CLI_ARGUMENT_TAG,
|
|
8
|
+
DEFAULT_PREFIX,
|
|
9
|
+
DEFAULT_TOOL_HOST,
|
|
10
|
+
DEFAULT_TOOL_PORT,
|
|
11
|
+
DEFAULT_TOOL_TAG,
|
|
12
|
+
HostType,
|
|
13
|
+
JsonRPCHttpRequestBody,
|
|
14
|
+
JsonRPCHttpResponseBody,
|
|
15
|
+
JsonRPCHttpResponseBodyError,
|
|
16
|
+
StatusInfo,
|
|
17
|
+
StatusType,
|
|
18
|
+
Version,
|
|
19
|
+
)
|
|
20
|
+
from .json_loader import OpenToolJsonLoader
|
|
21
|
+
from .llm.model import FunctionCall, ToolReturn
|
|
22
|
+
from .model.data_type import DataType
|
|
23
|
+
from .model.function_model import FunctionModel
|
|
24
|
+
from .model.info import Info
|
|
25
|
+
from .model.opentool import OpenTool
|
|
26
|
+
from .model.parameter import Parameter
|
|
27
|
+
from .model.return_model import Return
|
|
28
|
+
from .model.schema import Schema, SchemaReferenceResolver, SchemaResolver, SchemaType, SchemaValidationResult
|
|
29
|
+
from .model.server import ServerConfig
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"HostType",
|
|
33
|
+
"Version",
|
|
34
|
+
"JsonRPCHttpRequestBody",
|
|
35
|
+
"JsonRPCHttpResponseBody",
|
|
36
|
+
"JsonRPCHttpResponseBodyError",
|
|
37
|
+
"StatusInfo",
|
|
38
|
+
"StatusType",
|
|
39
|
+
"DEFAULT_PREFIX",
|
|
40
|
+
"DEFAULT_TOOL_TAG",
|
|
41
|
+
"DEFAULT_TOOL_HOST",
|
|
42
|
+
"DEFAULT_TOOL_PORT",
|
|
43
|
+
"CLI_ARGUMENT_TAG",
|
|
44
|
+
"CLI_ARGUMENT_HOST",
|
|
45
|
+
"CLI_ARGUMENT_PORT",
|
|
46
|
+
"CLI_ARGUMENT_APIKEYS",
|
|
47
|
+
"FunctionCall",
|
|
48
|
+
"ToolReturn",
|
|
49
|
+
"DataType",
|
|
50
|
+
"FunctionModel",
|
|
51
|
+
"Info",
|
|
52
|
+
"OpenTool",
|
|
53
|
+
"Parameter",
|
|
54
|
+
"Return",
|
|
55
|
+
"Schema",
|
|
56
|
+
"SchemaType",
|
|
57
|
+
"SchemaReferenceResolver",
|
|
58
|
+
"SchemaResolver",
|
|
59
|
+
"SchemaValidationResult",
|
|
60
|
+
"ServerConfig",
|
|
61
|
+
"OpenToolJsonLoader",
|
|
62
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from .exceptions import (
|
|
2
|
+
ErrorNullException,
|
|
3
|
+
OpenToolServerCallException,
|
|
4
|
+
OpenToolServerNoAccessException,
|
|
5
|
+
OpenToolServerUnauthorizedException,
|
|
6
|
+
ResponseNullException,
|
|
7
|
+
)
|
|
8
|
+
from .opentool_client import Client, OpenToolClient
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Client",
|
|
12
|
+
"OpenToolClient",
|
|
13
|
+
"ResponseNullException",
|
|
14
|
+
"ErrorNullException",
|
|
15
|
+
"OpenToolServerUnauthorizedException",
|
|
16
|
+
"OpenToolServerNoAccessException",
|
|
17
|
+
"OpenToolServerCallException",
|
|
18
|
+
]
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class ResponseNullException(Exception):
|
|
9
|
+
code: int
|
|
10
|
+
message: str = "Response is null"
|
|
11
|
+
|
|
12
|
+
def to_json(self) -> dict[str, Any]:
|
|
13
|
+
return {"code": self.code, "message": self.message}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass
|
|
17
|
+
class ErrorNullException(Exception):
|
|
18
|
+
code: int
|
|
19
|
+
message: str = "Error is null"
|
|
20
|
+
|
|
21
|
+
def to_json(self) -> dict[str, Any]:
|
|
22
|
+
return {"code": self.code, "message": self.message}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class OpenToolServerUnauthorizedException(Exception):
|
|
27
|
+
code: int = 401
|
|
28
|
+
message: str = "Please check API Key is VALID or NOT"
|
|
29
|
+
|
|
30
|
+
def to_json(self) -> dict[str, Any]:
|
|
31
|
+
return {"code": self.code, "message": self.message}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class OpenToolServerNoAccessException(Exception):
|
|
36
|
+
code: int = 404
|
|
37
|
+
message: str = "Please check OpenTool Server is RUNNING or NOT"
|
|
38
|
+
|
|
39
|
+
def to_json(self) -> dict[str, Any]:
|
|
40
|
+
return {"code": self.code, "message": self.message}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass
|
|
44
|
+
class OpenToolServerCallException(Exception):
|
|
45
|
+
message: str
|
|
46
|
+
|
|
47
|
+
def to_json(self) -> dict[str, Any]:
|
|
48
|
+
return {"message": self.message}
|