Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b539ae7
Create tests for client_lib_generator module
mabredin Nov 21, 2024
a7cf70d
Add some new tests
mabredin Nov 24, 2024
18116fa
Add typing in some modules
mabredin Nov 29, 2024
2d02e13
Implemented base part of the training v2.
Arondondon Dec 2, 2024
00e68f8
Updated proto and stubs, implemented method name check, changed uploa…
Arondondon Dec 3, 2024
3f57f2f
Implemented correct payment, checking the availability of training an…
Arondondon Dec 4, 2024
95fd649
Added specific exceptions and typing
Arondondon Dec 5, 2024
7083ce0
Code refactoring, changed .proto and pb files, moved some functions, …
Arondondon Dec 26, 2024
5f7417b
Changed .proto and pb files, added response classes.
Arondondon Jan 16, 2025
2113915
Added training payment strategy. Updated response models.
Arondondon Jan 29, 2025
1bfe165
Added availability to call services with several grpc services in one…
Arondondon Feb 12, 2025
42d6ffd
Updated training .proto file.
Arondondon Feb 12, 2025
8fb5c94
Updated training .proto files. Fixed bug with _check_dataset method.…
Arondondon Feb 19, 2025
17a9d1a
Added pb files
Arondondon Feb 19, 2025
a6033dc
Added new exception. Fixed bug with message in signature.
Arondondon Feb 20, 2025
49f050d
Updated existing files with the documentation. Added several new files.
Arondondon Feb 20, 2025
e3e08e5
Fully updated documentation
Arondondon Feb 21, 2025
185aac4
Updated docs main page
Arondondon Feb 24, 2025
7eb3d83
Fixed test_sdk_client
Arondondon Feb 24, 2025
31cab44
Fixed tests
Arondondon Feb 24, 2025
1a5a679
Fixed training check
Arondondon Feb 24, 2025
2592b0b
Fixed training check x2
Arondondon Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ print(messages)
# {'Numbers': [('float', 'a'), ('float', 'b')], 'Result': [('float', 'value')]}
```

## Training

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



---

###### 1 This method uses a call to a paid smart contract function.
Expand Down
2 changes: 1 addition & 1 deletion docs/main/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ is extended by: -

#### description

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

#### attributes
Expand Down
44 changes: 44 additions & 0 deletions docs/main/client_lib_generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Entities:
1. [ClientLibGenerator](#class-clientlibgenerator)
- [\_\_init\_\_](#__init__)
- [generate_client_library](#generate_client_library)
- [generate_directories_by_params](#generate_directories_by_params)
- [create_service_client_libraries_path](#create_service_client_libraries_path)
- [receive_proto_files](#receive_proto_files)
- [training_added](#training_added)

### Class `ClientLibGenerator`

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

###### returns:

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

- _None_

#### `generate_directories_by_params`

Generates directories for client library in the `~/.snet` directory based on organization and
service ids using the `create_service_client_libraries_path` method.

###### returns:

- _None_

#### `create_service_client_libraries_path`

Creates a directory for client library in the `~/.snet` directory based on organization and
service ids.

###### returns:

- _None_

#### `receive_proto_files`

Receives .proto files from IPFS or FileCoin based on service metadata and extracts them to a
given directory.

###### returns:

- _None_

###### raises:

- Exception: if the directory for storing proto files is not found.

#### `training_added`

Checks whether training is used in the service .proto file.

###### returns:

- _True_ if training is used in the service .proto file, _False_ otherwise.
18 changes: 2 additions & 16 deletions docs/main/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Entities:
- [\_\_init\_\_](#__init__)
- [create_service_client](#create_service_client)
- [get_service_stub](#get_service_stub)
- [get_path_to_pb_files](#get_path_to_pb_files)
- [get_module_by_keyword](#get_module_by_keyword)
- [get_service_metadata](#get_service_metadata)
- [_get_first_group](#_get_first_group)
Expand Down Expand Up @@ -62,7 +61,7 @@ contract. Instantiates the Account object with the specified Web3 client, SDK co

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

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

#### `get_path_to_pb_files`

Returns the path to the directory containing the protobuf files for a given organization and service.

###### args:

- `org_id` (str): The ID of the organization.
- `service_id` (str): The ID of the service.

###### returns:

- The path to the directory containing the protobuf files. (str)

#### `get_module_by_keyword`

Retrieves the module name from the given organization ID, service ID, and keyword.
Expand Down
72 changes: 45 additions & 27 deletions docs/main/service_client.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Entities:
1. [ServiceClient](#class-serviceclient)
- [\_\_init\_\_](#__init__)
- [call_rpc](#call_rpc)
- [_get_service_stub](#_get_service_stub)
- [_generate_grpc_stub](#_generate_grpc_stub)
- [get_grpc_base_channel](#get_grpc_base_channel)
- [_get_grpc_channel](#_get_grpc_channel)
- [_get_service_call_metadata](#_get_service_call_metadata)
- [_filter_existing_channels_from_new_payment_channels](#_filter_existing_channels_from_new_payment_channels)
- [load_open_channels](#load_open_channels)
- [get_current_block_number](#get_current_block_number)
Expand All @@ -23,10 +23,11 @@ Entities:
- [generate_training_signature](#generate_training_signature)
- [get_free_call_config](#get_free_call_config)
- [get_service_details](#get_service_details)
- [training](#training)
- [_get_training_model_id](#_get_training_model_id)
- [get_concurrency_flag](#get_concurrency_flag)
- [get_concurrency_token_and_channel](#get_concurrency_token_and_channel)
- [set_concurrency_token_and_channel](#set_concurrency_token_and_channel)
- [get_path_to_pb_files](#get_path_to_pb_files)
- [get_services_and_messages_info](#get_services_and_messages_info)
- [get_services_and_messages_info_as_pretty_string](#get_services_and_messages_info_as_pretty_string)

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

#### methods

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

###### returns:

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

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

#### `_get_service_stub`

Generates a gRPC stub instance for all the service stubs and returns one which matches the rpc name.

###### args:

- `rpc_name` (str): The name of the RPC method to call.

###### returns:

- service_stub (Any): The gRPC service stub.

#### `_generate_grpc_stub`

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

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

#### `_get_service_call_metadata`

Retrieves the metadata required for making a service call using the payment strategy.

###### returns:

- Payment metadata. (list[tuple[str, Any]])

<!-- TODO: implement method "_intercept_call"-->

#### `_filter_existing_channels_from_new_payment_channels`

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

#### `training`

Property that returns the training object associated with the service.

###### returns:

- The training object associated with the service. (Training)

###### raises:

- NoTrainingException: If training is not implemented for the service.

#### `_get_training_model_id`

Converts model ID from `str` to stub object.

###### args:

- `model_id` (str): The model ID to convert.

###### returns:

- The stub object for the model ID. (Any)

#### `get_concurrency_flag`

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

- _None_

#### `get_path_to_pb_files`

Returns the path to the directory containing the protobuf files for a given organization and service.

###### args:

- `org_id` (str): The ID of the organization.
- `service_id` (str): The ID of the service.

###### returns:

- The path to the directory containing the protobuf files. (str)

#### `get_services_and_messages_info`

Retrieves information about services and messages defined in a protobuf file.
Expand Down
2 changes: 1 addition & 1 deletion docs/payment_strategies/freecall_payment_strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ _Note_: If any exception occurs during the process, it returns False.

#### `get_payment_metadata`

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

###### args:
Expand Down
4 changes: 2 additions & 2 deletions docs/payment_strategies/paidcall_payment_strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Entities:

extends: `PaymentStrategy`

is extended by: -
is extended by: `TrainingPaymentStrategy`

#### description

Expand Down Expand Up @@ -57,7 +57,7 @@ Returns the price of the service call using service client.

#### `get_payment_metadata`

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

###### args:

Expand Down
2 changes: 1 addition & 1 deletion docs/payment_strategies/prepaid_payment_strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Returns the price of the service calls using service client.

#### `get_payment_metadata`

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

###### args:
Expand Down
Loading