Skip to content

Commit f3ae249

Browse files
committed
don't harmonize clients
1 parent ce5aed4 commit f3ae249

File tree

5 files changed

+146
-83
lines changed

5 files changed

+146
-83
lines changed

docs/code_samples/default_v2.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const modelId = "MY_MODEL_ID";
1010
const mindeeClient = new mindee.ClientV2({ apiKey: apiKey });
1111

1212
// Load a file from disk
13-
const inputSource = mindeeClient.docFromPath(filePath);
13+
const inputSource = mindeeClient.sourceFromPath(filePath);
1414
const params = {
1515
modelId: modelId,
1616
// If set to `true`, will enable Retrieval-Augmented Generation.

src/baseClient.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/client.ts

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import { setTimeout } from "node:timers/promises";
2121
import { MindeeError } from "./errors";
2222
import { WorkflowResponse } from "./parsing/common/workflowResponse";
2323
import { WorkflowEndpoint } from "./http/workflowEndpoint";
24-
import { BaseClient } from "./baseClient";
24+
import { Base64Input, BufferInput, BytesInput, PathInput, StreamInput, UrlInput } from "./input";
25+
import { Readable } from "stream";
2526

2627
/**
2728
* Common options for workflows & predictions.
@@ -129,7 +130,7 @@ export interface ClientOptions {
129130
*
130131
* @category Client
131132
*/
132-
export class Client extends BaseClient {
133+
export class Client {
133134
/** Key of the API. */
134135
protected apiKey: string;
135136

@@ -143,7 +144,6 @@ export class Client extends BaseClient {
143144
debug: false,
144145
}
145146
) {
146-
super();
147147
this.apiKey = apiKey ? apiKey : "";
148148
errorHandler.throwOnError = throwOnError ?? true;
149149
logger.level =
@@ -565,4 +565,72 @@ Job status: ${pollResults.job.status}.`
565565
InferenceFactory.getEndpoint(productClass);
566566
return [endpointName, endpointVersion];
567567
}
568+
569+
/**
570+
* Load an input document from a local path.
571+
* @param inputPath
572+
*/
573+
docFromPath(inputPath: string): PathInput {
574+
return new PathInput({
575+
inputPath: inputPath,
576+
});
577+
}
578+
579+
/**
580+
* Load an input document from a base64 encoded string.
581+
* @param inputString input content, as a string.
582+
* @param filename file name.
583+
*/
584+
docFromBase64(inputString: string, filename: string): Base64Input {
585+
return new Base64Input({
586+
inputString: inputString,
587+
filename: filename,
588+
});
589+
}
590+
591+
/**
592+
* Load an input document from a `stream.Readable` object.
593+
* @param inputStream input content, as a readable stream.
594+
* @param filename file name.
595+
*/
596+
docFromStream(inputStream: Readable, filename: string): StreamInput {
597+
return new StreamInput({
598+
inputStream: inputStream,
599+
filename: filename,
600+
});
601+
}
602+
603+
/**
604+
* Load an input document from bytes.
605+
* @param inputBytes input content, as a Uint8Array or Buffer.
606+
* @param filename file name.
607+
*/
608+
docFromBytes(inputBytes: Uint8Array, filename: string): BytesInput {
609+
return new BytesInput({
610+
inputBytes: inputBytes,
611+
filename: filename,
612+
});
613+
}
614+
615+
/**
616+
* Load an input document from a URL.
617+
* @param url input url. Must be HTTPS.
618+
*/
619+
docFromUrl(url: string): UrlInput {
620+
return new UrlInput({
621+
url: url,
622+
});
623+
}
624+
625+
/**
626+
* Load an input document from a Buffer.
627+
* @param buffer input content, as a buffer.
628+
* @param filename file name.
629+
*/
630+
docFromBuffer(buffer: Buffer, filename: string): BufferInput {
631+
return new BufferInput({
632+
buffer: buffer,
633+
filename: filename,
634+
});
635+
}
568636
}

src/clientV2.ts

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {
2-
LocalInputSource,
2+
Base64Input, BufferInput, BytesInput,
3+
LocalInputSource, PathInput, StreamInput, UrlInput,
34
} from "./input";
45
import { errorHandler } from "./errors/handler";
56
import { LOG_LEVELS, logger } from "./logger";
67

78
import { setTimeout } from "node:timers/promises";
89
import { ErrorResponse, InferenceResponse, JobResponse } from "./parsing/v2";
910
import { MindeeApiV2 } from "./http/mindeeApiV2";
10-
import { BaseClient } from "./baseClient";
1111
import { MindeeHttpErrorV2 } from "./errors/mindeeError";
12+
import { Readable } from "stream";
1213

1314
/**
1415
* Parameters for the internal polling loop in {@link ClientV2.enqueueAndGetInference | enqueueAndGetInference()} .
@@ -122,7 +123,7 @@ export interface ClientOptions {
122123
*
123124
* @category ClientV2
124125
*/
125-
export class ClientV2 extends BaseClient {
126+
export class ClientV2 {
126127
/** Key of the API. */
127128
protected mindeeApi: MindeeApiV2;
128129

@@ -136,7 +137,6 @@ export class ClientV2 extends BaseClient {
136137
debug: false,
137138
}
138139
) {
139-
super();
140140
this.mindeeApi = new MindeeApiV2(apiKey);
141141
errorHandler.throwOnError = throwOnError ?? true;
142142
logger.level =
@@ -283,4 +283,72 @@ Job status: ${pollResults.job.status}.`
283283
" seconds"
284284
);
285285
}
286+
287+
/**
288+
* Load an input document from a local path.
289+
* @param inputPath
290+
*/
291+
sourceFromPath(inputPath: string): PathInput {
292+
return new PathInput({
293+
inputPath: inputPath,
294+
});
295+
}
296+
297+
/**
298+
* Load an input document from a base64 encoded string.
299+
* @param inputString input content, as a string.
300+
* @param filename file name.
301+
*/
302+
sourceFromBase64(inputString: string, filename: string): Base64Input {
303+
return new Base64Input({
304+
inputString: inputString,
305+
filename: filename,
306+
});
307+
}
308+
309+
/**
310+
* Load an input document from a `stream.Readable` object.
311+
* @param inputStream input content, as a readable stream.
312+
* @param filename file name.
313+
*/
314+
sourceFromStream(inputStream: Readable, filename: string): StreamInput {
315+
return new StreamInput({
316+
inputStream: inputStream,
317+
filename: filename,
318+
});
319+
}
320+
321+
/**
322+
* Load an input document from bytes.
323+
* @param inputBytes input content, as a Uint8Array or Buffer.
324+
* @param filename file name.
325+
*/
326+
sourceFromBytes(inputBytes: Uint8Array, filename: string): BytesInput {
327+
return new BytesInput({
328+
inputBytes: inputBytes,
329+
filename: filename,
330+
});
331+
}
332+
333+
/**
334+
* Load an input document from a Buffer.
335+
* @param buffer input content, as a buffer.
336+
* @param filename file name.
337+
*/
338+
sourceFromBuffer(buffer: Buffer, filename: string): BufferInput {
339+
return new BufferInput({
340+
buffer: buffer,
341+
filename: filename,
342+
});
343+
}
344+
345+
/**
346+
* Load an input document from a URL.
347+
* @param url input url. Must be HTTPS.
348+
*/
349+
sourceFromUrl(url: string): UrlInput {
350+
return new UrlInput({
351+
url: url,
352+
});
353+
}
286354
}

tests/v2/clientV2.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe("ClientV2", () => {
7878

7979
it("enqueue(path) rejects with MindeeHttpErrorV2 on 4xx", async () => {
8080
const filePath = path.join(fileTypesDir, "receipt.jpg");
81-
const inputDoc = client.docFromPath(filePath);
81+
const inputDoc = client.sourceFromPath(filePath);
8282

8383
await assert.rejects(
8484
client.enqueueInference(inputDoc, { modelId: "dummy-model" }),
@@ -88,7 +88,7 @@ describe("ClientV2", () => {
8888

8989
it("enqueueAndParse(path) rejects with MindeeHttpErrorV2 on 4xx", async () => {
9090
const filePath = path.join(fileTypesDir, "receipt.jpg");
91-
const inputDoc = client.docFromPath(filePath);
91+
const inputDoc = client.sourceFromPath(filePath);
9292
await assert.rejects(
9393
client.enqueueAndGetInference(
9494
inputDoc,

0 commit comments

Comments
 (0)