feat: add word_confidence_threshold parameter to whisper#33
Conversation
Adds the `word_confidence_threshold` (float, default 0.3) parameter to the v2 client's whisper() method, forwarding it to the API. Words whose OCR confidence falls below the threshold are excluded from the output. Works with form, high_quality and table modes. Adds unit tests covering the default and a custom value. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
| Filename | Overview |
|---|---|
| src/unstract/llmwhisperer/client_v2.py | Adds word_confidence_threshold parameter to whisper() signature, docstring, and params dict; also adds "table" to the mode docstring. No validation is performed client-side, consistent with all other numeric params in this method. |
| tests/unit/client_v2_test.py | Two new unit tests check that the default (0.3) and a custom (0.75) word_confidence_threshold value are forwarded as query params; uses parse_qs on the prepared request URL, which is the correct approach. |
| tests/integration/client_v2_test.py | Pre-test webhook cleanup added to prevent duplicate-registration failures from prior failed runs; no functional changes to the test assertions. |
Sequence Diagram
sequenceDiagram
participant Caller
participant LLMWhispererClientV2
participant LLMWhispererAPI
Caller->>LLMWhispererClientV2: "whisper(url, word_confidence_threshold=0.3, ...)"
Note over LLMWhispererClientV2: Build params dict including<br/>word_confidence_threshold
LLMWhispererClientV2->>LLMWhispererAPI: "POST /whisper?...&word_confidence_threshold=0.3"
LLMWhispererAPI-->>LLMWhispererClientV2: "{"status_code": 200, "extraction": {...}}"
LLMWhispererClientV2-->>Caller: response dict
Reviews (3): Last reviewed commit: "test: delete pre-existing webhook before..." | Re-trigger Greptile
jaseemjaskp
left a comment
There was a problem hiding this comment.
Automated PR Review Toolkit pass (Code Reviewer, Silent Failure Hunter, Type Design Analyzer, PR Test Analyzer, Comment Analyzer, Code Simplifier).
The change is small, additive, and follows the established whisper() convention exactly (new kwarg with default -> entry in the params dict). Blast radius is contained to this one public method; no callers need changes. Inline comments below, ordered by priority. Net recommendation: address the docstring "table" mode inaccuracy and tighten the test assertions; the rest are confirm/optional.
- Add "table" to the list of valid whisper() modes in the docstring - Document the valid range [0.0, 1.0] for word_confidence_threshold and make the wording word-consistent - Assert on the parsed query value (parse_qs) instead of a URL substring so the tests can't false-match on a prefix (e.g. 0.3 vs 0.35) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A webhook left over from a previous failed run caused register_webhook to fail on a stale record. Delete any existing webhook (ignoring not-found) before registering so the test starts from a clean slate. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jaseemjaskp
left a comment
There was a problem hiding this comment.
Re-reviewed the latest revision with the PR Review Toolkit (code review, silent-failure, type-design, test, comment, and simplifier passes). All previously-raised threads have been addressed and resolved. Remaining observations are NIT/Suggestion-level only (no range validation by design — consistent with sibling numeric params; param forwarded for all modes and ignored server-side like include_line_confidence). No correctness, contract, or breaking-change issues found. LGTM 👍
Summary
Adds the new
word_confidence_thresholdparameter to the v2 client'swhisper()method, in sync with llmwhisperer-docs#57.word_confidence_threshold(float, default0.3): the minimum OCR confidence score a word must have to be included in the extracted text. Words below the threshold are excluded from the final output.form,high_qualityandtablemodes.Changes
whisper()signature, docstring, and the requestparamsdict inclient_v2.py.0.3) and a custom value are forwarded as request params.Testing
🤖 Generated with Claude Code