Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions src/clientV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ import { MindeeHttpErrorV2 } from "./errors/mindeeError";
* The `initialTimerOptions` and `recurringTimerOptions` objects let you pass an
* `AbortSignal` or make the timer `unref`-ed to the `setTimeout()`.
*
* @property initialDelaySec Number of seconds to wait **before the first poll**.
* @property delaySec Interval in seconds between two consecutive polls.
* @property maxRetries Maximum number of polling attempts (including the first one).
* @property initialTimerOptions Options passed to the initial `setTimeout()`.
* @property recurringTimerOptions Options passed to every recurring `setTimeout()`.
*
* @category ClientV2
* @example
* const params = {
Expand All @@ -41,13 +35,18 @@ import { MindeeHttpErrorV2 } from "./errors/mindeeError";
*/

export interface PollingOptions {
/** Number of seconds to wait *before the first poll*. */
initialDelaySec?: number;
/** Interval in seconds between two consecutive polls. */
delaySec?: number;
/** Maximum number of polling attempts (including the first one). */
maxRetries?: number;
/** Options passed to the initial `setTimeout()`. */
initialTimerOptions?: {
ref?: boolean,
signal?: AbortSignal
};
/** Options passed to every recurring `setTimeout()`. */
recurringTimerOptions?: {
ref?: boolean,
signal?: AbortSignal
Expand All @@ -65,16 +64,6 @@ interface ValidatedPollingOptions extends PollingOptions {
*
* All fields are optional except `modelId`.
*
* @property modelId Identifier of the model that must process the document. **Required**.
* @property rag Enhance extraction accuracy with Retrieval-Augmented Generation.
* @property rawText Extract the full text content from the document as strings, and fill the `raw_text` attribute.
* @property polygon Calculate bounding box polygons for all fields, and fill their `locations` attribute.
* @property confidence Boost the precision and accuracy of all extractions.
* Calculate confidence scores for all fields and fill their `confidence` attribute.
* @property alias Custom alias assigned to the uploaded document.
* @property webhookIds List of webhook UUIDs that will receive the final API response.
* @property pollingOptions Client-side polling configuration (see {@link PollingOptions}).
* @property closeFile By default the file is closed once the upload is finished, set to `false` to keep it open.
* @category ClientV2
* @example
* const params = {
Expand All @@ -89,24 +78,35 @@ interface ValidatedPollingOptions extends PollingOptions {
* };
*/
export interface InferenceParameters {
/** Model ID to use for the inference. **Required** */
modelId: string;
/** Use Retrieval-Augmented Generation during inference. */
rag?: boolean;
/** Extract the entire text from the document as strings, and fill the `rawText` attribute. */
rawText?: boolean;
/** Calculate bounding box polygons for values, and fill the `locations` attribute of fields. */
polygon?: boolean;
/** Calculate confidence scores for values, and fill the `confidence` attribute of fields.
* Useful for automation.*/
confidence?: boolean;
/** Use an alias to link the file to your own DB. If empty, no alias will be used. */
alias?: string;
/** Additional text context used by the model during inference.
* *Not recommended*, for specific use only. */
textContext?: string;
/** Webhook IDs to call after all processing is finished.
* If empty, no webhooks will be used. */
webhookIds?: string[];
/** Client-side polling configuration (see {@link PollingOptions}). */
pollingOptions?: PollingOptions;
/** By default, the file is closed once the upload is finished.
* Set to `false` to keep it open. */
closeFile?: boolean;
}

/**
* Options for the V2 Mindee Client.
*
* @property apiKey Your API key for all endpoints.
* @property throwOnError Raise an `Error` on errors.
* @property debug Log debug messages.
*
* @category ClientV2
* @example
* const client = new MindeeClientV2({
Expand All @@ -116,8 +116,11 @@ export interface InferenceParameters {
* });
*/
export interface ClientOptions {
/** Your API key for all endpoints. */
apiKey?: string;
/** Raise an `Error` on errors. */
throwOnError?: boolean;
/** Log debug messages. */
debug?: boolean;
}

Expand Down
4 changes: 3 additions & 1 deletion src/http/mindeeApiV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ export class MindeeApiV2 {
if (params.rawText !== undefined && params.rawText !== null) {
form.append("raw_text", params.rawText.toString().toLowerCase());
}

if (params.textContext !== undefined && params.textContext !== null) {
form.append("text_context", params.textContext);
}
if (params.webhookIds && params.webhookIds.length > 0) {
form.append("webhook_ids", params.webhookIds.join(","));
}
Expand Down
1 change: 1 addition & 0 deletions tests/v2/clientV2.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe("MindeeV2 – Client Integration Tests", () => {
rawText: true,
polygon: true,
confidence: false,
textContext: "this is an invoice",
webhookIds: [],
alias: "ts_integration_binary_filled_single"
};
Expand Down
4 changes: 2 additions & 2 deletions tests/v2/clientV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("MindeeV2 - ClientV2", () => {
const inputDoc = new PathInput({ inputPath: filePath });

await assert.rejects(
client.enqueueInference(inputDoc, { modelId: "dummy-model" }),
client.enqueueInference(inputDoc, { modelId: "dummy-model", textContext: "hello" }),
MindeeHttpErrorV2
);
});
Expand All @@ -87,7 +87,7 @@ describe("MindeeV2 - ClientV2", () => {
await assert.rejects(
client.enqueueAndGetInference(
inputDoc,
{ modelId: "dummy-model" }
{ modelId: "dummy-model", rag: false }
),
MindeeHttpErrorV2
);
Expand Down