Skip to content

Feat/ai bean import enhancements#1105

Merged
graphefruit merged 7 commits intographefruit:developfrom
silasg:feat/ai-bean-import-enhancements
Mar 29, 2026
Merged

Feat/ai bean import enhancements#1105
graphefruit merged 7 commits intographefruit:developfrom
silasg:feat/ai-bean-import-enhancements

Conversation

@silasg
Copy link
Copy Markdown
Contributor

@silasg silasg commented Mar 29, 2026

This PR bundles different improvements for the AI based bean import feature:

  1. Roast date from best-before (cloud based LLMs only): Derive roast date when label states an offset (e.g. "best before 12 months after roasting")
  2. Rotated OCR: Detect 90°-rotated text on coffee labels via additional OCR passes
  3. Text size classification improvement: Use average line height instead of block bounding box height — prevents tall paragraphs from being misclassified as headings
  4. Logging improvement: Add LLM prompt/response UI logs to better understand how the feature works with dedicated label/model combinations if users report problems, remove noisy log lines, esp. from OCR

silasg added 7 commits March 28, 2026 19:33
… 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).
… 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
- 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
@graphefruit
Copy link
Copy Markdown
Owner

Thank you for the PR! Looks good to me!

@graphefruit graphefruit merged commit e3d4e67 into graphefruit:develop Mar 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants