Module: node
Module containing the NodeClient class, which is a client for the Infernet Node's REST API.
Example Usage
You can use the Node client as follows:
from infernet_client import NodeClient
client = NodeClient("http://localhost:8000")
# Check the node's health
client.health()
# Get information about the node
client.get_info()
NodeClient
Source code in src/infernet_client/node.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
|
__init__(base_url)
Initializes the client
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_url |
str
|
The base URL of the REST server |
required |
check_model_support(model_id, timeout=1)
async
Checks model support on each container
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_id |
str
|
The ID of the model to check support for |
required |
timeout |
int
|
The timeout for the request. Defaults to 1. |
1
|
Returns:
Type | Description |
---|---|
dict[str, ModelSupport]
|
dict[str, ModelSupport]: Returns support of the model by container. |
Raises:
Type | Description |
---|---|
ClientResponseError
|
If the request returns an error code |
TimeoutError
|
If the request times out |
Source code in src/infernet_client/node.py
get_info(timeout=1)
async
Retrieves node info
Fetches containers running on this node, the number of jobs pending, and chain information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
int
|
The timeout for the request. Defaults to 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
NodeInfo |
NodeInfo
|
The node info object |
Raises:
Type | Description |
---|---|
ClientResponseError
|
If the request returns an error code |
TimeoutError
|
If the request times out |
Source code in src/infernet_client/node.py
get_job_result_sync(job_id, retries=5, timeout=5)
async
Retrieves job result synchronously
Repeatedly polls the server for the job result until the job is no longer running or the maximum number of retries is reached.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job_id |
JobID
|
The job ID |
required |
retries |
int
|
The number of retries if the job is still running. Each retry waits for 1 second before polling again. Defaults to 5. |
5
|
timeout |
int
|
The timeout for the request. Defaults to 5. |
5
|
Returns:
Type | Description |
---|---|
Optional[JobResult]
|
Optional[JobResult]: The job result, or None if the job is not found |
Raises:
Type | Description |
---|---|
APIError
|
If the job status is "failed" or the request returns an error code |
TimeoutError
|
If the request times out |
TimeoutError
|
If the job result is not available after the maximum number of retries |
Source code in src/infernet_client/node.py
get_job_results(job_ids, intermediate=False, timeout=5)
async
Retrieves job results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job_ids |
list[JobID]
|
The list of job IDs |
required |
intermediate |
bool
|
Whether to return intermediate results (only applicable for when multiple containers are chained). Defaults to False. |
False
|
timeout |
int
|
The timeout for the request. Defaults to 5. |
5
|
Returns:
Type | Description |
---|---|
list[JobResult]
|
list[JobResult]: The list of job results |
Raises:
Type | Description |
---|---|
ClientResponseError
|
If the request returns an error code |
TimeoutError
|
If the request times out |
Source code in src/infernet_client/node.py
get_jobs(pending=None, timeout=5)
async
Retrieves a list of job IDs for this client
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pending |
Optional[bool]
|
If True, only pending jobs are returned. If False, only completed jobs are returned. By default, all jobs are returned. |
None
|
timeout |
int
|
The timeout for the request. Defaults to 5. |
5
|
Returns:
Type | Description |
---|---|
list[JobID]
|
list[JobID]: The list of job IDs |
Raises:
Type | Description |
---|---|
ClientResponseError
|
If the request returns an error code |
TimeoutError
|
If the request times out |
Source code in src/infernet_client/node.py
get_resources(timeout=1)
async
Collects container resources on the node
Returns:
Type | Description |
---|---|
dict[str, ServiceResources]
|
dict[str, ServiceResources]: Returns full resources of each container. |
dict[str, ServiceResources]
|
See infernet-ml.docs.ritual.net/reference/infernet_ml/utils/spec/#infernet_ml.utils.spec.ServiceResources for details. |
Raises:
Type | Description |
---|---|
ClientResponseError
|
If the request returns an error code |
TimeoutError
|
If the request times out |
Source code in src/infernet_client/node.py
health(timeout=1)
async
Server health check
Parameters:
Name | Type | Description | Default |
---|---|---|---|
timeout |
int
|
The timeout for the health check. Defaults to 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the server is healthy, False otherwise |
Raises:
Type | Description |
---|---|
ClientResponseError
|
If the health check returns an error code |
TimeoutError
|
If the health check times out |
Source code in src/infernet_client/node.py
record_status(id, status, job, timeout=5)
async
Manually records the status of a job with the node.
NOTE: DO NOT USE THIS FUNCTION IF YOU DON'T KNOW WHAT YOU'RE DOING.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id |
JobID
|
The ID of the job |
required |
status |
JobStatus
|
The status of the job |
required |
job |
JobRequest
|
The job request |
required |
timeout |
int
|
The timeout for the request. Defaults to 5. |
5
|
Raises:
Type | Description |
---|---|
Exception
|
If the job status cannot be recorded |
Source code in src/infernet_client/node.py
request_delegated_subscription(subscription, rpc, coordinator_address, expiry, nonce, private_key, data, timeout=5)
async
Creates a new delegated subscription
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subscription |
Subscription
|
The subscription object |
required |
rpc |
RPC
|
The RPC client |
required |
coordinator_address |
ChecksumAddress
|
The coordinator contract address |
required |
expiry |
int
|
The expiry of the subscription, in seconds (UNIX timestamp) |
required |
nonce |
int
|
The nonce of the subscription signing |
required |
private_key |
str
|
The private key of the subscriber |
required |
data |
dict[str, Any]
|
The input data for the first container |
required |
timeout |
int
|
The timeout for the request. Defaults to 5. |
5
|
Raises:
Type | Description |
---|---|
APIError
|
If the request returns an error code |
Source code in src/infernet_client/node.py
request_job(job, timeout=5)
async
Requests an asynchronous job
Returns the job ID if the request is successful. Otherwise, raises an exception. Job status and results can be retrieved asynchronously using the job ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job |
JobRequest
|
The job request |
required |
timeout |
int
|
The timeout for the request. Defaults to 5. |
5
|
Returns:
Name | Type | Description |
---|---|---|
JobID |
JobID
|
The ID of the job |
Raises:
Type | Description |
---|---|
ClientResponseError
|
If the request returns an error code |
TimeoutError
|
If the request times out |
Source code in src/infernet_client/node.py
request_jobs(jobs, timeout=10)
async
Requests asynchronous jobs in batch
For each job request, the server returns a job ID if the request is successful, or an error response otherwise. Job status and results can be retrieved asynchronously using the job ID.
Note
The order of the responses corresponds to the order of the job requests. It is the responsibility of the caller to match the responses with the requests, and handle errors appropriately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
jobs |
list[JobRequest]
|
The list of job requests |
required |
timeout |
int
|
The timeout for the request. Defaults to 10. |
10
|
Returns:
Type | Description |
---|---|
list[Union[JobResponse, ErrorResponse]]
|
list[Union[JobResponse, ErrorResponse]]: The list of job IDs or error |
list[Union[JobResponse, ErrorResponse]]
|
responses for each job request. |
Raises:
Type | Description |
---|---|
ClientResponseError
|
If the request returns an error code |
TimeoutError
|
If the request times out |
Source code in src/infernet_client/node.py
request_stream(job, timeout=180)
async
Requests a streaming job
Parameters:
Name | Type | Description | Default |
---|---|---|---|
job |
JobRequest
|
The streaming job request |
required |
timeout |
int
|
The timeout for the request. Since this is a synchronous request, the timeout is the maximum time to wait for the server to finish streaming the response. Defaults to 180. |
180
|
Yields:
Type | Description |
---|---|
AsyncGenerator[Union[str, bytes], None]
|
Union[str, bytes]: The job ID followed by the output of the job |
Raises:
Type | Description |
---|---|
ClientResponseError
|
If the request returns an error code |
TimeoutError
|
If the request times out |