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:

The Modus Models APIs allow you to invoke AI models directly from your functions, irrespective of the model’s host.

Since many models have unique interfaces, the design of the Models APIs are extremely flexible. An interface and common base type forms the core of the APIs, which extends to conform to any model’s required schema.

The SDK contains both the base types and pre-defined implementations for many commonly used models. You can either use one of the pre-defined model types, or can create custom types for any model you like, by following the same pattern as implemented in the pre-defined models.

For your reference, several complete examples for using the Models APIs are available in Model Invoking.

Each example demonstrates using different types of AI models for different purposes. However, the Models interface isn’t limited to these purposes. You can use it for any task that an AI model can perform.

Import

To begin, import the models package from the SDK:

import "github.com/hypermodeinc/modus/sdk/go/pkg/models"

You’ll also need to import one or more packages for the model you are working with. For example:

import "github.com/hypermodeinc/modus/sdk/go/pkg/models/openai"

If you would like to request a new model, please open an issue. You can also send a pull request, if you’d like to contribute a new model yourself.

Models APIs

The APIs in the models package are below, organized by category.

We’re constantly introducing new APIs through ongoing development with early users. Please open an issue if you have ideas on what would make Modus even more powerful for your next app!

Functions

GetModel

Get a model instance by name and type.

func GetModel[TModel](modelName string) (*TModel, error)
TModel
required

The type of model to return. This can be any struct that implements the Model interface.

modelName
string
required

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.

type Model[TIn, TOut any] interface {
  Info() *ModelInfo
  Invoke(input *TIn) (*TOut, error)
}
TIn
required

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’s usually a struct.

TOut
required

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’s usually a struct.

Info()
method

Returns information about the model set by the Modus Runtime when creating the instance. See the ModelInfo object for more information.

Invoke(input)
method

Invokes the model with input data and returns the output data.

ModelBase

The base type for all models that Modus functions can invoke.

If you are implementing a custom model, you’ll need to create a type alias based on this struct. You’ll also need structs to represent the input and output types for your model. See the implementations of the pre-defined models in the Modus GitHub repository for examples.

type ModelBase[TIn, TOut any] struct {
  Debug bool
}

// methods
func (ModelBase[TIn, TOut]) Info() *ModelInfo
func (ModelBase[TIn, TOut]) Invoke(input *TIn) (*TOut, error)
TIn
required

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’s usually a struct.

TOut
required

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’s usually a struct.

Debug
bool

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.

Info()
method

Returns information about the model set by the Modus Runtime when creating the instance. See the ModelInfo object for more information.

Invoke(input)
method

Invokes the model with input data and returns the output data.

ModelInfo

Information about a model that’s used to construct a Model instance. It’s 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.

type ModelInfo struct {
  Name string
  FullName string
}
Name
string

The name of the model from the app manifest.

FullName
string

The full name or identifier of the model, as defined by the model provider.