Model customization

Credmark uses a simple base class called ‘Model’ class to set up a model.

All Models should import this class import credmark.cmf.model and can override the run() method.

The @Model.describe() decorator provides a simple interface to define the model properties such as slug, version, display_name, description, developer, input, output etc so that it can be used easily by consumers and other models.

If description is not specified, the __doc__ string of the model's class is used for the model description.

Let's make this model our own by customization.

The in-file instructions are the first things to do. Let's complete them and then remove the instruction comments. The resulting file is more concise.

from credmark.cmf.model import Model
from credmark.dto import EmptyInput

@Model.describe(slug='contrib.ape-count',
                version='1.0',
                display_name='Count how many transactions in the one block',
                description="Use ledger and some counting",
                input=EmptyInput,
                output=dict)
class ContribModel(Model):
    def run(self, input: EmptyInput) -> dict:
        return {}

Use credmark-dev describe with the mode slug to check whether we can load the model correctly. yay! There has been no error so far.

> credmark-dev describe contrib.ape-count

contrib.ape-count
 - slug: contrib.ape-count
 - version: 1.0
 - displayName: Count how many transactions in the one block
 - description: Use ledger and some counts
 - developer: 
 - tags: None
 - input schema (* for required field):
   EmptyInput(object)
 - input example:
   #01: {}
 - output schema (* for required field):
   Object(object)
 - output example:
   #01: {}
 - errors:
   No defined errors
 - class: models.contrib.ape.count.ContribModel

Last updated