Skip to content

From legacy MLForm

Older examples used a class-shaped API:

const mlForm = new MLForm("/api/predict");
await mlForm.toHTMLElement(schema, container);

Use mountForm instead:

import { mountForm } from "mlform/kit";
import { transport } from "./transport";
const mounted = mountForm(container, {
transport,
schema,
});

Migration map:

Legacy Current
new MLForm(url) An application-owned Transport plus mountForm(...)
toHTMLElement(...) mountForm(...)
inputs collection fields collection
outputs collection reports collection
field type field kind
field title field label
onSubmit callback hooks.afterSubmit or await mounted.submit()
mlform/extensions strategies Definitions and presenters packaged through defineMLFormPlugin(...)

Legacy schema:

const oldSchema = {
inputs: [{ type: "text", title: "Prompt" }],
outputs: [{ type: "classifier", title: "Prediction" }],
};

Current schema:

const schema = {
fields: [{ id: "prompt", kind: "text", label: "Prompt", mappedTo: "prompt" }],
reports: [{ id: "prediction", kind: "classifier", label: "Prediction", mappedTo: "prediction" }],
};

The legacy class posted to a URL itself. Now that request lives in an application-owned transport, and the response must contain report envelopes:

const transport = {
async submit(request) {
return callBackend(request.modelValues, { signal: request.signal });
},
};

There are no built-in HTTP, streaming, retry, cache, tracing, or circuit-breaker layers to migrate. Keep those concerns in the application client that implements submit.