Skip to content
Open
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
16 changes: 14 additions & 2 deletions .github/workflows/_test-code-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ on:
workflow_call:
workflow_dispatch:

env:
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}

jobs:
build:
name: Run Tests
Expand Down Expand Up @@ -33,7 +42,10 @@ jobs:
- name: Build
run: npm run build-for-dist

- name: Tests sample code
- name: Tests v2 sample code
run: |
./tests/test_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }} ${{ secrets.MINDEE_API_KEY_SE_TESTS }} ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }} ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
./tests/test_v2_code_samples.sh

- name: Tests v1 sample code
run: |
./tests/test_v1_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }}
17 changes: 11 additions & 6 deletions .github/workflows/_test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ on:
workflow_call:
workflow_dispatch:

env:
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}

jobs:
run-tests:
name: Run Integration Tests
Expand Down Expand Up @@ -56,10 +67,4 @@ jobs:
run: npm run build

- name: Test code
env:
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
run: npm run test-integration
33 changes: 33 additions & 0 deletions docs/code_samples/v2_classification.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as mindee from "mindee";
// If you're on CommonJS:
// const mindee = require("mindee");

const apiKey = "MY_API_KEY";
const filePath = "/path/to/the/file.ext";
const modelId = "MY_CLASSIFICATION_MODEL_ID";

// Init a new client
const mindeeClient = new mindee.Client(
{ apiKey: apiKey }
);

// Set product parameters
const params = {
modelId: modelId,
};

// Load a file from disk
const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Classification,
inputSource,
params,
);

// print a string summary
console.log(response.inference.toString());

// Access the classification result
const classification = response.inference.result.classification;
33 changes: 33 additions & 0 deletions docs/code_samples/v2_crop.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as mindee from "mindee";
// If you're on CommonJS:
// const mindee = require("mindee");

const apiKey = "MY_API_KEY";
const filePath = "/path/to/the/file.ext";
const modelId = "MY_CROP_MODEL_ID";

// Init a new client
const mindeeClient = new mindee.Client(
{ apiKey: apiKey }
);

// Set product parameters
const params = {
modelId: modelId,
};

// Load a file from disk
const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Crop,
inputSource,
params,
);

// print a string summary
console.log(response.inference.toString());

// Access the result crops
const crops = response.inference.result.crops;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mindee = require("mindee");
// for TS or modules:
// import * as mindee from "mindee";
import * as mindee from "mindee";
// If you're on CommonJS:
// const mindee = require("mindee");

const apiKey = "MY_API_KEY";
const filePath = "/path/to/the/file.ext";
Expand All @@ -11,8 +11,8 @@ const mindeeClient = new mindee.Client(
{ apiKey: apiKey }
);

