While each Modus SDK offers similar capabilities, the APIs and usage may vary between languages.Modus Models APIs documentation is available on the following pages:
- AssemblyScript Models APIs
- Go Models APIs(this page)
Import
To begin, import themodels package from the SDK:
Models APIs
The APIs in themodels package are below, organized by category.
Functions
GetModel
Get a model instance by name and type.The type of model to return. This can be any struct that implements the
Model interface.The name of the model to retrieve. This must match the name of a model defined
in your project’s manifest file.
Types
Model
The interface that all Modus models must implement.The type of the input data for the model. This can be any type, including a
custom type defined in your project. It should match the shape of the data
expected by the model. It is usually a struct.
The type of the output data from the model. This can be any type, including a
custom type defined in your project. It should match the shape of the data
returned by the model. It is usually a struct.
Returns information about the model set by the Modus Runtime when creating the
instance. See the
ModelInfo object for more information.Invokes the model with input data and returns the output data.
ModelBase
The base type for all models that Modus functions can invoke.The type of the input data for the model. This can be any type, including a
custom type defined in your project. It should match the shape of the data
expected by the model. It is usually a struct.
The type of the output data from the model. This can be any type, including a
custom type defined in your project. It should match the shape of the data
returned by the model. It is usually a struct.
A flag to enable debug mode for the model. When enabled, Modus automatically
logs the full request and response data to the console. Implementations can
also use this flag to enable additional debug logging. Defaults to
false.Returns information about the model set by the Modus Runtime when creating the
instance. See the
ModelInfo object for more information.Invokes the model with input data and returns the output data.
ModelInfo
Information about a model that’s used to construct aModel instance. It is
also available from a method on the Model interface.
This struct relays information from the Modus runtime to the model
implementation. Generally, you don’t need to create
ModelInfo instances
directly.However, if you are implementing a custom model, you may wish to use a field
from this struct, such as FullName, for model providers that require the model
name in the input request body.The name of the model from the app manifest.
The full name or identifier of the model, as defined by the model provider.