AI bean import: roast date derivation, rotated OCR, text size fix, logging - #2
Merged
Merged
Conversation
… offset Cloud AI prompt now instructs the model to calculate the roast date by subtracting the stated period from a best-before/expiration date when no explicit roast date is present but the label explicitly describes the offset (e.g. 'roasted 12 months before best before date'). The hint notes this may be stated in the local language of the label.
…bels Run OCR at 0°, 90°, and 270° for each image to detect text printed sideways on labels. Rotated-pass blocks are classified using the 0° pass height statistics as baseline and merged into the enriched text under a '--- Rotated text detected ---' section (only when rotated passes actually find text).
… classifyHeight helper
… remove noise Log prompt and response for both Apple Intelligence (in sendLLMPrompt) and Cloud LLM (in cloud-field-extraction) to make debugging easier. Suppress the deleteChat 'not implemented' error on iOS. Remove 18 verbose log calls (base64 lengths, OCR JSON dumps, photo processing progress) that cluttered output without aiding diagnosis.
…height A multi-line paragraph in small font produces a tall bounding box, causing misclassification as LARGE. Use average line height within each block as proxy for font size, falling back to block height when line data is unavailable.
- Remove no-op test asserting block texts on raw string (no layout logic exercised) - Remove subsumed rotated-section test, move hasUsefulMetadata assertion into classification loop - Modify shouldUseMetadata test to use line data, proving representative height drives decision - Extract boundingBoxHeight() to eliminate duplication in getRepresentativeHeight - Refactor createBlock to use options object instead of 7 positional params
silasg
force-pushed
the
feat/ai-bean-import-enhancements
branch
from
March 28, 2026 18:33
eb4eed5 to
7b26edb
Compare
silasg
commented
Mar 28, 2026
| }); | ||
|
|
||
| [90, 270].forEach((degrees) => { | ||
| it(`should produce a non-empty base64 string without data URL prefix when rotated by ${degrees}°`, async () => { |
Owner
Author
There was a problem hiding this comment.
How does this test it was rotated? Does it make sense to generate the expected image as well and compare those?
| ); | ||
|
|
||
| const ocrResult = await this.ocrWithRotations(imageData.base64String); | ||
| const rawText = ocrResult.primary.text; |
Owner
Author
There was a problem hiding this comment.
Does this mean rawtext does not include rotated text, even when found? Why is this not a problem?
| img.onload = () => { | ||
| const canvas = document.createElement('canvas'); | ||
| const ctx = canvas.getContext('2d'); | ||
| if (!ctx) { |
Owner
Author
There was a problem hiding this comment.
Why do we need this check?
|
|
||
| // Collect all rotated blocks | ||
| const rotatedBlocks = multiPass.rotated.flatMap((r) => r.blocks ?? []); | ||
| if (rotatedBlocks.length === 0) { |
Owner
Author
There was a problem hiding this comment.
Isn't this check the same as L150?
- Strengthen rotation test to verify dimensions are swapped (4×2 → 2×4) - Include rotated pass text in rawText via extracted collectRawText() - Replace canvas context null guard with optional chaining - Collapse duplicate early-return guards in enrichWithLayoutMultiPass - Extract stripLayoutHeader() to eliminate duplicated regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Key improvements