feat(offers): Danish translation and AI matching via Claude

Offers come from the German avis, so add Claude-backed language help,
reusing BlaaAi's ANTHROPIC_API_KEY + Haiku pattern. Both degrade
gracefully: without a key, offers stay German and the token heuristic
still matches.

- Translate offer headings DE→DA in the fetch job, cached per heading
  in a translations table (only new headings cost a call). UI shows
  Danish primary + German subtitle for in-store navigation.
- AI match the fixed list against offers (offer_matches table): Claude
  returns same-product matches, far more precise than the token
  heuristic (which false-matched e.g. Nutella jar → advent calendar).
  load_deals() prefers AI matches, falls back to the heuristic.
- Haiku 5.5 by default (MATCH_MODEL/TRANSLATE_MODEL env overridable to
  Sonnet); no temperature param (Haiku 5.5 rejects non-default).
- requirements: add anthropic
This commit is contained in:
Henrik Jess Nielsen
2026-10-30 11:02:47 +01:00
parent 3b0ea28db5
commit 8dd435a7d0
5 changed files with 182 additions and 10 deletions

View File

@@ -238,7 +238,7 @@
{% if item.get('de') %}<span class="de">🇩🇪 {{ item.de }}</span>{% endif %}
{% if item.get('note') %}<span class="note">{{ item.note }}</span>{% endif %}
{% set d = deals.get(item.key) %}
{% if d %}<a class="deal" href="/tilbud" title="{{ d.heading }} ({{ d.catalog }})">🏷 på tilbud: {{ "{:.2f}".format(d.price_eur).replace(".",",") }} € ≈ {{ "{:.0f}".format(d.price_eur * eur_dkk) }} kr. · {{ d.heading }}</a>{% endif %}
{% if d %}<a class="deal" href="/tilbud" title="{{ d.heading }} ({{ d.catalog }})">🏷 på tilbud: {{ "{:.2f}".format(d.price_eur).replace(".",",") }} € ≈ {{ "{:.0f}".format(d.price_eur * eur_dkk) }} kr. · {{ d.heading_da or d.heading }}</a>{% endif %}
</div>
<div class="item-qty">
<input type="text" value="{{ s.get('qty') or item.qty }}" placeholder="{{ item.qty }}"
@@ -278,7 +278,8 @@
<div class="item-row{% if ps.get('checked') %} checked{% endif %}" data-key="{{ o.id }}" id="pick-{{ o.id }}">
<div class="item-check"><input type="checkbox" {% if ps.get('checked') %}checked{% endif %} onchange="toggleOffer(this)"></div>
<div class="item-name">
{{ o.heading }}
{{ o.heading_da or o.heading }}
{% if o.heading_da and o.heading_da != o.heading %}<span class="de">🇩🇪 {{ o.heading }}</span>{% endif %}
<span class="note">{{ o.catalog }}{% if o.page %} · s. {{ o.page }}{% endif %}{% if o.unit %} · {{ o.size_from|int if o.size_from else '' }}{{ o.unit }}{% endif %}</span>
</div>
<div class="item-qty" style="display:flex;align-items:center;color:var(--muted);font-size:12px">