mindee
Version:
Mindee Client Library for Node.js
43 lines (42 loc) • 1.29 kB
JavaScript
import { FormData } from "undici";
import { MindeeConfigurationError } from "../../errors/index.js";
/**
* Parameters accepted by all v2 products.
*
* 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"],
* };
*/
export class BaseParameters {
constructor(params) {
if (params.modelId === undefined || params.modelId === null || params.modelId === "") {
throw new MindeeConfigurationError("Model ID must be provided");
}
this.modelId = params.modelId;
this.alias = params.alias;
this.webhookIds = params.webhookIds;
this.closeFile = params.closeFile;
}
/**
* Returns the form data to send to the API.
* @returns A `FormData` object.
*/
getFormData() {
const form = new FormData();
form.set("model_id", this.modelId);
if (this.alias !== undefined && this.alias !== null) {
form.set("alias", this.alias);
}
if (this.webhookIds && this.webhookIds.length > 0) {
form.set("webhook_ids", this.webhookIds.join(","));
}
return form;
}
}