daisi-sdk 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.
- daisi_sdk-0.1.0/LICENSE +21 -0
- daisi_sdk-0.1.0/PKG-INFO +322 -0
- daisi_sdk-0.1.0/README.md +280 -0
- daisi_sdk-0.1.0/pyproject.toml +117 -0
- daisi_sdk-0.1.0/setup.cfg +4 -0
- daisi_sdk-0.1.0/src/daisi/__init__.py +72 -0
- daisi_sdk-0.1.0/src/daisi/aio/__init__.py +42 -0
- daisi_sdk-0.1.0/src/daisi/aio/base_client.py +77 -0
- daisi_sdk-0.1.0/src/daisi/aio/client.py +97 -0
- daisi_sdk-0.1.0/src/daisi/aio/clients/__init__.py +24 -0
- daisi_sdk-0.1.0/src/daisi/aio/clients/auth.py +175 -0
- daisi_sdk-0.1.0/src/daisi/aio/clients/commands.py +98 -0
- daisi_sdk-0.1.0/src/daisi/aio/clients/hosts.py +95 -0
- daisi_sdk-0.1.0/src/daisi/aio/clients/inference.py +226 -0
- daisi_sdk-0.1.0/src/daisi/aio/clients/models.py +52 -0
- daisi_sdk-0.1.0/src/daisi/aio/clients/peers.py +50 -0
- daisi_sdk-0.1.0/src/daisi/aio/clients/session.py +168 -0
- daisi_sdk-0.1.0/src/daisi/aio/clients/settings.py +69 -0
- daisi_sdk-0.1.0/src/daisi/base_client.py +81 -0
- daisi_sdk-0.1.0/src/daisi/client.py +147 -0
- daisi_sdk-0.1.0/src/daisi/clients/__init__.py +24 -0
- daisi_sdk-0.1.0/src/daisi/clients/accounts.py +200 -0
- daisi_sdk-0.1.0/src/daisi/clients/auth.py +192 -0
- daisi_sdk-0.1.0/src/daisi/clients/commands.py +92 -0
- daisi_sdk-0.1.0/src/daisi/clients/dapps.py +174 -0
- daisi_sdk-0.1.0/src/daisi/clients/hosts.py +131 -0
- daisi_sdk-0.1.0/src/daisi/clients/inference.py +223 -0
- daisi_sdk-0.1.0/src/daisi/clients/models.py +50 -0
- daisi_sdk-0.1.0/src/daisi/clients/networks.py +139 -0
- daisi_sdk-0.1.0/src/daisi/clients/orcs.py +138 -0
- daisi_sdk-0.1.0/src/daisi/clients/peers.py +50 -0
- daisi_sdk-0.1.0/src/daisi/clients/session.py +172 -0
- daisi_sdk-0.1.0/src/daisi/clients/settings.py +69 -0
- daisi_sdk-0.1.0/src/daisi/config.py +169 -0
- daisi_sdk-0.1.0/src/daisi/exceptions.py +21 -0
- daisi_sdk-0.1.0/src/daisi/protos/__init__.py +0 -0
- daisi_sdk-0.1.0/src/daisi/providers.py +133 -0
- daisi_sdk-0.1.0/src/daisi/session_manager.py +323 -0
- daisi_sdk-0.1.0/src/daisi_sdk.egg-info/PKG-INFO +322 -0
- daisi_sdk-0.1.0/src/daisi_sdk.egg-info/SOURCES.txt +132 -0
- daisi_sdk-0.1.0/src/daisi_sdk.egg-info/__init__.py +0 -0
- daisi_sdk-0.1.0/src/daisi_sdk.egg-info/dependency_links.txt +1 -0
- daisi_sdk-0.1.0/src/daisi_sdk.egg-info/requires.txt +23 -0
- daisi_sdk-0.1.0/src/daisi_sdk.egg-info/top_level.txt +2 -0
- daisi_sdk-0.1.0/src/protos/__init__.py +0 -0
- daisi_sdk-0.1.0/src/protos/v1/Accounts_pb2.py +37 -0
- daisi_sdk-0.1.0/src/protos/v1/Accounts_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Accounts_pb2_grpc.py +391 -0
- daisi_sdk-0.1.0/src/protos/v1/Auth_pb2.py +37 -0
- daisi_sdk-0.1.0/src/protos/v1/Auth_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Auth_pb2_grpc.py +297 -0
- daisi_sdk-0.1.0/src/protos/v1/Commands_pb2.py +39 -0
- daisi_sdk-0.1.0/src/protos/v1/Commands_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Commands_pb2_grpc.py +188 -0
- daisi_sdk-0.1.0/src/protos/v1/Dapps_pb2.py +37 -0
- daisi_sdk-0.1.0/src/protos/v1/Dapps_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Dapps_pb2_grpc.py +344 -0
- daisi_sdk-0.1.0/src/protos/v1/Hosts_pb2.py +37 -0
- daisi_sdk-0.1.0/src/protos/v1/Hosts_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Hosts_pb2_grpc.py +297 -0
- daisi_sdk-0.1.0/src/protos/v1/Inferences_pb2.py +39 -0
- daisi_sdk-0.1.0/src/protos/v1/Inferences_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Inferences_pb2_grpc.py +250 -0
- daisi_sdk-0.1.0/src/protos/v1/Models_pb2.py +37 -0
- daisi_sdk-0.1.0/src/protos/v1/Models_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Models_pb2_grpc.py +109 -0
- daisi_sdk-0.1.0/src/protos/v1/Networks_pb2.py +37 -0
- daisi_sdk-0.1.0/src/protos/v1/Networks_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Networks_pb2_grpc.py +250 -0
- daisi_sdk-0.1.0/src/protos/v1/Orcs_pb2.py +37 -0
- daisi_sdk-0.1.0/src/protos/v1/Orcs_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Orcs_pb2_grpc.py +250 -0
- daisi_sdk-0.1.0/src/protos/v1/Peers_pb2.py +37 -0
- daisi_sdk-0.1.0/src/protos/v1/Peers_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Peers_pb2_grpc.py +109 -0
- daisi_sdk-0.1.0/src/protos/v1/Sessions_pb2.py +37 -0
- daisi_sdk-0.1.0/src/protos/v1/Sessions_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Sessions_pb2_grpc.py +250 -0
- daisi_sdk-0.1.0/src/protos/v1/Settings_pb2.py +40 -0
- daisi_sdk-0.1.0/src/protos/v1/Settings_pb2.pyi +8 -0
- daisi_sdk-0.1.0/src/protos/v1/Settings_pb2_grpc.py +156 -0
- daisi_sdk-0.1.0/src/protos/v1/__init__.py +0 -0
- daisi_sdk-0.1.0/src/protos/v1/models/AccountModels_pb2.py +76 -0
- daisi_sdk-0.1.0/src/protos/v1/models/AccountModels_pb2.pyi +607 -0
- daisi_sdk-0.1.0/src/protos/v1/models/AccountModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/AuthModels_pb2.py +63 -0
- daisi_sdk-0.1.0/src/protos/v1/models/AuthModels_pb2.pyi +422 -0
- daisi_sdk-0.1.0/src/protos/v1/models/AuthModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/CommandModels_pb2.py +58 -0
- daisi_sdk-0.1.0/src/protos/v1/models/CommandModels_pb2.pyi +339 -0
- daisi_sdk-0.1.0/src/protos/v1/models/CommandModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/DappModels_pb2.py +67 -0
- daisi_sdk-0.1.0/src/protos/v1/models/DappModels_pb2.pyi +335 -0
- daisi_sdk-0.1.0/src/protos/v1/models/DappModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/HostModels_pb2.py +67 -0
- daisi_sdk-0.1.0/src/protos/v1/models/HostModels_pb2.pyi +509 -0
- daisi_sdk-0.1.0/src/protos/v1/models/HostModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/InferenceModels_pb2.py +61 -0
- daisi_sdk-0.1.0/src/protos/v1/models/InferenceModels_pb2.pyi +710 -0
- daisi_sdk-0.1.0/src/protos/v1/models/InferenceModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/ModelModels_pb2.py +38 -0
- daisi_sdk-0.1.0/src/protos/v1/models/ModelModels_pb2.pyi +104 -0
- daisi_sdk-0.1.0/src/protos/v1/models/ModelModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/NetworkModels_pb2.py +59 -0
- daisi_sdk-0.1.0/src/protos/v1/models/NetworkModels_pb2.pyi +330 -0
- daisi_sdk-0.1.0/src/protos/v1/models/NetworkModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/OrcModels_pb2.py +61 -0
- daisi_sdk-0.1.0/src/protos/v1/models/OrcModels_pb2.pyi +426 -0
- daisi_sdk-0.1.0/src/protos/v1/models/OrcModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/PeerModels_pb2.py +38 -0
- daisi_sdk-0.1.0/src/protos/v1/models/PeerModels_pb2.pyi +75 -0
- daisi_sdk-0.1.0/src/protos/v1/models/PeerModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/SessionModels_pb2.py +57 -0
- daisi_sdk-0.1.0/src/protos/v1/models/SessionModels_pb2.pyi +294 -0
- daisi_sdk-0.1.0/src/protos/v1/models/SessionModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/SettingsModels_pb2.py +70 -0
- daisi_sdk-0.1.0/src/protos/v1/models/SettingsModels_pb2.pyi +467 -0
- daisi_sdk-0.1.0/src/protos/v1/models/SettingsModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/SystemModels_pb2.py +40 -0
- daisi_sdk-0.1.0/src/protos/v1/models/SystemModels_pb2.pyi +127 -0
- daisi_sdk-0.1.0/src/protos/v1/models/SystemModels_pb2_grpc.py +27 -0
- daisi_sdk-0.1.0/src/protos/v1/models/__init__.py +0 -0
- daisi_sdk-0.1.0/tests/test_async_client.py +125 -0
- daisi_sdk-0.1.0/tests/test_async_inference_client.py +340 -0
- daisi_sdk-0.1.0/tests/test_async_session_client.py +328 -0
- daisi_sdk-0.1.0/tests/test_auth_client.py +276 -0
- daisi_sdk-0.1.0/tests/test_base_client.py +150 -0
- daisi_sdk-0.1.0/tests/test_client.py +112 -0
- daisi_sdk-0.1.0/tests/test_config.py +98 -0
- daisi_sdk-0.1.0/tests/test_exceptions.py +49 -0
- daisi_sdk-0.1.0/tests/test_hosts_client.py +196 -0
- daisi_sdk-0.1.0/tests/test_inference_client.py +305 -0
- daisi_sdk-0.1.0/tests/test_models_client.py +74 -0
- daisi_sdk-0.1.0/tests/test_session_client.py +293 -0
daisi_sdk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Daisi Contributors
|
|
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.
|
daisi_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: daisi-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python API wrapper for the Daisi SDK
|
|
5
|
+
Author-email: Daisi Contributors <dev@daisi.net>
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: daisi,sdk,api,wrapper
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: grpcio>=1.60.0
|
|
21
|
+
Requires-Dist: grpcio-tools>=1.60.0
|
|
22
|
+
Requires-Dist: protobuf>=4.25.0
|
|
23
|
+
Requires-Dist: pydantic>=2.0.0
|
|
24
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-grpc>=0.8.0; extra == "dev"
|
|
30
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
32
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: mypy>=1.4.0; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy-protobuf>=3.5.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pylint>=2.17.0; extra == "dev"
|
|
36
|
+
Requires-Dist: grpc-stubs>=1.53.0; extra == "dev"
|
|
37
|
+
Provides-Extra: docs
|
|
38
|
+
Requires-Dist: sphinx>=7.0.0; extra == "docs"
|
|
39
|
+
Requires-Dist: sphinx-rtd-theme>=1.3.0; extra == "docs"
|
|
40
|
+
Requires-Dist: sphinx-autodoc-typehints>=1.23.0; extra == "docs"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# Daisi SDK - Python gRPC Wrapper
|
|
44
|
+
|
|
45
|
+
A modern Python wrapper for the Daisi SDK, providing a clean and Pythonic interface to interact with the Daisi distributed AI network via gRPC.
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- **gRPC-based**: Full gRPC implementation matching the .NET SDK
|
|
50
|
+
- **Type-safe**: Full type hints for IDE autocomplete and type checking
|
|
51
|
+
- **Streaming support**: Native support for streaming inference responses
|
|
52
|
+
- **Session management**: Complete session lifecycle management
|
|
53
|
+
- **Comprehensive**: All Daisi services (Auth, Sessions, Inference, Models, Hosts, Peers, Settings, Commands)
|
|
54
|
+
- **Production-ready**: Follows PEP standards and best practices
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install daisi-sdk
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Development Installation
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
git clone https://github.com/daisinet/daisi-sdk-python.git
|
|
66
|
+
cd daisi-sdk-python
|
|
67
|
+
pip install -e ".[dev]"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Quick Start
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from daisi import DaisiClient
|
|
74
|
+
|
|
75
|
+
# Initialize client with API key
|
|
76
|
+
client = DaisiClient(client_key="your-client-key")
|
|
77
|
+
|
|
78
|
+
# Create a session
|
|
79
|
+
session_id, host = client.session.create(model_name="llama-3")
|
|
80
|
+
|
|
81
|
+
# Create an inference
|
|
82
|
+
inference_id = client.inference.create(
|
|
83
|
+
session_id=session_id,
|
|
84
|
+
initialization_prompt="You are a helpful assistant."
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# Send inference request with streaming response
|
|
88
|
+
for response in client.inference.send("Hello, how are you?"):
|
|
89
|
+
if response.Type == InferenceResponseTypes.InferenceText:
|
|
90
|
+
print(response.Content, end="", flush=True)
|
|
91
|
+
|
|
92
|
+
# Get statistics
|
|
93
|
+
stats = client.inference.stats()
|
|
94
|
+
print(f"\nTokens used: {stats.SessionTokenCount}")
|
|
95
|
+
|
|
96
|
+
# Clean up
|
|
97
|
+
client.inference.close_inference()
|
|
98
|
+
client.session.close()
|
|
99
|
+
client.close()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
Set your configuration via environment variables:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
export DAISI_CLIENT_KEY="your-client-key"
|
|
108
|
+
export DAISI_ORC_ADDRESS="orc.daisi.net"
|
|
109
|
+
export DAISI_ORC_PORT="443"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Or configure in code:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from daisi import DaisiClient, DaisiConfig
|
|
116
|
+
|
|
117
|
+
config = DaisiConfig(
|
|
118
|
+
client_key="your-client-key",
|
|
119
|
+
orc_address="orc.daisi.net",
|
|
120
|
+
orc_port=443,
|
|
121
|
+
use_ssl=True
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
client = DaisiClient(
|
|
125
|
+
client_key=config.client_key,
|
|
126
|
+
orc_address=config.orc_address,
|
|
127
|
+
orc_port=config.orc_port
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Available Clients
|
|
132
|
+
|
|
133
|
+
The SDK provides specialized clients for each service:
|
|
134
|
+
|
|
135
|
+
- **`client.auth`**: Authentication operations (create/validate keys, auth codes)
|
|
136
|
+
- **`client.session`**: Session management (create, claim, close, connect)
|
|
137
|
+
- **`client.inference`**: Inference operations (create, send streaming, stats, close)
|
|
138
|
+
- **`client.models`**: Model discovery and requirements
|
|
139
|
+
- **`client.hosts`**: Host registration and management
|
|
140
|
+
- **`client.peers`**: Peer operations
|
|
141
|
+
- **`client.settings`**: Settings management
|
|
142
|
+
- **`client.host_commands`**: Host command streaming
|
|
143
|
+
- **`client.app_commands`**: App command streaming
|
|
144
|
+
|
|
145
|
+
## Usage Examples
|
|
146
|
+
|
|
147
|
+
### Authentication
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from daisi import DaisiClient
|
|
151
|
+
|
|
152
|
+
client = DaisiClient(client_key="initial-key")
|
|
153
|
+
|
|
154
|
+
# Send auth code
|
|
155
|
+
client.auth.send_auth_code("user@example.com")
|
|
156
|
+
|
|
157
|
+
# Validate auth code and get new client key
|
|
158
|
+
client_key, user_name, account_name, account_id = client.auth.validate_auth_code(
|
|
159
|
+
secret_key="secret",
|
|
160
|
+
email_or_phone="user@example.com",
|
|
161
|
+
auth_code="123456",
|
|
162
|
+
app_id="my-app"
|
|
163
|
+
)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Session Management
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
# Create session with preferences
|
|
170
|
+
session_id, host = client.session.create(
|
|
171
|
+
model_name="llama-3",
|
|
172
|
+
direct_connect_required=False,
|
|
173
|
+
preferred_region="us-west",
|
|
174
|
+
private_network_only=False
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
# Connect to session
|
|
178
|
+
sid, has_capacity, already_connected = client.session.connect(session_id)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Inference with Tool Groups
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from protos.v1.models.InferenceModels_pb2 import (
|
|
185
|
+
ThinkChainOfThought,
|
|
186
|
+
InferenceCodingTools,
|
|
187
|
+
InferenceFileTools
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
# Create inference with tools
|
|
191
|
+
session_id, inference_id = client.inference.create(
|
|
192
|
+
session_id=session_id,
|
|
193
|
+
think_level=ThinkChainOfThought,
|
|
194
|
+
tool_groups=[InferenceCodingTools, InferenceFileTools]
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
# Send with custom parameters
|
|
198
|
+
for response in client.inference.send(
|
|
199
|
+
text="Write a Python function to calculate fibonacci",
|
|
200
|
+
temperature=0.7,
|
|
201
|
+
top_p=0.9,
|
|
202
|
+
max_tokens=2000
|
|
203
|
+
):
|
|
204
|
+
print(response.Content, end="")
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Models
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
# Get required models
|
|
211
|
+
models_response = client.models.get_required_models()
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Hosts
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
# Get available hosts
|
|
218
|
+
hosts = client.hosts.get_hosts()
|
|
219
|
+
|
|
220
|
+
for host in hosts:
|
|
221
|
+
print(f"{host.Name}: {host.Status} - {host.Region}")
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Development
|
|
225
|
+
|
|
226
|
+
### Generating Protobuf Code
|
|
227
|
+
|
|
228
|
+
If you modify the .proto files:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
python generate_protos.py
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Testing
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
# Run all tests
|
|
238
|
+
pytest
|
|
239
|
+
|
|
240
|
+
# Run with coverage
|
|
241
|
+
pytest --cov=src/daisi
|
|
242
|
+
|
|
243
|
+
# Run specific test file
|
|
244
|
+
pytest tests/test_client.py
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Code Quality
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Format code
|
|
251
|
+
black src/ tests/
|
|
252
|
+
|
|
253
|
+
# Sort imports
|
|
254
|
+
isort src/ tests/
|
|
255
|
+
|
|
256
|
+
# Lint
|
|
257
|
+
flake8 src/ tests/
|
|
258
|
+
|
|
259
|
+
# Type checking
|
|
260
|
+
mypy src/
|
|
261
|
+
|
|
262
|
+
# Run all checks
|
|
263
|
+
make lint
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Project Structure
|
|
267
|
+
|
|
268
|
+
```
|
|
269
|
+
daisi-sdk-python/
|
|
270
|
+
├── src/daisi/ # Main package
|
|
271
|
+
│ ├── __init__.py
|
|
272
|
+
│ ├── client.py # Main unified client
|
|
273
|
+
│ ├── config.py # Configuration
|
|
274
|
+
│ ├── base_client.py # Base gRPC client
|
|
275
|
+
│ ├── exceptions.py # Custom exceptions
|
|
276
|
+
│ └── clients/ # Service-specific clients
|
|
277
|
+
│ ├── auth.py
|
|
278
|
+
│ ├── session.py
|
|
279
|
+
│ ├── inference.py
|
|
280
|
+
│ ├── models.py
|
|
281
|
+
│ ├── hosts.py
|
|
282
|
+
│ ├── peers.py
|
|
283
|
+
│ ├── settings.py
|
|
284
|
+
│ └── commands.py
|
|
285
|
+
├── protos/v1/ # Protobuf definitions
|
|
286
|
+
│ ├── *.proto # Service definitions
|
|
287
|
+
│ └── models/ # Model definitions
|
|
288
|
+
├── src/protos/ # Generated Python code
|
|
289
|
+
├── tests/ # Test suite
|
|
290
|
+
├── pyproject.toml # Project configuration
|
|
291
|
+
├── generate_protos.py # Proto generation script
|
|
292
|
+
└── README.md
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Architecture
|
|
296
|
+
|
|
297
|
+
The SDK is built on gRPC and Protocol Buffers, matching the .NET SDK architecture:
|
|
298
|
+
|
|
299
|
+
- **gRPC**: Efficient binary protocol with streaming support
|
|
300
|
+
- **Protocol Buffers**: Strongly-typed message definitions
|
|
301
|
+
- **Session-based**: Orchestrator (Orc) manages session lifecycle
|
|
302
|
+
- **Streaming**: Real-time token-by-token inference responses
|
|
303
|
+
- **Direct Connect**: Optional peer-to-peer mode
|
|
304
|
+
|
|
305
|
+
## Contributing
|
|
306
|
+
|
|
307
|
+
Contributions are welcome! Ensure:
|
|
308
|
+
|
|
309
|
+
1. Code follows PEP 8 with Black formatting
|
|
310
|
+
2. All tests pass and coverage is maintained
|
|
311
|
+
3. Type hints are included
|
|
312
|
+
4. Documentation is updated
|
|
313
|
+
|
|
314
|
+
## License
|
|
315
|
+
|
|
316
|
+
MIT License - see LICENSE file for details
|
|
317
|
+
|
|
318
|
+
## Links
|
|
319
|
+
|
|
320
|
+
- [Daisi Website](https://daisi.net)
|
|
321
|
+
- [.NET SDK](https://github.com/daisinet/daisi-sdk-dotnet)
|
|
322
|
+
- [Documentation](https://daisi.ai/Learn/SDK)
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# Daisi SDK - Python gRPC Wrapper
|
|
2
|
+
|
|
3
|
+
A modern Python wrapper for the Daisi SDK, providing a clean and Pythonic interface to interact with the Daisi distributed AI network via gRPC.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **gRPC-based**: Full gRPC implementation matching the .NET SDK
|
|
8
|
+
- **Type-safe**: Full type hints for IDE autocomplete and type checking
|
|
9
|
+
- **Streaming support**: Native support for streaming inference responses
|
|
10
|
+
- **Session management**: Complete session lifecycle management
|
|
11
|
+
- **Comprehensive**: All Daisi services (Auth, Sessions, Inference, Models, Hosts, Peers, Settings, Commands)
|
|
12
|
+
- **Production-ready**: Follows PEP standards and best practices
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install daisi-sdk
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Development Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git clone https://github.com/daisinet/daisi-sdk-python.git
|
|
24
|
+
cd daisi-sdk-python
|
|
25
|
+
pip install -e ".[dev]"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from daisi import DaisiClient
|
|
32
|
+
|
|
33
|
+
# Initialize client with API key
|
|
34
|
+
client = DaisiClient(client_key="your-client-key")
|
|
35
|
+
|
|
36
|
+
# Create a session
|
|
37
|
+
session_id, host = client.session.create(model_name="llama-3")
|
|
38
|
+
|
|
39
|
+
# Create an inference
|
|
40
|
+
inference_id = client.inference.create(
|
|
41
|
+
session_id=session_id,
|
|
42
|
+
initialization_prompt="You are a helpful assistant."
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
# Send inference request with streaming response
|
|
46
|
+
for response in client.inference.send("Hello, how are you?"):
|
|
47
|
+
if response.Type == InferenceResponseTypes.InferenceText:
|
|
48
|
+
print(response.Content, end="", flush=True)
|
|
49
|
+
|
|
50
|
+
# Get statistics
|
|
51
|
+
stats = client.inference.stats()
|
|
52
|
+
print(f"\nTokens used: {stats.SessionTokenCount}")
|
|
53
|
+
|
|
54
|
+
# Clean up
|
|
55
|
+
client.inference.close_inference()
|
|
56
|
+
client.session.close()
|
|
57
|
+
client.close()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Configuration
|
|
61
|
+
|
|
62
|
+
Set your configuration via environment variables:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
export DAISI_CLIENT_KEY="your-client-key"
|
|
66
|
+
export DAISI_ORC_ADDRESS="orc.daisi.net"
|
|
67
|
+
export DAISI_ORC_PORT="443"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Or configure in code:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from daisi import DaisiClient, DaisiConfig
|
|
74
|
+
|
|
75
|
+
config = DaisiConfig(
|
|
76
|
+
client_key="your-client-key",
|
|
77
|
+
orc_address="orc.daisi.net",
|
|
78
|
+
orc_port=443,
|
|
79
|
+
use_ssl=True
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
client = DaisiClient(
|
|
83
|
+
client_key=config.client_key,
|
|
84
|
+
orc_address=config.orc_address,
|
|
85
|
+
orc_port=config.orc_port
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Available Clients
|
|
90
|
+
|
|
91
|
+
The SDK provides specialized clients for each service:
|
|
92
|
+
|
|
93
|
+
- **`client.auth`**: Authentication operations (create/validate keys, auth codes)
|
|
94
|
+
- **`client.session`**: Session management (create, claim, close, connect)
|
|
95
|
+
- **`client.inference`**: Inference operations (create, send streaming, stats, close)
|
|
96
|
+
- **`client.models`**: Model discovery and requirements
|
|
97
|
+
- **`client.hosts`**: Host registration and management
|
|
98
|
+
- **`client.peers`**: Peer operations
|
|
99
|
+
- **`client.settings`**: Settings management
|
|
100
|
+
- **`client.host_commands`**: Host command streaming
|
|
101
|
+
- **`client.app_commands`**: App command streaming
|
|
102
|
+
|
|
103
|
+
## Usage Examples
|
|
104
|
+
|
|
105
|
+
### Authentication
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from daisi import DaisiClient
|
|
109
|
+
|
|
110
|
+
client = DaisiClient(client_key="initial-key")
|
|
111
|
+
|
|
112
|
+
# Send auth code
|
|
113
|
+
client.auth.send_auth_code("user@example.com")
|
|
114
|
+
|
|
115
|
+
# Validate auth code and get new client key
|
|
116
|
+
client_key, user_name, account_name, account_id = client.auth.validate_auth_code(
|
|
117
|
+
secret_key="secret",
|
|
118
|
+
email_or_phone="user@example.com",
|
|
119
|
+
auth_code="123456",
|
|
120
|
+
app_id="my-app"
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Session Management
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
# Create session with preferences
|
|
128
|
+
session_id, host = client.session.create(
|
|
129
|
+
model_name="llama-3",
|
|
130
|
+
direct_connect_required=False,
|
|
131
|
+
preferred_region="us-west",
|
|
132
|
+
private_network_only=False
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# Connect to session
|
|
136
|
+
sid, has_capacity, already_connected = client.session.connect(session_id)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Inference with Tool Groups
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from protos.v1.models.InferenceModels_pb2 import (
|
|
143
|
+
ThinkChainOfThought,
|
|
144
|
+
InferenceCodingTools,
|
|
145
|
+
InferenceFileTools
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# Create inference with tools
|
|
149
|
+
session_id, inference_id = client.inference.create(
|
|
150
|
+
session_id=session_id,
|
|
151
|
+
think_level=ThinkChainOfThought,
|
|
152
|
+
tool_groups=[InferenceCodingTools, InferenceFileTools]
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# Send with custom parameters
|
|
156
|
+
for response in client.inference.send(
|
|
157
|
+
text="Write a Python function to calculate fibonacci",
|
|
158
|
+
temperature=0.7,
|
|
159
|
+
top_p=0.9,
|
|
160
|
+
max_tokens=2000
|
|
161
|
+
):
|
|
162
|
+
print(response.Content, end="")
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Models
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
# Get required models
|
|
169
|
+
models_response = client.models.get_required_models()
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Hosts
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
# Get available hosts
|
|
176
|
+
hosts = client.hosts.get_hosts()
|
|
177
|
+
|
|
178
|
+
for host in hosts:
|
|
179
|
+
print(f"{host.Name}: {host.Status} - {host.Region}")
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Development
|
|
183
|
+
|
|
184
|
+
### Generating Protobuf Code
|
|
185
|
+
|
|
186
|
+
If you modify the .proto files:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
python generate_protos.py
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Testing
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Run all tests
|
|
196
|
+
pytest
|
|
197
|
+
|
|
198
|
+
# Run with coverage
|
|
199
|
+
pytest --cov=src/daisi
|
|
200
|
+
|
|
201
|
+
# Run specific test file
|
|
202
|
+
pytest tests/test_client.py
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Code Quality
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# Format code
|
|
209
|
+
black src/ tests/
|
|
210
|
+
|
|
211
|
+
# Sort imports
|
|
212
|
+
isort src/ tests/
|
|
213
|
+
|
|
214
|
+
# Lint
|
|
215
|
+
flake8 src/ tests/
|
|
216
|
+
|
|
217
|
+
# Type checking
|
|
218
|
+
mypy src/
|
|
219
|
+
|
|
220
|
+
# Run all checks
|
|
221
|
+
make lint
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Project Structure
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
daisi-sdk-python/
|
|
228
|
+
├── src/daisi/ # Main package
|
|
229
|
+
│ ├── __init__.py
|
|
230
|
+
│ ├── client.py # Main unified client
|
|
231
|
+
│ ├── config.py # Configuration
|
|
232
|
+
│ ├── base_client.py # Base gRPC client
|
|
233
|
+
│ ├── exceptions.py # Custom exceptions
|
|
234
|
+
│ └── clients/ # Service-specific clients
|
|
235
|
+
│ ├── auth.py
|
|
236
|
+
│ ├── session.py
|
|
237
|
+
│ ├── inference.py
|
|
238
|
+
│ ├── models.py
|
|
239
|
+
│ ├── hosts.py
|
|
240
|
+
│ ├── peers.py
|
|
241
|
+
│ ├── settings.py
|
|
242
|
+
│ └── commands.py
|
|
243
|
+
├── protos/v1/ # Protobuf definitions
|
|
244
|
+
│ ├── *.proto # Service definitions
|
|
245
|
+
│ └── models/ # Model definitions
|
|
246
|
+
├── src/protos/ # Generated Python code
|
|
247
|
+
├── tests/ # Test suite
|
|
248
|
+
├── pyproject.toml # Project configuration
|
|
249
|
+
├── generate_protos.py # Proto generation script
|
|
250
|
+
└── README.md
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Architecture
|
|
254
|
+
|
|
255
|
+
The SDK is built on gRPC and Protocol Buffers, matching the .NET SDK architecture:
|
|
256
|
+
|
|
257
|
+
- **gRPC**: Efficient binary protocol with streaming support
|
|
258
|
+
- **Protocol Buffers**: Strongly-typed message definitions
|
|
259
|
+
- **Session-based**: Orchestrator (Orc) manages session lifecycle
|
|
260
|
+
- **Streaming**: Real-time token-by-token inference responses
|
|
261
|
+
- **Direct Connect**: Optional peer-to-peer mode
|
|
262
|
+
|
|
263
|
+
## Contributing
|
|
264
|
+
|
|
265
|
+
Contributions are welcome! Ensure:
|
|
266
|
+
|
|
267
|
+
1. Code follows PEP 8 with Black formatting
|
|
268
|
+
2. All tests pass and coverage is maintained
|
|
269
|
+
3. Type hints are included
|
|
270
|
+
4. Documentation is updated
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
MIT License - see LICENSE file for details
|
|
275
|
+
|
|
276
|
+
## Links
|
|
277
|
+
|
|
278
|
+
- [Daisi Website](https://daisi.net)
|
|
279
|
+
- [.NET SDK](https://github.com/daisinet/daisi-sdk-dotnet)
|
|
280
|
+
- [Documentation](https://daisi.ai/Learn/SDK)
|