APIs
Running the pipeline API
You can use the Transformer.js pipeline API directly to perform inference, as long as the model is in our model hub.
The Transformers.js documentation provides a lot of examples that you can slightly adapt when running in Firefox.
In the example below, a text summarization task is performed using the summarization task:
const { createEngine } = ChromeUtils.importESModule("chrome://global/content/ml/EngineProcess.sys.mjs");
const options = {
taskName: "summarization",
modelId: "mozilla/text_summarization",
modelRevision: "main"
};
const engine = await createEngine(options);
const text = 'The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, ' +
'and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. ' +
'During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest ' +
'man-made structure in the world, a title it held for 41 years until the Chrysler Building in New ' +
'York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to ' +
'the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the ' +
'Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second ' +
'tallest free-standing structure in France after the Millau Viaduct.';
const request = { args: [text], options: { max_new_tokens: 100 } };
const res = await engine.run(request);
console.log(res[0]["summary_text"]);