mindee
Version:
Mindee Client Library for Node.js
68 lines (67 loc) • 2.44 kB
JavaScript
import { FormData } from "undici";
import { DataSchema } from "./dataSchema.js";
import { BaseParameters } from "../../../../v2/clientOptions/baseParameters.js";
import { logger } from "../../../../logger.js";
/**
* Parameters accepted by the asynchronous **inference** v2 endpoint.
*
* All fields are optional except `modelId`.
*
* @category ClientV2
* @example
* const params = {
* modelId: "YOUR_MODEL_ID",
* rag: true,
* alias: "YOUR_ALIAS",
* webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
* pollingOptions: {
* initialDelaySec: 2,
* delaySec: 1.5,
* }
* };
*/
export class ExtractionParameters extends BaseParameters {
constructor(params) {
super({ ...params });
this.rag = params.rag;
this.rawText = params.rawText;
this.polygon = params.polygon;
this.confidence = params.confidence;
this.textContext = params.textContext;
if (params.dataSchema !== undefined && params.dataSchema !== null) {
if (!(params.dataSchema instanceof DataSchema)) {
this.dataSchema = new DataSchema(params.dataSchema);
}
else {
this.dataSchema = params.dataSchema;
}
}
logger.debug("Extraction parameters initialized.");
}
getFormData() {
const form = new FormData();
form.set("model_id", this.modelId);
if (this.rag !== undefined && this.rag !== null) {
form.set("rag", this.rag.toString());
}
if (this.polygon !== undefined && this.polygon !== null) {
form.set("polygon", this.polygon.toString().toLowerCase());
}
if (this.confidence !== undefined && this.confidence !== null) {
form.set("confidence", this.confidence.toString().toLowerCase());
}
if (this.rawText !== undefined && this.rawText !== null) {
form.set("raw_text", this.rawText.toString().toLowerCase());
}
if (this.textContext !== undefined && this.textContext !== null) {
form.set("text_context", this.textContext);
}
if (this.dataSchema !== undefined && this.dataSchema !== null) {
form.set("data_schema", this.dataSchema.toString());
}
if (this.webhookIds && this.webhookIds.length > 0) {
form.set("webhook_ids", this.webhookIds.join(","));
}
return form;
}
}