Skip to content

Commit 1d66bba

Browse files
authored
Merge pull request #83 from singnet/development
Training v2
2 parents ed13dab + f84e523 commit 1d66bba

57 files changed

Lines changed: 3498 additions & 853 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ print(messages)
265265
# {'Numbers': [('float', 'a'), ('float', 'b')], 'Result': [('float', 'value')]}
266266
```
267267

268+
## Training
269+
270+
With the SDK, you can also train models and use them when calling the service.
271+
272+
273+
268274
---
269275

270276
###### 1 This method uses a call to a paid smart contract function.

docs/main/account.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ is extended by: -
2626

2727
#### description
2828

29-
`TransactionError` is a custom exception class that is raised when an Ethereum transaction receipt has a status of 0.
29+
`TransactionError` is a custom exception class that is raised when an Ethereum transaction receipt has a status of 0.
3030
This indicates that the transaction failed. Can provide a custom message. Optionally includes receipt
3131

3232
#### attributes

docs/main/client_lib_generator.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ Entities:
66
1. [ClientLibGenerator](#class-clientlibgenerator)
77
- [\_\_init\_\_](#__init__)
88
- [generate_client_library](#generate_client_library)
9+
- [generate_directories_by_params](#generate_directories_by_params)
10+
- [create_service_client_libraries_path](#create_service_client_libraries_path)
11+
- [receive_proto_files](#receive_proto_files)
12+
- [training_added](#training_added)
913

1014
### Class `ClientLibGenerator`
1115

@@ -36,6 +40,7 @@ Initializes a new instance of the class. Initializes the attributes by arguments
3640
- `metadata_provider` (StorageProvider): An instance of the `StorageProvider` class.
3741
- `org_id` (str): The organization ID of the service.
3842
- `service_id` (str): The service ID.
43+
- `protodir` (Path | None): The directory where the .proto files are located. Default is _None_.
3944

4045
###### returns:
4146

@@ -51,3 +56,42 @@ Generates client library stub files based on specified organization and service
5156
###### returns:
5257

5358
- _None_
59+
60+
#### `generate_directories_by_params`
61+
62+
Generates directories for client library in the `~/.snet` directory based on organization and
63+
service ids using the `create_service_client_libraries_path` method.
64+
65+
###### returns:
66+
67+
- _None_
68+
69+
#### `create_service_client_libraries_path`
70+
71+
Creates a directory for client library in the `~/.snet` directory based on organization and
72+
service ids.
73+
74+
###### returns:
75+
76+
- _None_
77+
78+
#### `receive_proto_files`
79+
80+
Receives .proto files from IPFS or FileCoin based on service metadata and extracts them to a
81+
given directory.
82+
83+
###### returns:
84+
85+
- _None_
86+
87+
###### raises:
88+
89+
- Exception: if the directory for storing proto files is not found.
90+
91+
#### `training_added`
92+
93+
Checks whether training is used in the service .proto file.
94+
95+
###### returns:
96+
97+
- _True_ if training is used in the service .proto file, _False_ otherwise.

docs/main/init.md

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Entities:
77
- [\_\_init\_\_](#__init__)
88
- [create_service_client](#create_service_client)
99
- [get_service_stub](#get_service_stub)
10-
- [get_path_to_pb_files](#get_path_to_pb_files)
1110
- [get_module_by_keyword](#get_module_by_keyword)
1211
- [get_service_metadata](#get_service_metadata)
1312
- [_get_first_group](#_get_first_group)
@@ -62,7 +61,7 @@ contract. Instantiates the Account object with the specified Web3 client, SDK co
6261

6362
If `force_update` is True or if there are no gRPC stubs for the given service, the proto files are loaded
6463
and compiled using the `generate_client_library()` method of the `ClientLibGenerator` class instance.
65-
It then initializes `payment_channel_management_strategy` to `DefaultPaymentStrategy` if it is not specified.
64+
It then initializes `payment_strategy` to `DefaultPaymentStrategy` if it is not specified.
6665
It also sets the `options` dictionary with some default values. If `self._metadata_provider` is not specified
6766
it is initialized by `IPFSMetadataProvider`. It also gets the service stub using the `self.get_service_stub`
6867
method and the pb2 module using the `self.get_module_by_keyword` method. Finally, it creates a new instance
@@ -73,7 +72,7 @@ of the `ServiceClient` class with all the required parameters, which is then ret
7372
- `org_id` (str): The ID of the organization.
7473
- `service_id` (str): The ID of the service.
7574
- `group_name` (str): The name of the payment group. Defaults to _None_.
76-
- `payment_channel_management_strategy` (PaymentStrategy): The payment channel management strategy. Defaults to _None_.
75+
- `payment_strategy` (PaymentStrategy): The payment channel management strategy. Defaults to _None_.
7776
- `free_call_auth_token_bin` (str): The free call authentication token in binary format. Defaults to _None_.
7877
- `free_call_token_expiry_block` (int): The block number when the free call token expires. Defaults to _None_.
7978
- `options` (dict): Additional options for the service client. Defaults to _None_.
@@ -100,19 +99,6 @@ Retrieves the gRPC service stub for the given organization and service ID.
10099

101100
- Exception: If an error occurs while importing a module.
102101

103-
#### `get_path_to_pb_files`
104-
105-
Returns the path to the directory containing the protobuf files for a given organization and service.
106-
107-
###### args:
108-
109-
- `org_id` (str): The ID of the organization.
110-
- `service_id` (str): The ID of the service.
111-
112-
###### returns:
113-
114-
- The path to the directory containing the protobuf files. (str)
115-
116102
#### `get_module_by_keyword`
117103

118104
Retrieves the module name from the given organization ID, service ID, and keyword.

docs/main/service_client.md

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Entities:
66
1. [ServiceClient](#class-serviceclient)
77
- [\_\_init\_\_](#__init__)
88
- [call_rpc](#call_rpc)
9+
- [_get_service_stub](#_get_service_stub)
910
- [_generate_grpc_stub](#_generate_grpc_stub)
1011
- [get_grpc_base_channel](#get_grpc_base_channel)
1112
- [_get_grpc_channel](#_get_grpc_channel)
12-
- [_get_service_call_metadata](#_get_service_call_metadata)
1313
- [_filter_existing_channels_from_new_payment_channels](#_filter_existing_channels_from_new_payment_channels)
1414
- [load_open_channels](#load_open_channels)
1515
- [get_current_block_number](#get_current_block_number)
@@ -23,10 +23,11 @@ Entities:
2323
- [generate_training_signature](#generate_training_signature)
2424
- [get_free_call_config](#get_free_call_config)
2525
- [get_service_details](#get_service_details)
26+
- [training](#training)
27+
- [_get_training_model_id](#_get_training_model_id)
2628
- [get_concurrency_flag](#get_concurrency_flag)
2729
- [get_concurrency_token_and_channel](#get_concurrency_token_and_channel)
2830
- [set_concurrency_token_and_channel](#set_concurrency_token_and_channel)
29-
- [get_path_to_pb_files](#get_path_to_pb_files)
3031
- [get_services_and_messages_info](#get_services_and_messages_info)
3132
- [get_services_and_messages_info_as_pretty_string](#get_services_and_messages_info_as_pretty_string)
3233

@@ -58,14 +59,16 @@ the `PaymentStrategy` inheritor classes.
5859
- `payment_channel_provider` (PaymentChannelProvider): An instance of the `PaymentChannelProvider` class for
5960
working with channels and interacting with MPE.
6061
- `payment_channel_state_service_client` (Any): Stub for interacting with PaymentChannelStateService via gRPC.
61-
- `service` (Any): The gRPC service stub instance.
62+
- `service_stubs` (Any): The gRPC service stubs.
6263
- `pb2_module` (ModuleType): The imported protobuf module.
6364
- `payment_channels` (list[PaymentChannel]): The list of payment channels.
6465
- `last_read_block` (int): The last read block number.
6566
- `account` (Account): An instance of the `Account` class for interacting with the MultiPartyEscrow and
6667
SingularityNetToken contracts.
6768
- `sdk_web3` (Web3): The `Web3` instance.
6869
- `mpe_address` (str): The MPE contract address.
70+
- `path_to_pb_files` (Path): The path to the protobuf files.
71+
- `__training` (Training): An instance of the `Training` class.
6972

7073
#### methods
7174

@@ -79,14 +82,16 @@ Initializes a new instance of the class.
7982
- `service_id` (str): The ID of the service.
8083
- `service_metadata` (MPEServiceMetadata): The metadata for the service.
8184
- `group` (dict): The payment group from the service metadata.
82-
- `service_stub` (ServiceStub): The gRPC service stub.
85+
- `service_stubs` (list[ServiceStub]): The gRPC service stubs.
8386
- `payment_strategy` (PaymentStrategy): The payment channel management strategy.
8487
- `options` (dict): Additional options for the service client.
8588
- `mpe_contract` (MPEContract): The MPE contract instance.
8689
- `account` (Account): An instance of the `Account` class.
8790
- `sdk_web3` (Web3): The `Web3` instance.
8891
- `pb2_module` (str | ModuleType): The module containing the gRPC message definitions.
8992
- `payment_channel_provider` (PaymentChannelProvider): The payment channel provider instance.
93+
- `path_to_pb_files` (Path): The path to the protobuf files.
94+
- `training_added` (bool): Whether training enabled on the service or not.
9095

9196
###### returns:
9297

@@ -107,6 +112,18 @@ that are passed to the called method as arguments.
107112

108113
- The response from the RPC method call. (Any)
109114

115+
#### `_get_service_stub`
116+
117+
Generates a gRPC stub instance for all the service stubs and returns one which matches the rpc name.
118+
119+
###### args:
120+
121+
- `rpc_name` (str): The name of the RPC method to call.
122+
123+
###### returns:
124+
125+
- service_stub (Any): The gRPC service stub.
126+
110127
#### `_generate_grpc_stub`
111128

112129
Generates a gRPC stub instance for the given service stub.
@@ -148,16 +165,6 @@ a ValueError is raised with an error message.
148165

149166
- ValueError: If the scheme in the service metadata is neither "http" nor "https".
150167

151-
#### `_get_service_call_metadata`
152-
153-
Retrieves the metadata required for making a service call using the payment strategy.
154-
155-
###### returns:
156-
157-
- Payment metadata. (list[tuple[str, Any]])
158-
159-
<!-- TODO: implement method "_intercept_call"-->
160-
161168
#### `_filter_existing_channels_from_new_payment_channels`
162169

163170
Filters the new channel list so that only those that are not yet among the existing ones remain,
@@ -300,6 +307,30 @@ Retrieves the details of the service.
300307
- A tuple containing the organization ID, service ID, group ID, and the first endpoint for the group.
301308
(tuple[str, str, str, str])
302309

310+
#### `training`
311+
312+
Property that returns the training object associated with the service.
313+
314+
###### returns:
315+
316+
- The training object associated with the service. (Training)
317+
318+
###### raises:
319+
320+
- NoTrainingException: If training is not implemented for the service.
321+
322+
#### `_get_training_model_id`
323+
324+
Converts model ID from `str` to stub object.
325+
326+
###### args:
327+
328+
- `model_id` (str): The model ID to convert.
329+
330+
###### returns:
331+
332+
- The stub object for the model ID. (Any)
333+
303334
#### `get_concurrency_flag`
304335

305336
Returns the value of the `concurrency` option from the `self.options` dict.
@@ -330,19 +361,6 @@ Sets the concurrency token and channel for the payment strategy.
330361

331362
- _None_
332363

333-
#### `get_path_to_pb_files`
334-
335-
Returns the path to the directory containing the protobuf files for a given organization and service.
336-
337-
###### args:
338-
339-
- `org_id` (str): The ID of the organization.
340-
- `service_id` (str): The ID of the service.
341-
342-
###### returns:
343-
344-
- The path to the directory containing the protobuf files. (str)
345-
346364
#### `get_services_and_messages_info`
347365

348366
Retrieves information about services and messages defined in a protobuf file.

docs/payment_strategies/freecall_payment_strategy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ _Note_: If any exception occurs during the process, it returns False.
4242

4343
#### `get_payment_metadata`
4444

45-
Retrieves the payment metadata for a service client with the field `snet-paument-type` equals to `free-call`
45+
Retrieves the payment metadata for a service client with the field `snet-payment-type` equals to `free-call`
4646
using the provided free call configuration.
4747

4848
###### args:

docs/payment_strategies/paidcall_payment_strategy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Entities:
1515

1616
extends: `PaymentStrategy`
1717

18-
is extended by: -
18+
is extended by: `TrainingPaymentStrategy`
1919

2020
#### description
2121

@@ -57,7 +57,7 @@ Returns the price of the service call using service client.
5757

5858
#### `get_payment_metadata`
5959

60-
Creates and returns the payment metadata for a service client with the field `snet-paument-type` equals to `escrow`.
60+
Creates and returns the payment metadata for a service client with the field `snet-payment-type` equals to `escrow`.
6161

6262
###### args:
6363

docs/payment_strategies/prepaid_payment_strategy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Returns the price of the service calls using service client.
6161

6262
#### `get_payment_metadata`
6363

64-
Creates and returns the payment metadata for a service client with the field `snet-paument-type` equals
64+
Creates and returns the payment metadata for a service client with the field `snet-payment-type` equals
6565
to `prepaid-call`.
6666

6767
###### args:

0 commit comments

Comments
 (0)