No description
Add comprehensive token breakdown logging to understand MAX_TOKENS behavior and verify documentation claims about thinking tokens. New Fields Added to ai_call_logs: - thoughts_tokens: Thinking tokens (thoughtsTokenCount) - documented as separate from output budget - tool_use_prompt_tokens: Tool use overhead (toolUsePromptTokenCount) - cached_content_tokens: Cached content tokens (cachedContentTokenCount) Purpose: Investigate token counting mystery from production logs where: prompt_tokens: 4400 completion_tokens: 589 total_tokens: 8489 ← Should be 4400 + 589 = 4989, missing 3500! According to Gemini API docs (Polish translation): totalTokenCount = promptTokenCount + candidatesTokenCount (thoughts NOT included in total) But production logs show 3500 token gap. New logging will reveal: 1. Are thinking tokens actually separate from max_output_tokens limit? 2. Where did the 3500 missing tokens go? 3. Does MEDIUM thinking level consume output budget despite docs? 4. Are tool use tokens included in total but not shown separately? Changes: - Added 3 new integer columns to ai_call_logs (nullable) - Enhanced llm.py to capture all usage_metadata fields - Used getattr() for safe access (fields may not exist in all responses) - Database migration: 7e6f73d1cc95 This will provide complete data for future LLM calls to diagnose: - MAX_TOKENS failures - Token budget behavior - Thinking token costs - Tool use overhead |
||
|---|---|---|
| backend | ||
| docs | ||
| frontend | ||
| nginx | ||
| systemd | ||
| .gitignore | ||
| AGENTS.md | ||
| deploy.sh | ||
| PHASE1_COMPLETE.md | ||
| README.md | ||
innercontext
Personal health and skincare data hub. Collects structured data (products, routines, lab results, medications, skin snapshots) and exposes it via a REST API and a web UI to an LLM agent.
Repository layout
backend/ Python backend — FastAPI REST API + SQLModel models
frontend/ SvelteKit web UI (Svelte 5, TypeScript, Tailwind CSS v4)
docs/ Deployment guides
nginx/ nginx config for production
systemd/ systemd service units
Backend quick start
Requirements: Python 3.12+, PostgreSQL, uv
cd backend
# Install dependencies
uv sync
# Set database URL (defaults to postgresql+psycopg://localhost/innercontext)
export DATABASE_URL=postgresql+psycopg://user:password@localhost/innercontext
# Start the API server (creates tables on first run)
uv run uvicorn main:app --reload
API docs available at http://localhost:8000/docs.
Frontend quick start
Requirements: Node.js 24 LTS+, pnpm
cd frontend
# Install dependencies
pnpm install
# Start dev server (proxies API calls to localhost:8000)
pnpm dev
UI available at http://localhost:5173.
API overview
| Prefix | Resource |
|---|---|
/products |
Skincare / medication products + inventory |
/inventory |
Individual inventory entries |
/health/medications |
Medication entries and usage history |
/health/lab-results |
Lab test results |
/routines |
AM/PM skincare routines and steps |
/routines/grooming-schedule |
Weekly grooming schedule |
/skincare |
Weekly skin condition snapshots |
/profile |
User profile (birth date, sex at birth) |
/health-check |
Liveness probe |
Frontend routes
| Route | Description |
|---|---|
/ |
Dashboard |
/products |
Product list |
/products/new |
Add product |
/products/[id] |
Product detail / edit |
/routines |
Routine list |
/routines/new |
Create routine |
/routines/[id] |
Routine detail |
/health/medications |
Medications |
/health/lab-results |
Lab results |
/skin |
Skin condition snapshots |
/profile |
User profile |
Development
cd backend
# Lint
uv run ruff check .
# Format
uv run black .
uv run isort .
# Tests
uv run pytest
Stack
- Backend: Python 3.12, FastAPI, Uvicorn, SQLModel 0.0.37 + SQLAlchemy, Pydantic v2, PostgreSQL (psycopg3)
- Frontend: SvelteKit 2, Svelte 5 (Runes), TypeScript, Tailwind CSS v4, shadcn-svelte
Deployment
See docs/DEPLOYMENT.md for a step-by-step guide for a Proxmox LXC setup (Debian 13, nginx, systemd services).