Skip to content

Commit 6a326a5

Browse files
authored
✨ add text_context to v2 inference enqueue (#400)
1 parent 2e340a4 commit 6a326a5

File tree

4 files changed

+29
-23
lines changed

4 files changed

+29
-23
lines changed

src/clientV2.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ import { MindeeHttpErrorV2 } from "./errors/mindeeError";
2323
* The `initialTimerOptions` and `recurringTimerOptions` objects let you pass an
2424
* `AbortSignal` or make the timer `unref`-ed to the `setTimeout()`.
2525
*
26-
* @property initialDelaySec Number of seconds to wait **before the first poll**.
27-
* @property delaySec Interval in seconds between two consecutive polls.
28-
* @property maxRetries Maximum number of polling attempts (including the first one).
29-
* @property initialTimerOptions Options passed to the initial `setTimeout()`.
30-
* @property recurringTimerOptions Options passed to every recurring `setTimeout()`.
31-
*
3226
* @category ClientV2
3327
* @example
3428
* const params = {
@@ -41,13 +35,18 @@ import { MindeeHttpErrorV2 } from "./errors/mindeeError";
4135
*/
4236

4337
export interface PollingOptions {
38+
/** Number of seconds to wait *before the first poll*. */
4439
initialDelaySec?: number;
40+
/** Interval in seconds between two consecutive polls. */
4541
delaySec?: number;
42+
/** Maximum number of polling attempts (including the first one). */
4643
maxRetries?: number;
44+
/** Options passed to the initial `setTimeout()`. */
4745
initialTimerOptions?: {
4846
ref?: boolean,
4947
signal?: AbortSignal
5048
};
49+
/** Options passed to every recurring `setTimeout()`. */
5150
recurringTimerOptions?: {
5251
ref?: boolean,
5352
signal?: AbortSignal
@@ -65,16 +64,6 @@ interface ValidatedPollingOptions extends PollingOptions {
6564
*
6665
* All fields are optional except `modelId`.
6766
*
68-
* @property modelId Identifier of the model that must process the document. **Required**.
69-
* @property rag Enhance extraction accuracy with Retrieval-Augmented Generation.
70-
* @property rawText Extract the full text content from the document as strings, and fill the `raw_text` attribute.
71-
* @property polygon Calculate bounding box polygons for all fields, and fill their `locations` attribute.
72-
* @property confidence Boost the precision and accuracy of all extractions.
73-
* Calculate confidence scores for all fields and fill their `confidence` attribute.
74-
* @property alias Custom alias assigned to the uploaded document.
75-
* @property webhookIds List of webhook UUIDs that will receive the final API response.
76-
* @property pollingOptions Client-side polling configuration (see {@link PollingOptions}).
77-
* @property closeFile By default the file is closed once the upload is finished, set to `false` to keep it open.
7867
* @category ClientV2
7968
* @example
8069
* const params = {
@@ -89,24 +78,35 @@ interface ValidatedPollingOptions extends PollingOptions {
8978
* };
9079
*/
9180
export interface InferenceParameters {
81+
/** Model ID to use for the inference. **Required** */
9282
modelId: string;
83+
/** Use Retrieval-Augmented Generation during inference. */
9384
rag?: boolean;
85+
/** Extract the entire text from the document as strings, and fill the `rawText` attribute. */
9486
rawText?: boolean;
87+
/** Calculate bounding box polygons for values, and fill the `locations` attribute of fields. */
9588
polygon?: boolean;
89+
/** Calculate confidence scores for values, and fill the `confidence` attribute of fields.
90+
* Useful for automation.*/
9691
confidence?: boolean;
92+
/** Use an alias to link the file to your own DB. If empty, no alias will be used. */
9793
alias?: string;
94+
/** Additional text context used by the model during inference.
95+
* *Not recommended*, for specific use only. */
96+
textContext?: string;
97+
/** Webhook IDs to call after all processing is finished.
98+
* If empty, no webhooks will be used. */
9899
webhookIds?: string[];
100+
/** Client-side polling configuration (see {@link PollingOptions}). */
99101
pollingOptions?: PollingOptions;
102+
/** By default, the file is closed once the upload is finished.
103+
* Set to `false` to keep it open. */
100104
closeFile?: boolean;
101105
}
102106

103107
/**
104108
* Options for the V2 Mindee Client.
105109
*
106-
* @property apiKey Your API key for all endpoints.
107-
* @property throwOnError Raise an `Error` on errors.
108-
* @property debug Log debug messages.
109-
*
110110
* @category ClientV2
111111
* @example
112112
* const client = new MindeeClientV2({
@@ -116,8 +116,11 @@ export interface InferenceParameters {
116116
* });
117117
*/
118118
export interface ClientOptions {
119+
/** Your API key for all endpoints. */
119120
apiKey?: string;
121+
/** Raise an `Error` on errors. */
120122
throwOnError?: boolean;
123+
/** Log debug messages. */
121124
debug?: boolean;
122125
}
123126

src/http/mindeeApiV2.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ export class MindeeApiV2 {
110110
if (params.rawText !== undefined && params.rawText !== null) {
111111
form.append("raw_text", params.rawText.toString().toLowerCase());
112112
}
113-
113+
if (params.textContext !== undefined && params.textContext !== null) {
114+
form.append("text_context", params.textContext);
115+
}
114116
if (params.webhookIds && params.webhookIds.length > 0) {
115117
form.append("webhook_ids", params.webhookIds.join(","));
116118
}

tests/v2/clientV2.integration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe("MindeeV2 – Client Integration Tests", () => {
8282
rawText: true,
8383
polygon: true,
8484
confidence: false,
85+
textContext: "this is an invoice",
8586
webhookIds: [],
8687
alias: "ts_integration_binary_filled_single"
8788
};

tests/v2/clientV2.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe("MindeeV2 - ClientV2", () => {
7676
const inputDoc = new PathInput({ inputPath: filePath });
7777

7878
await assert.rejects(
79-
client.enqueueInference(inputDoc, { modelId: "dummy-model" }),
79+
client.enqueueInference(inputDoc, { modelId: "dummy-model", textContext: "hello" }),
8080
MindeeHttpErrorV2
8181
);
8282
});
@@ -87,7 +87,7 @@ describe("MindeeV2 - ClientV2", () => {
8787
await assert.rejects(
8888
client.enqueueAndGetInference(
8989
inputDoc,
90-
{ modelId: "dummy-model" }
90+
{ modelId: "dummy-model", rag: false }
9191
),
9292
MindeeHttpErrorV2
9393
);

0 commit comments

Comments
 (0)