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
13 changes: 1 addition & 12 deletions src/v2/clientOptions/baseProductParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,7 @@ export interface BaseProductParametersConstructor {
}

/**
* 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"],
* };
* Base parameters for sending a file to a Mindee V2 product.
*/
export abstract class BaseProductParameters {
/**
Expand Down
54 changes: 27 additions & 27 deletions src/v2/http/mindeeApiV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,7 @@ export class MindeeApiV2 {
}

/**
* Searches for resources matching the given criteria.
* @param search
* @param parameters Search parameters.
* @returns a `Promise` containing the search response.
*/
async reqGetSearch<S extends typeof BaseSearch>(
search: S,
parameters: BaseSearchParameters
): Promise<InstanceType<S["responseClass"]>> {
const options: RequestOptions = {
method: "GET",
headers: this.settings.baseHeaders,
hostname: this.settings.hostname,
path: `/v2/search/${search.slug}`,
queryParams: parameters.getRequestParameters(),
timeoutSecs: this.settings.timeoutSecs,
};
const response: BaseHttpResponse = await sendRequestAndReadResponse(this.settings.dispatcher, options);
return this.#processResponse(response, search.responseClass) as InstanceType<S["responseClass"]>;
}

/**
* Sends a document to the inference queue.
* Send a file to the asynchronous processing queue for inference processing.
* @param product Product to enqueue.
* @param inputSource Local or remote file as an input.
* @param params {ExtractionParameters} parameters relating to the enqueueing options.
Expand Down Expand Up @@ -89,7 +67,7 @@ export class MindeeApiV2 {
}

/**
* Get the specified Job by its ID.
* Get the status of an inference that was previously enqueued.
* Throws an error if the server's response contains an error.
* @param jobId The Job ID as returned by the enqueue request.
* @returns a `Promise` containing the job response.
Expand All @@ -101,7 +79,7 @@ export class MindeeApiV2 {
}

/**
* Get the specified Job from a polling URL.
* Get the status of an inference that was previously enqueued.
* Throws an error if the server's response contains an error.
* @param pollingUrl The polling URL as returned by a Job's pollingUrl property.
* @returns a `Promise` containing the job response.
Expand All @@ -120,7 +98,7 @@ export class MindeeApiV2 {
}

/**
* Get the result of a queued document from the API.
* Get the result of an inference that was previously enqueued.
* Throws an error if the server's response contains an error.
* @param product
* @param inferenceId The inference ID for the result.
Expand All @@ -137,7 +115,7 @@ export class MindeeApiV2 {
}

/**
* Get the result of a queued document from the API.
* Get the result of an inference that was previously enqueued.
* Throws an error if the server's response contains an error.
* @param product
* @param url The URL as returned by a Job's resultUrl property.
Expand All @@ -160,6 +138,28 @@ export class MindeeApiV2 {
return this.#processResponse(response, product.responseClass) as InstanceType<P["responseClass"]>;
}

/**
* Searches for resources matching the given criteria.
* @param search
* @param parameters Search parameters.
* @returns a `Promise` containing the search response.
*/
async reqGetSearch<S extends typeof BaseSearch>(
search: S,
parameters: BaseSearchParameters
): Promise<InstanceType<S["responseClass"]>> {
const options: RequestOptions = {
method: "GET",
headers: this.settings.baseHeaders,
hostname: this.settings.hostname,
path: `/v2/search/${search.slug}`,
queryParams: parameters.getRequestParameters(),
timeoutSecs: this.settings.timeoutSecs,
};
const response: BaseHttpResponse = await sendRequestAndReadResponse(this.settings.dispatcher, options);
return this.#processResponse(response, search.responseClass) as InstanceType<S["responseClass"]>;
}

#paramsToFormData(params: Record<string, string>): FormData {
const form = new FormData();
for (const [key, value] of Object.entries(params)) {
Expand Down
16 changes: 1 addition & 15 deletions src/v2/product/classification/params/classificationParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ import { BaseProductParameters, BaseProductParametersConstructor } from "@/v2/cl
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",
* alias: "YOUR_ALIAS",
* webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
* pollingOptions: {
* initialDelaySec: 2,
* delaySec: 1.5,
* }
* };
* Parameters for sending a file to a Classification product.
*/
export class ClassificationParameters extends BaseProductParameters {
constructor(params: BaseProductParametersConstructor & {}) {
Expand Down
16 changes: 1 addition & 15 deletions src/v2/product/crop/params/cropParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ import { BaseProductParameters, BaseProductParametersConstructor } from "@/v2/cl
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",
* alias: "YOUR_ALIAS",
* webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
* pollingOptions: {
* initialDelaySec: 2,
* delaySec: 1.5,
* }
* };
* Parameters for sending a file to a Crop product.
*/
export class CropParameters extends BaseProductParameters {
constructor(params: BaseProductParametersConstructor & {}) {
Expand Down
17 changes: 1 addition & 16 deletions src/v2/product/extraction/params/extractionParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,7 @@ import { BaseProductParameters, BaseProductParametersConstructor } from "@/v2/cl
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,
* }
* };
* Parameters for sending a file to an Extraction product.
*/
export class ExtractionParameters extends BaseProductParameters {
/**
Expand Down
16 changes: 1 addition & 15 deletions src/v2/product/ocr/params/ocrParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,7 @@ import { BaseProductParameters, BaseProductParametersConstructor } from "@/v2/cl
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",
* alias: "YOUR_ALIAS",
* webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
* pollingOptions: {
* initialDelaySec: 2,
* delaySec: 1.5,
* }
* };
* Parameters for sending a file to a Raw Text (OCR) product.
*/
export class OcrParameters extends BaseProductParameters {
constructor(params: BaseProductParametersConstructor & {}) {
Expand Down
16 changes: 1 addition & 15 deletions src/v2/product/split/params/splitParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@ import {
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",
* alias: "YOUR_ALIAS",
* webhookIds: ["YOUR_WEBHOOK_ID_1", "YOUR_WEBHOOK_ID_2"],
* pollingOptions: {
* initialDelaySec: 2,
* delaySec: 1.5,
* }
* };
* Parameters for sending a file to a Split product.
*/
export class SplitParameters extends BaseProductParameters {
constructor(params: BaseProductParametersConstructor & {}) {
Expand Down
17 changes: 9 additions & 8 deletions src/v2/search/ragDocuments/ragDocumentSearchParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BaseSearchParameters, BaseSearchParametersConstructor } from "@/v2/clie
* Constructor parameters for RagDocumentSearchParameters.
*/
export interface RagDocumentSearchParametersConstructor extends BaseSearchParametersConstructor {
modelId?: string;
modelId: string;
filename?: string;
}

Expand All @@ -16,14 +16,17 @@ export class RagDocumentSearchParameters extends BaseSearchParameters {
/**
* Model identifier to search in.
*/
modelId?: string;
modelId: string;

/**
* Case-insensitive substring search on filename.
*/
filename?: string;

constructor(params: RagDocumentSearchParametersConstructor = {}) {
constructor(params: RagDocumentSearchParametersConstructor) {
if (!params.modelId) {
throw new MindeeConfigurationError("ModelId is required in RagDocumentSearchParameters");
}
super(params);
this.modelId = params.modelId;
this.filename = params.filename;
Expand All @@ -32,11 +35,9 @@ export class RagDocumentSearchParameters extends BaseSearchParameters {
/** @inheritdoc */
getRequestParameters(): Record<string, string> {
const parameters = super.getRequestParameters();
if (this.modelId) {
parameters["model_id"] = this.modelId;
} else {
throw new MindeeConfigurationError("ModelId is required in RagDocumentSearchParameters");
}

parameters["model_id"] = this.modelId;

if (this.filename) {
parameters["filename"] = this.filename;
}
Expand Down
Loading