Files
Business-Management/changelog/2026-04-14_doc-service-tests-suggestions.md
curo1305 88c1ea297e Add shared ai-service container as AI provider intermediary
All feature containers now POST messages to ai-service (port 8010) instead
of calling AI providers directly. ai-service routes to LM Studio, Ollama,
or Anthropic based on /config/ai_service_config.json. doc-service AI
providers removed; replaced by httpx ai_client.py. Backend settings
restructured to /api/settings/ai. Frontend gets dedicated AIAdminSettingsPage
and AI Service card in AppsPage.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 12:30:45 +02:00

4.6 KiB
Raw Permalink Blame History

2026-04-14 — Doc-service tests, AI category suggestions, LM Studio default

Timestamp: 2026-04-14T00:00:00+00:00

Summary

Added pytest test suite for doc-service, updated the AI prompt to return suggested categories, wired up a suggestions UI in DocumentsPage (per-suggestion Accept/Create&Assign/Dismiss), changed the default AI provider to LM Studio at host.docker.internal:1234, and created a gitignored test PDF directory.

Files Added

  • features/doc-service/tests/__init__.py
  • features/doc-service/tests/conftest.py — SQLite in-memory DB, tmp DATA_DIR, mock AI provider, minimal+invoice PDF builders, real_pdfs fixture (auto-skips if no PDFs present)
  • features/doc-service/tests/test_categories.py — full CRUD + per-user isolation
  • features/doc-service/tests/test_documents.py — upload, list, get, status, delete, category assignment, AI processing integration, live PDF tests
  • features/doc-service/tests/pdfs/.gitkeep — tracked empty directory; drop PDFs here for live testing

Files Modified

  • .gitignore — ignore features/doc-service/tests/pdfs/*.pdf
  • features/doc-service/pyproject.toml — added aiosqlite>=0.20 to dev deps
  • features/doc-service/app/services/ai/base.py — added suggested_categories to AI prompt (25 category names per document)
  • features/doc-service/app/services/config_reader.py — default provider changed to lmstudio; URLs changed to host.docker.internal:1234/v1 (Docker→host resolution on macOS/Windows)
  • backend/app/core/app_config.py — default LMStudioConfig.base_url = http://host.docker.internal:1234/v1; default provider = lmstudio
  • frontend/src/pages/DocumentsPage.tsx — added SuggestionChip component and suggested_categories section in DocumentRow: checks if suggestion already exists as a user category, shows "Assign" (existing) or "Create & Assign" (new), dismiss removes from local state

2026-04-14 — AI service container (shared AI intermediary)

Timestamp: 2026-04-14T12:00:00+00:00

Summary

Extracted all AI provider logic from doc-service into a new standalone ai-service container (port 8010). All feature containers now POST messages to ai-service instead of calling AI providers directly. Added tests for ai-service, updated backend settings routes to /api/settings/ai, added AI Service card to frontend AppsPage with dedicated settings page.

Files Added

  • features/ai-service/ — full new microservice: Dockerfile, pyproject.toml, scripts/, app/ (providers, schemas, routers, services), tests/
  • features/ai-service/.env — gitignored, holds LM Studio API key for dev
  • features/ai-service/.env.example
  • features/doc-service/app/services/prompts.py — domain prompts extracted from deleted base.py
  • features/doc-service/app/services/ai_client.py — httpx client that calls ai-service /chat

Files Modified

  • features/doc-service/app/routers/documents.py — replaced provider call with classify_document()
  • features/doc-service/app/services/config_reader.py — removed AI config section (owned by ai-service now)
  • features/doc-service/app/core/config.py — added AI_SERVICE_URL setting
  • features/doc-service/pyproject.toml — removed anthropic/openai, added httpx
  • features/doc-service/.env — removed LMSTUDIO_* vars, added AI_SERVICE_URL
  • features/doc-service/tests/conftest.py — renamed mock_ai → mock_ai_service, patching classify_document
  • features/doc-service/tests/test_documents.py — mock_ai → mock_ai_service; added graceful 502 test
  • backend/app/core/app_config.py — AIServiceConfig split from DocServiceConfig; new load/save/mask helpers
  • backend/app/core/config.py — added AI_SERVICE_URL setting
  • backend/app/routers/settings.py — new /api/settings/ai routes; test endpoint proxies to ai-service via httpx
  • docker-compose.yml — added ai-service container; AI_SERVICE_URL env on backend + doc-service
  • docker-compose.dev.yml — added ai-service dev override with hot reload and .env
  • frontend/src/api/client.ts — renamed getDocumentSettings→getAISettings, updateDocumentAISettings→updateAISettings, testDocumentAIConnection→testAIConnection; added getDocumentLimits
  • frontend/src/pages/AIAdminSettingsPage.tsx — new page at /apps/ai/settings/admin
  • frontend/src/pages/DocumentAdminSettingsPage.tsx — now shows Upload Limits only
  • frontend/src/pages/AppsPage.tsx — added AI Service card (admin settings link, no Open button)
  • frontend/src/App.tsx — added /apps/ai/settings/admin route

Files Deleted

  • features/doc-service/app/services/ai/ — anthropic_provider.py, openai_compat.py, base.py, __init__.py