Skip to content

Commit a9c839b

Browse files
authored
Merge pull request #88 from singnet/development
Fixed adding .proto files to the package, updated readme.md
2 parents d5ce719 + 8168da3 commit a9c839b

3 files changed

Lines changed: 104 additions & 5 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include snet/sdk/resources/*
1+
recursive-include snet/sdk/resources *
22

33
recursive-exclude * .git
44
recursive-exclude * node_modules

README.md

Lines changed: 102 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ SingularityNET SDK for Python
77

88
The package is published in PyPI at the following link:
99

10-
|Package |Description |
11-
|----------------------------------------------|---------------------------------------------------------------------|
12-
|[snet.sdk](https://pypi.org/project/snet.sdk/)|Integrate SingularityNET services seamlessly into Python applications|
10+
| Package |Description |
11+
|------------------------------------------------|---------------------------------------------------------------------|
12+
| [snet-sdk](https://pypi.org/project/snet-sdk/) |Integrate SingularityNET services seamlessly into Python applications|
1313

1414
### Core concepts
1515

@@ -198,6 +198,28 @@ payment_channel.extend_expiration(expiration=33333)
198198
payment_channel.extend_and_add_funds(amount=123456, expiration=33333)
199199
```
200200

201+
### Train call
202+
203+
Some of the training methods, namely `upload_and_validate` and `train_model`, are paid as well as the regular service call.
204+
Accordingly, you need to pay some AGIX to take advantage of the training. For this, as for a regular service call,
205+
you need a payment channel with the required amount of funds on it and expiration (in Python SDK, the selection,
206+
opening or adding funds to the channel is done automatically).
207+
208+
The only difference is that the price of a service call is a static number stored in the service metadata, whereas
209+
the price of calling the methods above is determined each time through the service provider before calling
210+
these methods. There are auxiliary methods `validate_model_price` and `train_model_price` respectively to determine
211+
the price of calling paid methods.
212+
213+
```python
214+
validate_price = service_client.training.validate_model_price(model_id)
215+
model_status = service_client.training.upload_and_validate(model_id, zip_path, validate_price)
216+
217+
# -------------------------------------------------------------------------------
218+
219+
train_price = service_client.training.train_model_price(model_id)
220+
model_status = service_client.training.train_model(model_id, train_price)
221+
```
222+
201223
## Other useful features
202224

203225
#### Get the current block number
@@ -269,7 +291,84 @@ print(messages)
269291

270292
With the SDK, you can also train models and use them when calling the service.
271293

294+
### Base pipeline
295+
296+
The sequence of basic actions is as follows:
297+
1) Create models
298+
2) Upload training dataset
299+
3) Train the model
300+
4) Call the service based on the new model
301+
302+
##### `create_model`
303+
304+
To create a new model you need to call the `create_model` method. It takes the following parameters:
305+
- `method_name` - name of the service method for which we want to create a new model
306+
(use [get_training_metadata](#get-training-metadata) method to get the list of available methods)
307+
- `model_name` - name of the new model (you need to come up with this)
308+
- `model_description`- description of the new model (optional)
309+
- `is_public_accessible` - whether the model is publicly accessible (optional, default: `False`)
310+
- `addresses_with_access` - list of addresses with access to the model (optional) (makes sense only if `is_public_accessible` is _False_)
311+
312+
and returns a `Model` object with all the model information.
313+
314+
```python
315+
new_model = service_client.training.create_model(method_name=grpc_method_name,
316+
model_name=model_name)
317+
model_id = new_model.model_id
318+
319+
print(new_model.status) # ModelStatus.CREATED
320+
```
321+
322+
##### `upload_and_validate`
323+
324+
To upload the training dataset you need to call the `upload_and_validate` method. It takes the following parameters:
325+
- `model_id` - id of the model
326+
- `zip_path` - path to archive file with the training dataset
327+
- `validate_price` - price of validating the dataset
328+
329+
and returns a `ModelStatus` object.
330+
331+
```python
332+
validate_price = service_client.training.validate_model_price(model_id)
333+
zip_path = "PATH_TO_YOUR_DATASET_FILE"
334+
model_status = service_client.training.upload_and_validate(model_id, zip_path, validate_price)
335+
336+
print(model_status) # ModelStatus.VALIDATING
337+
```
338+
339+
> Note: Dataset validation usually takes some time, so you should wait for the `VALIDATED` status of the model
340+
> (using the `get_model` or `get_all_models` methods) after sending the dataset for validation before proceeding
341+
> further with the model.
342+
343+
##### `train_model`
344+
345+
To train the model on an uploaded dataset you need to call the `train_model` method. It takes the following parameters:
346+
- `model_id` - id of the model
347+
- `train_price` - price of training the model
348+
349+
and returns a `ModelStatus` object.
350+
351+
```python
352+
train_price = service_client.training.train_model_price(model_id)
353+
model_status = service_client.training.train_model(model_id, train_price)
354+
355+
print(model_status) # ModelStatus.TRAINING
356+
```
357+
358+
> Note: Model training usually takes some time, so you should wait for the `READY_TO_USE` status of the model
359+
> (using the `get_model` or `get_all_models` methods) after calling the `train_model` method before proceeding
360+
> further with the model.
361+
362+
Finally, to call the service, you must call the `call_rpc` method of the `ServiceClient` instance with an
363+
additional parameter `model_id` in a similar way:
364+
365+
```python
366+
result = service_client.call_rpc(grpc_method_name, grpc_message_name, model_id=model_id, **parameters)
367+
```
272368

369+
For more detailed description please refer to Developer Portal guides:
370+
- [Service Training via SDK]()
371+
- [Training in Python SDK]()
273372

274373
---
275374

version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.7.1"
1+
__version__ = "3.7.2"

0 commit comments

Comments
 (0)