From 83fa8ed734b561847836dbec674832011b6fc746 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Thu, 18 Dec 2025 16:57:23 +0100 Subject: [PATCH] feat: Add AI extraction schemas and prompt templates, and refine price extraction logic to prioritize TTC over HT. --- app/ai_schema.py | 7 +++++-- task.md | 1 + verify_extraction_logic.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/ai_schema.py b/app/ai_schema.py index 2d4aadd..31c7bc4 100644 --- a/app/ai_schema.py +++ b/app/ai_schema.py @@ -142,8 +142,11 @@ EXTRACTION_PROMPT_TEMPLATE = """Extract product price and stock status from this - Extract as DECIMAL NUMBER: If you see "3.99", return 3.99 - Ignore crossed-out/barré prices (old prices) - **CRITICAL:** Ignore "Prix au litre", "Prix au kg", "P.U.", or unit prices usually shown in smaller text/parentheses (e.g., "4.60 € / L"). -- If multiple prices, take the current/main price (not the original, not the unit price) -- **B&M STORES Specific:** The main price is often large and bold (e.g. "1.15€"), while unit price is small (e.g. "4.60 €/L"). ALWAYS take the main price. +- **CRITICAL:** If you see both HT (Hors Taxe) and TTC (Toutes Taxes Comprises) prices, **ALWAYS select the TTC price**. +- Look for labels like "Taxe incluse", "TTC", "Prix payé". Ignore "HT" or "Hors Taxe". +- Example: If text has "1.15 € HT" and "1.38 € TTC", return 1.38 (NOT 1.15). +- If multiple prices, take the current/main price (not the original, not the unit price, not the HT price) +- **B&M STORES Specific:** The main price is often large and bold (e.g. "1.38€"), while unit price is small. ALWAYS take the main price (TTC). Ignore hidden HT prices (e.g. 1.15€). **CRITICAL - Common mistakes to avoid:** - "3.99 €" means 3.99 (NOT 399.00, NOT 3990.00) diff --git a/task.md b/task.md index 53e9bc7..296c011 100644 --- a/task.md +++ b/task.md @@ -37,3 +37,4 @@ Improving price extraction reliability for B&M Stores and others. - Improved AI prompt to ignore unit prices (like "Prix au litre"). - Enhanced text extraction to remove menu/footer noise. - Verified logic with `verify_extraction_logic.py` (simulated). +- **Fixed HT vs TTC issue**: AI was extracting 1.15€ (HT) instead of 1.38€ (TTC). Updated prompt to prioritize "Taxe incluse"/TTC prices. diff --git a/verify_extraction_logic.py b/verify_extraction_logic.py index 713dec8..3e3e8ba 100644 --- a/verify_extraction_logic.py +++ b/verify_extraction_logic.py @@ -118,7 +118,9 @@ async def verify_extraction_logic(): "CRITICAL", "Ignore \"Prix au litre\"", "B&M STORES Specific", - "Extract as DECIMAL NUMBER" + "Extract as DECIMAL NUMBER", + "ALWAYS select the TTC price", + "Ignore \"HT\"" ] all_passed = True