//clika-runtime/io.clika.runtime/FunctionModel
FunctionModel
[common]
class FunctionModel
A serving model whose phases are Kotlin bodies: declare the contract, bind each phase (and the state factory of a stateful model), then hand it to an Executor or a Pipeline. A phase bound after an executor or a pipeline was created over the model is not one it runs. AutoCloseable; close refuses while an executor or a pipeline holds the model.
val model = FunctionModel(ModelSchema(inputs = listOf(TensorSpec("x")), outputs = listOf(TensorSpec("y"))))
model.onRunOnce("run") { ctx -> ctx.input("x").use { x -> Ops.mul(x, 2.0).use { y -> ctx.setOutput("y", y) } } }
Constructors
| FunctionModel | [common] constructor(schema: ModelSchema) A model carrying schema whose phases are bound as bodies. |
Types
| Name | Summary |
|---|---|
| Companion | [common] object Companion |
Properties
| Name | Summary |
|---|---|
| schema | [common] val schema: ModelSchema |
Functions
| Name | Summary |
|---|---|
| close | [common] open fun close() |
| onIterate | [common] fun onIterate(name: String, body: IterateBody): FunctionModel Bind the body of the iterate phase named name (stepped over the active batch until each session finishes). Returns this for chaining. |
| onRunOnce | [common] fun onRunOnce(name: String, body: RunOnceBody): FunctionModel Bind the body of the run-once phase named name (a single pass per session). Returns this for chaining. |
| withState | [common] fun withState(factory: StateFactory): FunctionModel Set the per-session state factory (a stateful model only). Returns this for chaining. |