// Set inference parameters
const extractionParams = {
// Set product parameters
const params = {
modelId: modelId,

// Options: set to `true` or `false` to override defaults
Expand All @@ -32,14 +32,14 @@ const extractionParams = {
const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = mindeeClient.enqueueAndGetResult(
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Extraction,
inputSource,
extractionParams
params,
);

// Handle the response Promise
response.then((resp) => {
// print a string summary
console.log(resp.inference.toString());
});
// print a string summary
console.log(response.inference.toString());

// Access the result fields
const fields = response.inference.result.fields;
33 changes: 33 additions & 0 deletions docs/code_samples/v2_ocr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as mindee from "mindee";
// If you're on CommonJS:
// const mindee = require("mindee");

const apiKey = "MY_API_KEY";
const filePath = "/path/to/the/file.ext";
const modelId = "MY_OCR_MODEL_ID";

// Init a new client
const mindeeClient = new mindee.Client(
{ apiKey: apiKey }
);

// Set product parameters
const params = {
modelId: modelId,
};

// Load a file from disk
const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Ocr,
inputSource,
params,
);

// print a string summary
console.log(response.inference.toString());

// Access the result OCR pages
const crops = response.inference.result.pages;
33 changes: 33 additions & 0 deletions docs/code_samples/v2_split.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as mindee from "mindee";
// If you're on CommonJS:
// const mindee = require("mindee");

const apiKey = "MY_API_KEY";
const filePath = "/path/to/the/file.ext";
const modelId = "MY_SPLIT_MODEL_ID";

// Init a new client
const mindeeClient = new mindee.Client(
{ apiKey: apiKey }
);

// Set product parameters
const params = {
modelId: modelId,
};

// Load a file from disk
const inputSource = new mindee.PathInput({ inputPath: filePath });

// Send for processing
const response = await mindeeClient.enqueueAndGetResult(
mindee.v2.product.Split,
inputSource,
params,
);

// print a string summary
console.log(response.inference.toString());

// Access the result splits
const crops = response.inference.result.splits;
1 change: 0 additions & 1 deletion src/v2/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {

const program = new Command();


//
// EXECUTE THE COMMANDS
//
Expand Down
9 changes: 9 additions & 0 deletions src/v2/parsing/inference/baseInference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ export abstract class BaseInference {
this.model = new InferenceModel(serverResponse["model"]);
this.file = new InferenceFile(serverResponse["file"]);
}

toString(): string {
return (
"Inference\n" +
"#########\n" +
this.model.toString() + "\n" +
this.file.toString() + "\n"
);
}
}
16 changes: 16 additions & 0 deletions src/v2/product/classification/classificationClassifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { StringDict } from "@/parsing/index.js";

/**
* Document level classification.
*/
export class ClassificationClassifier {
documentType: string;

constructor(serverResponse: StringDict) {
this.documentType = serverResponse["document_type"];
}

toString(): string {
return `Document Type: ${this.documentType}`;
}
}
10 changes: 4 additions & 6 deletions src/v2/product/classification/classificationInference.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { StringDict } from "@/parsing/index.js";
import { BaseInference } from "@/v2/parsing/inference/baseInference.js";
import { ClassificationResult } from "./classificationResult.js";

export class ClassificationInference extends BaseInference {
/**
* Result of a classification inference.
*/
result: any;
result: ClassificationResult;

constructor(serverResponse: StringDict) {
super(serverResponse);
this.result = serverResponse["result"];
this.result = new ClassificationResult(serverResponse["result"]);
}

toString(): string {
return (
"Inference\n" +
"#########\n" +
this.model.toString() + "\n" +
this.file.toString() + "\n" +
super.toString() +
this.result.toString() + "\n"
);
}
Expand Down
17 changes: 17 additions & 0 deletions src/v2/product/classification/classificationResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { StringDict } from "@/parsing/stringDict.js";
import { ClassificationClassifier } from "./classificationClassifier.js";

export class ClassificationResult {
/**
* Fields contained in the inference.
*/
public classification: ClassificationClassifier;

constructor(serverResponse: StringDict) {
this.classification = new ClassificationClassifier(serverResponse["classification"]);
}

toString(): string {
return `Classification\n==============\n${this.classification}`;
}
}
2 changes: 2 additions & 0 deletions src/v2/product/classification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export { Classification } from "./classification.js";
export { ClassificationParameters } from "./classificationParameters.js";
export { ClassificationResponse } from "./classificationResponse.js";
export { ClassificationInference } from "./classificationInference.js";
export { ClassificationResult } from "./classificationResult.js";
export { ClassificationClassifier } from "./classificationClassifier.js";
5 changes: 1 addition & 4 deletions src/v2/product/crop/cropInference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export class CropInference extends BaseInference {

toString(): string {
return (
"Inference\n" +
"#########\n" +
this.model.toString() + "\n" +
this.file.toString() + "\n" +
super.toString() +
this.result.toString() + "\n"
);
}
Expand Down
5 changes: 1 addition & 4 deletions src/v2/product/extraction/extractionInference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ export class ExtractionInference extends BaseInference {

toString(): string {
return (
"Inference\n" +
"#########\n" +
this.model.toString() + "\n" +
this.file.toString() + "\n" +
super.toString() +
this.activeOptions.toString() + "\n" +
this.result.toString() + "\n"
);
Expand Down
1 change: 0 additions & 1 deletion src/v2/product/extraction/extractionResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { StringDict } from "@/parsing/stringDict.js";
import { BaseResponse } from "@/v2/parsing/index.js";

export class ExtractionResponse extends BaseResponse {

/**
* The inference result for an extraction request.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/v2/product/ocr/ocrInference.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { StringDict } from "@/parsing/index.js";
import { BaseInference } from "@/v2/parsing/inference/baseInference.js";
import { OcrResult } from "@/v2/product/ocr/ocrResult.js";

export class OcrInference extends BaseInference {
/**
* Result of an OCR inference.
*/
result: any;
result: OcrResult;

constructor(serverResponse: StringDict) {
super(serverResponse);
this.result = serverResponse["result"];
this.result = new OcrResult(serverResponse["result"]);
}

toString(): string {
Expand Down
Loading
Loading