extractWithModels
function extractWithModels<F>( doc, options, models, __namedParameters?): Promise<ExtractResult[F]>;Defined in: packages/sdk/src/extract-job.ts:221
Runs an extraction whose models the host runs asynchronously: steps a job, and for each
request awaits the matching function of models, then hands its result back.
Type Parameters
Section titled “Type Parameters”F extends ExtractFormat
Parameters
Section titled “Parameters”options
Section titled “options”models
Section titled “models”__namedParameters?
Section titled “__namedParameters?”budget?
Section titled “budget?”number = 16
signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”Promise<ExtractResult[F]>
Example
Section titled “Example”const json = await extractWithModels( doc, { format: "json", models: { layout: { name: "my-layout", version: "1", sha256, licence: "Apache-2.0" } } }, { layout: async ({ page, dpi }) => myModel.detect(await render(page, dpi)) },);On a document opened with Document.openRange, a step that needs bytes not yet fetched ends
the job with data-pending, as every error ends a job; fetch the file first (await doc.ensure(() => doc.pages) reads only the page tree, so read the whole file for a long
extraction), or wrap the call in doc.ensure, which runs it again, models included.
Throws
Section titled “Throws”LaminaPdfError as ExtractJob.step; invalid-argument when
options.models names a model models has no function for; cancelled once signal
aborts, also when the model rejects because of it (the model’s error is the cause).
0.2.0