Modularize and re-use Chainlet implementations
MyBaseChainlet
works with integer inputs and returns floats. If
you want to reuse the computation, but provide an alternative interface (e.g.
for a different client with different request/response schema), you can create
a subclass which does the I/O conversion. The actual computation is delegated to
the base classes above.
MyBaseChainlet
uses preprocessing that doubles the input. If
you want to use a different variant of preprocessing - while keeping
MyBaseChainlet.run_remote
and everything else as is - you can define a shallow
subclass of MyBaseChainlet
where you use a different dependency
Preprocess8x
, which multiplies by 8 instead of 2.
remote_config
.
remote_config
is a class variable. In the example above we
created a completely new RemoteConfig
value, because changing fields
inplace would also affect the base class.If you want to share config between the base class and subclasses, you can
define them in additional variables e.g. for the image: