diff --git a/index.js b/index.js index 9f6f0f9..ac38364 100644 --- a/index.js +++ b/index.js @@ -184,7 +184,12 @@ class LLMWhispererClientV2 { * @param {boolean} [options.addLineNos=false] - If true, adds line numbers to the extracted text * and saves line metadata, which can be queried later * using the highlights API. - + * @param {number} [options.wordConfidenceThreshold=0.3] - The minimum OCR confidence score a word must + * have to be included in the extracted text. Any text whose confidence + * value falls below the configured threshold is ignored and excluded + * from the final output. This parameter works only with "form", + * "high_quality" and "table" modes. + * * @returns {Promise} The response from the whisper API. * @throws {LLMWhispererClientException} If there is an error in the request. */ @@ -210,6 +215,7 @@ class LLMWhispererClientV2 { waitForCompletion = false, waitTimeout = 180, addLineNos = false, + wordConfidenceThreshold = 0.3, } = {}) { this.logger.debug("whisper called"); const apiUrl = `${this.baseUrl}/whisper`; @@ -234,6 +240,7 @@ class LLMWhispererClientV2 { wait_for_completion: waitForCompletion, wait_timeout: waitTimeout, add_line_nos: addLineNos, + word_confidence_threshold: wordConfidenceThreshold, }; this.logger.debug(`api_url: ${apiUrl}`); diff --git a/package-lock.json b/package-lock.json index 272c683..02b01cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "llmwhisperer-client", - "version": "2.5.1", + "version": "2.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "llmwhisperer-client", - "version": "2.5.1", + "version": "2.6.0", "license": "MIT", "dependencies": { "axios": "~1.17.0", diff --git a/package.json b/package.json index e6e6d85..02207fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "llmwhisperer-client", - "version": "2.5.1", + "version": "2.6.0", "description": "LLMWhisper JS Client", "main": "index.js", "scripts": { diff --git a/test/retry.test.js b/test/retry.test.js index 89d2497..eff4f40 100644 --- a/test/retry.test.js +++ b/test/retry.test.js @@ -328,3 +328,42 @@ describe("Logging on retries", () => { expect(warnCall).toMatch(/503/); }); }); + +describe("whisper word_confidence_threshold param", () => { + test("forwards a custom wordConfidenceThreshold as word_confidence_threshold", async () => { + const client = createV2Client(); + let capturedConfig; + client.client.defaults.adapter = (config) => { + capturedConfig = config; + return Promise.resolve({ + status: 202, + data: { whisper_hash: "h" }, + headers: {}, + config, + }); + }; + + await client.whisper({ + url: "https://example.com/doc.pdf", + wordConfidenceThreshold: 0.7, + }); + expect(capturedConfig.params.word_confidence_threshold).toBe(0.7); + }); + + test("sends the default word_confidence_threshold of 0.3 when omitted", async () => { + const client = createV2Client(); + let capturedConfig; + client.client.defaults.adapter = (config) => { + capturedConfig = config; + return Promise.resolve({ + status: 202, + data: { whisper_hash: "h" }, + headers: {}, + config, + }); + }; + + await client.whisper({ url: "https://example.com/doc.pdf" }); + expect(capturedConfig.params.word_confidence_threshold).toBe(0.3); + }); +});