innercontext/backend/innercontext/models
Piotr Oleszczyk c87d1b8581 feat(api): implement Phase 2 token optimization and reasoning capture
- Add tiered context system (summary/detailed/full) to reduce token usage by 70-80%
- Replace old _build_products_context with build_products_context_summary_list (Tier 1: ~15 tokens/product vs 150)
- Optimize function tool responses: exclude INCI list by default (saves ~15KB/product)
- Reduce actives from 24 to top 5 in function tools
- Add reasoning_chain field to AICallLog model for observability
- Implement _extract_thinking_content to capture LLM reasoning (MEDIUM thinking level)
- Strengthen prompt enforcement for prohibited fields (dose, amount, quantity)
- Update get_creative_config to use MEDIUM thinking level instead of LOW

Token Savings:
- Routine suggestions: 9,613 → ~1,300 tokens (-86%)
- Batch planning: 12,580 → ~1,800 tokens (-86%)
- Function tool responses: ~15KB → ~2KB per product (-87%)

Breaks discovered in log analysis (ai_call_log.json):
- Lines 10, 27, 61, 78: LLM returned prohibited dose field
- Line 85: MAX_TOKENS failure (output truncated)

Phase 2 complete. Next: two-phase batch planning with safety verification.
2026-03-06 10:26:29 +01:00
..
__init__.py style: apply black and isort formatting 2026-03-06 10:17:00 +01:00
ai_log.py feat(api): implement Phase 2 token optimization and reasoning capture 2026-03-06 10:26:29 +01:00
base.py Initial commit: backend API, data models, and test suite 2026-02-26 15:10:24 +01:00
domain.py Initial commit: backend API, data models, and test suite 2026-02-26 15:10:24 +01:00
enums.py feat(profile): add profile settings and LLM user context 2026-03-05 15:57:21 +01:00
health.py fix(models): add cascade delete-orphan to parent-child relationships 2026-03-01 00:59:10 +01:00
pricing.py feat(backend): move product pricing to async persisted jobs 2026-03-04 22:46:16 +01:00
product.py refactor(products): remove usage notes and contraindications fields 2026-03-05 10:11:24 +01:00
profile.py feat(profile): add profile settings and LLM user context 2026-03-05 15:57:21 +01:00
routine.py fix(models): add cascade delete-orphan to parent-child relationships 2026-03-01 00:59:10 +01:00
skincare.py refactor(skin): replace trend with texture field on SkinConditionSnapshot 2026-02-28 13:25:57 +01:00