Skip to content

Commit 6d76515

Browse files
✨ add text context option return param (#401)
1 parent 6a326a5 commit 6d76515

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parsing/v2/inferenceActiveOptions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ export class InferenceActiveOptions {
1818
*/
1919
public confidence: boolean;
2020

21+
/**
22+
* Whether the text context feature was activated.
23+
*/
24+
public textContext: boolean;
25+
2126
constructor(serverResponse: StringDict) {
2227
this.rag = serverResponse["rag"];
2328
this.rawText = serverResponse["raw_text"];
2429
this.polygon = serverResponse["polygon"];
2530
this.confidence = serverResponse["confidence"];
31+
this.textContext = serverResponse["text_context"];
2632
}
2733

2834
toString(): string {

tests/v2/clientV2.integration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe("MindeeV2 – Client Integration Tests", () => {
7272
expect(inference.activeOptions?.rawText).to.be.false;
7373
expect(inference.activeOptions?.polygon).to.be.false;
7474
expect(inference.activeOptions?.confidence).to.be.false;
75+
expect(inference.activeOptions?.textContext).to.be.false;
7576
}).timeout(60000);
7677

7778
it("Filled, single-page image – PathInput - enqueueAndGetInference must succeed", async () => {
@@ -107,6 +108,7 @@ describe("MindeeV2 – Client Integration Tests", () => {
107108
expect(inference.activeOptions?.rawText).to.be.true;
108109
expect(inference.activeOptions?.polygon).to.be.true;
109110
expect(inference.activeOptions?.confidence).to.be.false;
111+
expect(inference.activeOptions?.textContext).to.be.true;
110112

111113
expect(inference.result.rawText?.pages).to.have.lengthOf(1);
112114
}).timeout(120000);
@@ -143,6 +145,7 @@ describe("MindeeV2 – Client Integration Tests", () => {
143145
expect(inference.activeOptions?.rawText).to.be.false;
144146
expect(inference.activeOptions?.polygon).to.be.false;
145147
expect(inference.activeOptions?.confidence).to.be.false;
148+
expect(inference.activeOptions?.textContext).to.be.false;
146149
}).timeout(120000);
147150

148151
it("Invalid model ID – enqueue must raise 422", async () => {

tests/v2/input/localResponse.spec.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,34 @@ import { InferenceResponse, LocalResponse } from "../../../src";
44

55
import path from "path";
66
import { V2_RESOURCE_PATH } from "../../index";
7+
import { Buffer } from "node:buffer";
78

8-
const signature: string = "a1bc9012fa63539d602f163d8980604a0cf2b2ae88e56009cfa1db33382736cf";
9+
const signature: string = "b82a515c832fd2c4f4ce3a7e6f53c12e8d10e19223f6cf0e3a9809a7a3da26be";
910
const dummySecretKey: string = "ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH";
1011
const filePath: string = path.join(V2_RESOURCE_PATH, "inference/standard_field_types.json");
1112

13+
async function assertLocalResponse(localResponse: LocalResponse) {
14+
await localResponse.init();
15+
expect(localResponse.asDict()).to.not.be.null;
16+
expect(localResponse.isValidHmacSignature(dummySecretKey, "invalid signature")).to.be.false;
17+
expect(localResponse.getHmacSignature(dummySecretKey)).to.eq(signature);
18+
expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true;
19+
}
20+
1221
describe("MindeeV2 - Load Local Response", () => {
1322
it("should load a string properly.", async () => {
1423
const fileObj = await fs.readFile(filePath, { encoding: "utf-8" });
15-
const localResponse = new LocalResponse(fileObj);
16-
await localResponse.init();
17-
expect(localResponse.asDict()).to.not.be.null;
18-
expect(localResponse.isValidHmacSignature(dummySecretKey, "invalid signature")).to.be.false;
19-
expect(localResponse.getHmacSignature(dummySecretKey)).to.eq(signature);
20-
expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true;
24+
await assertLocalResponse(new LocalResponse(fileObj));
2125
});
2226

2327
it("should load a file properly.", async () => {
24-
const localResponse = new LocalResponse(filePath);
25-
await localResponse.init();
26-
expect(localResponse.asDict()).to.not.be.null;
27-
expect(localResponse.isValidHmacSignature(dummySecretKey, "invalid signature")).to.be.false;
28-
expect(localResponse.getHmacSignature(dummySecretKey)).to.eq(signature);
29-
expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true;
28+
await assertLocalResponse(new LocalResponse(filePath));
3029
});
3130

3231
it("should load a buffer properly.", async () => {
3332
const fileStr = (await fs.readFile(filePath, { encoding: "utf-8" })).replace(/\r/g, "").replace(/\n/g, "");
3433
const fileBuffer = Buffer.from(fileStr, "utf-8");
35-
const localResponse = new LocalResponse(fileBuffer);
36-
await localResponse.init();
37-
expect(localResponse.asDict()).to.not.be.null;
38-
expect(localResponse.isValidHmacSignature(dummySecretKey, "invalid signature")).to.be.false;
39-
expect(localResponse.getHmacSignature(dummySecretKey)).to.eq(signature);
40-
expect(localResponse.isValidHmacSignature(dummySecretKey, signature)).to.be.true;
34+
await assertLocalResponse(new LocalResponse(fileBuffer));
4135
});
4236

4337
it("should deserialize a prediction.", async () => {

0 commit comments

Comments
 (0)