diff --git a/.github/workflows/_test-code-samples.yml b/.github/workflows/_test-code-samples.yml index 371787e9..1c6c587a 100644 --- a/.github/workflows/_test-code-samples.yml +++ b/.github/workflows/_test-code-samples.yml @@ -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 @@ -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 }} diff --git a/.github/workflows/_test-integrations.yml b/.github/workflows/_test-integrations.yml index 3519c18e..4d96c033 100644 --- a/.github/workflows/_test-integrations.yml +++ b/.github/workflows/_test-integrations.yml @@ -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 @@ -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 diff --git a/docs/code_samples/v2_classification.txt b/docs/code_samples/v2_classification.txt new file mode 100644 index 00000000..938983ea --- /dev/null +++ b/docs/code_samples/v2_classification.txt @@ -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; diff --git a/docs/code_samples/v2_crop.txt b/docs/code_samples/v2_crop.txt new file mode 100644 index 00000000..161f9b2f --- /dev/null +++ b/docs/code_samples/v2_crop.txt @@ -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; diff --git a/docs/code_samples/v2_default.txt b/docs/code_samples/v2_extraction.txt similarity index 69% rename from docs/code_samples/v2_default.txt rename to docs/code_samples/v2_extraction.txt index d7f41d0e..caba4b9b 100644 --- a/docs/code_samples/v2_default.txt +++ b/docs/code_samples/v2_extraction.txt @@ -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"; @@ -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 @@ -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; diff --git a/docs/code_samples/v2_ocr.txt b/docs/code_samples/v2_ocr.txt new file mode 100644 index 00000000..389c1efd --- /dev/null +++ b/docs/code_samples/v2_ocr.txt @@ -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; diff --git a/docs/code_samples/v2_split.txt b/docs/code_samples/v2_split.txt new file mode 100644 index 00000000..6445c56f --- /dev/null +++ b/docs/code_samples/v2_split.txt @@ -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; diff --git a/src/v2/cli.ts b/src/v2/cli.ts index c3c34c41..b499bf44 100644 --- a/src/v2/cli.ts +++ b/src/v2/cli.ts @@ -14,7 +14,6 @@ import { const program = new Command(); - // // EXECUTE THE COMMANDS // diff --git a/src/v2/parsing/inference/baseInference.ts b/src/v2/parsing/inference/baseInference.ts index 6552a368..e0d2c538 100644 --- a/src/v2/parsing/inference/baseInference.ts +++ b/src/v2/parsing/inference/baseInference.ts @@ -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" + ); + } } diff --git a/src/v2/product/classification/classificationClassifier.ts b/src/v2/product/classification/classificationClassifier.ts new file mode 100644 index 00000000..e2d65ce1 --- /dev/null +++ b/src/v2/product/classification/classificationClassifier.ts @@ -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}`; + } +} diff --git a/src/v2/product/classification/classificationInference.ts b/src/v2/product/classification/classificationInference.ts index 916c71dd..872fa2ee 100644 --- a/src/v2/product/classification/classificationInference.ts +++ b/src/v2/product/classification/classificationInference.ts @@ -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" ); } diff --git a/src/v2/product/classification/classificationResult.ts b/src/v2/product/classification/classificationResult.ts new file mode 100644 index 00000000..99f16b08 --- /dev/null +++ b/src/v2/product/classification/classificationResult.ts @@ -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}`; + } +} diff --git a/src/v2/product/classification/index.ts b/src/v2/product/classification/index.ts index 5c34b115..389576bd 100644 --- a/src/v2/product/classification/index.ts +++ b/src/v2/product/classification/index.ts @@ -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"; diff --git a/src/v2/product/crop/cropInference.ts b/src/v2/product/crop/cropInference.ts index 6b35c269..ecfbc713 100644 --- a/src/v2/product/crop/cropInference.ts +++ b/src/v2/product/crop/cropInference.ts @@ -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" ); } diff --git a/src/v2/product/extraction/extractionInference.ts b/src/v2/product/extraction/extractionInference.ts index 7db6d240..aca2702c 100644 --- a/src/v2/product/extraction/extractionInference.ts +++ b/src/v2/product/extraction/extractionInference.ts @@ -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" ); diff --git a/src/v2/product/extraction/extractionResponse.ts b/src/v2/product/extraction/extractionResponse.ts index 8a568f30..39e637b1 100644 --- a/src/v2/product/extraction/extractionResponse.ts +++ b/src/v2/product/extraction/extractionResponse.ts @@ -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. */ diff --git a/src/v2/product/ocr/ocrInference.ts b/src/v2/product/ocr/ocrInference.ts index c767fccf..284461f8 100644 --- a/src/v2/product/ocr/ocrInference.ts +++ b/src/v2/product/ocr/ocrInference.ts @@ -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 { diff --git a/src/v2/product/ocr/ocrPage.ts b/src/v2/product/ocr/ocrPage.ts new file mode 100644 index 00000000..b531025b --- /dev/null +++ b/src/v2/product/ocr/ocrPage.ts @@ -0,0 +1,29 @@ +import { OcrWord } from "./ocrWord.js"; +import { StringDict } from "@/parsing/index.js"; + +export class OcrPage { + /** + * List of words extracted from the document page. + */ + words: OcrWord[]; + + /** + * Full text content extracted from the document page. + */ + content: string; + + constructor(serverResponse: StringDict) { + this.words = (serverResponse["words"] as any[]).map(word => new OcrWord(word)); + this.content = serverResponse["content"] as string; + } + + toString(): string { + let ocrWords = "\n"; + if (this.words.length > 0) { + ocrWords += this.words.map(word => word.toString()).join("\n\n"); + } + let outStr = `OCR Words\n---------${ocrWords}`; + outStr += `\n\n:Content: ${this.content}`; + return outStr; + } +} diff --git a/src/v2/product/ocr/ocrResult.ts b/src/v2/product/ocr/ocrResult.ts new file mode 100644 index 00000000..4473a5f8 --- /dev/null +++ b/src/v2/product/ocr/ocrResult.ts @@ -0,0 +1,24 @@ +import { StringDict } from "@/parsing/index.js"; +import { OcrPage } from "./ocrPage.js"; + +/** + * OCR result info. + */ +export class OcrResult { + /** + * List of OCR results for each page in the document. + */ + pages: OcrPage[]; + + constructor(serverResponse: StringDict) { + this.pages = serverResponse.pages.map((ocr: any) => new OcrPage(ocr)); + } + + toString(): string { + let pages = "\n"; + if (this.pages.length > 0) { + pages += this.pages.map(ocr => ocr.toString()).join("\n\n"); + } + return `Pages\n======${pages}`; + } +} diff --git a/src/v2/product/ocr/ocrWord.ts b/src/v2/product/ocr/ocrWord.ts new file mode 100644 index 00000000..aca6080e --- /dev/null +++ b/src/v2/product/ocr/ocrWord.ts @@ -0,0 +1,23 @@ +import { Polygon } from "@/geometry/index.js"; +import { StringDict } from "@/parsing/index.js"; + +export class OcrWord { + /** + * Text content of the word. + */ + content: string; + + /** + * Position information as a list of points in clockwise order. + */ + polygon: Polygon; + + constructor(serverResponse: StringDict) { + this.content = serverResponse["content"]; + this.polygon = new Polygon(serverResponse["polygon"]); + } + + toString(): string { + return this.content; + } +} diff --git a/src/v2/product/split/index.ts b/src/v2/product/split/index.ts index 10477bb7..59891e87 100644 --- a/src/v2/product/split/index.ts +++ b/src/v2/product/split/index.ts @@ -2,3 +2,5 @@ export { Split } from "./split.js"; export { SplitParameters } from "./splitParameters.js"; export { SplitResponse } from "./splitResponse.js"; export { SplitInference } from "./splitInference.js"; +export { SplitRange } from "./splitRange.js"; +export { SplitResult } from "./splitResult.js"; diff --git a/src/v2/product/split/splitInference.ts b/src/v2/product/split/splitInference.ts index a195a9b9..eefcbb29 100644 --- a/src/v2/product/split/splitInference.ts +++ b/src/v2/product/split/splitInference.ts @@ -1,23 +1,21 @@ import { StringDict } from "@/parsing/index.js"; import { BaseInference } from "@/v2/parsing/inference/baseInference.js"; +import { SplitResult } from "./splitResult.js"; export class SplitInference extends BaseInference { /** * Result of a split inference. */ - result: any; + result: SplitResult; constructor(serverResponse: StringDict) { super(serverResponse); - this.result = serverResponse["result"]; + this.result = new SplitResult(serverResponse["result"]); } toString(): string { return ( - "Inference\n" + - "#########\n" + - this.model.toString() + "\n" + - this.file.toString() + "\n" + + super.toString() + this.result.toString() + "\n" ); } diff --git a/src/v2/product/split/splitRange.ts b/src/v2/product/split/splitRange.ts new file mode 100644 index 00000000..0974b435 --- /dev/null +++ b/src/v2/product/split/splitRange.ts @@ -0,0 +1,27 @@ +import { StringDict } from "@/parsing/index.js"; + +/** + * Split inference result. + */ +export class SplitRange { + /** + * 0-based page indexes, where the first integer indicates the start page and the + * second integer indicates the end page. + */ + pageRange: number[]; + + /** + * The document type, as identified on given classification values. + */ + documentType: string; + + constructor(serverResponse: StringDict) { + this.pageRange = serverResponse["page_range"]; + this.documentType = serverResponse["document_type"]; + } + + toString(): string { + const pageRange = this.pageRange.join(","); + return `* :Page Range: ${pageRange}\n :Document Type: ${this.documentType}`; + } +} diff --git a/src/v2/product/split/splitResult.ts b/src/v2/product/split/splitResult.ts new file mode 100644 index 00000000..af3b4ec7 --- /dev/null +++ b/src/v2/product/split/splitResult.ts @@ -0,0 +1,24 @@ +import { SplitRange } from "./splitRange.js"; +import { StringDict } from "@/parsing/index.js"; + +/** + * Split result info. + */ +export class SplitResult { + /** + * List of split ranges. + */ + splits: SplitRange[]; + + constructor(rawResponse: StringDict) { + this.splits = rawResponse.splits.map((split: StringDict) => new SplitRange(split)); + } + + toString(): string { + let splits = "\n"; + if (this.splits.length > 0) { + splits += this.splits.map(split => split.toString()).join("\n\n"); + } + return `Splits\n======${splits}`; + } +} diff --git a/tests/test_code_samples.sh b/tests/test_v1_code_samples.sh similarity index 68% rename from tests/test_code_samples.sh rename to tests/test_v1_code_samples.sh index 69528399..27884a9a 100755 --- a/tests/test_code_samples.sh +++ b/tests/test_v1_code_samples.sh @@ -1,12 +1,10 @@ #!/bin/sh set -e -OUTPUT_FILE='../test_code_samples/_test.js' +OUTPUT_FILE='../test_code_samples/_test_v1.js' ACCOUNT=$1 ENDPOINT=$2 -API_KEY=$3 -API_KEY_V2=$4 -MODEL_ID=$5 +API_KEY=${MINDEE_API_KEY} rm -fr ../test_code_samples mkdir ../test_code_samples @@ -15,16 +13,8 @@ cd ../test_code_samples npm install ../mindee-api-nodejs/dist --ignore-scripts --no-bin-links cd - -for f in $(find docs/code_samples -maxdepth 1 -name "*.txt" -not -name "workflow_*.txt" | sort -h) +for f in $(find docs/code_samples -maxdepth 1 -name "*.txt" -not -name "workflow_*.txt" -not -name "v2_*.txt" | sort -h) do - if echo "${f}" | grep -q "default_v2.txt"; then - if [ -z "${API_KEY_V2}" ] || [ -z "${MODEL_ID}" ]; then - echo "Skipping ${f} (API_KEY_V2 or MODEL_ID not supplied)" - echo - continue - fi - fi - echo "###############################################" echo "${f}" echo "###############################################" @@ -33,14 +23,6 @@ do sed "s/my-api-key/$API_KEY/" "${f}" > $OUTPUT_FILE sed -i "s/\/path\/to\/the\/file.ext/..\/mindee-api-nodejs\/tests\/data\/file_types\/pdf\/blank_1.pdf/" $OUTPUT_FILE - if echo "${f}" | grep -q "v2_default.txt" - then - sed -i "s/MY_API_KEY/$API_KEY_V2/" $OUTPUT_FILE - sed -i "s/MY_MODEL_ID/$MODEL_ID/" $OUTPUT_FILE - else - sed -i "s/my-api-key/$API_KEY/" $OUTPUT_FILE - fi - if echo "$f" | grep -q "custom_v1.txt" then sed -i "s/my-account/$ACCOUNT/g" $OUTPUT_FILE diff --git a/tests/test_v2_code_samples.sh b/tests/test_v2_code_samples.sh new file mode 100755 index 00000000..0703482f --- /dev/null +++ b/tests/test_v2_code_samples.sh @@ -0,0 +1,53 @@ +#!/bin/sh +set -e + +OUTPUT_FILE='../test_code_samples/_test_v2.mjs' +API_KEY_V2=${MINDEE_V2_API_KEY} + +rm -fr ../test_code_samples +mkdir ../test_code_samples + +cd ../test_code_samples +npm install ../mindee-api-nodejs/dist --ignore-scripts --no-bin-links +cd - + +for f in $(find docs/code_samples -maxdepth 1 -name "v2_*.txt" | sort -h) +do + echo "###############################################" + echo "${f}" + echo "###############################################" + echo + + sed "s/my-api-key/$API_KEY/" "${f}" > $OUTPUT_FILE + sed -i "s/\/path\/to\/the\/file.ext/..\/mindee-api-nodejs\/tests\/data\/file_types\/pdf\/blank_1.pdf/" $OUTPUT_FILE + + sed -i "s/MY_API_KEY/$API_KEY_V2/" $OUTPUT_FILE + + if echo "${f}" | grep -q "v2_extraction.txt" + then + sed -i "s/MY_MODEL_ID/${MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID}/" $OUTPUT_FILE + fi + + if echo "${f}" | grep -q "v2_classification.txt" + then + sed -i "s/MY_CLASSIFICATION_MODEL_ID/${MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID}/" $OUTPUT_FILE + fi + + if echo "${f}" | grep -q "v2_crop.txt" + then + sed -i "s/MY_CROP_MODEL_ID/${MINDEE_V2_SE_TESTS_CROP_MODEL_ID}/" $OUTPUT_FILE + fi + + if echo "${f}" | grep -q "v2_split.txt" + then + sed -i "s/MY_SPLIT_MODEL_ID/${MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID}/" $OUTPUT_FILE + fi + + if echo "${f}" | grep -q "v2_ocr.txt" + then + sed -i "s/MY_OCR_MODEL_ID/${MINDEE_V2_SE_TESTS_OCR_MODEL_ID}/" $OUTPUT_FILE + fi + + sleep 0.5 # avoid too many request errors + node $OUTPUT_FILE +done diff --git a/tests/v2/client.integration.ts b/tests/v2/client.integration.ts index bc760d42..fd5c7c8f 100644 --- a/tests/v2/client.integration.ts +++ b/tests/v2/client.integration.ts @@ -64,7 +64,7 @@ describe("MindeeV2 – Client Integration Tests", () => { beforeEach(async () => { const apiKey = process.env["MINDEE_V2_API_KEY"] ?? ""; - modelId = process.env["MINDEE_V2_FINDOC_MODEL_ID"] ?? ""; + modelId = process.env["MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID"] ?? ""; client = new Client({ apiKey: apiKey, debug: true }); });