1cdc532fff
- pytest suite for doc-service: 20+ tests covering category CRUD, document upload/get/delete/patch, ownership isolation, category assignment, AI processing (mock), and live PDF tests (auto-skipped when tests/pdfs/ is empty) - Minimal in-memory PDF builder in conftest so tests run without any fixture files; real PDFs can be dropped into tests/pdfs/ to activate live extraction tests - AI prompt updated to return suggested_categories (2–5 short names) - Frontend: SuggestionChip component in DocumentRow shows AI-suggested categories after processing; "Assign" links to an existing category, "Create & Assign" creates it first, ✕ dismisses locally - Default AI provider changed to LM Studio at http://host.docker.internal:1234/v1 (host.docker.internal resolves to the macOS host from inside Docker Desktop) - tests/pdfs/ directory tracked via .gitkeep; *.pdf excluded by .gitignore Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
"""
|
|
Reads doc_service_config.json from the shared config volume.
|
|
Caches the result for 30 seconds to avoid hitting the filesystem on every request.
|
|
Uses asyncio.to_thread so the synchronous file read doesn't block the event loop.
|
|
"""
|
|
import asyncio
|
|
import json
|
|
import time
|
|
from pathlib import Path
|
|
|
|
from app.core.config import settings
|
|
|
|
_DEFAULT_CONFIG: dict = {
|
|
"ai": {
|
|
# Default: LM Studio running on the host machine at port 1234.
|
|
# Inside Docker, host.docker.internal resolves to the host; for local
|
|
# dev outside Docker use http://localhost:1234/v1 instead.
|
|
"provider": "lmstudio",
|
|
"anthropic": {"api_key": "", "model": "claude-haiku-4-5-20251001"},
|
|
"ollama": {"base_url": "http://host.docker.internal:11434/v1", "model": "llama3.2", "api_key": "ollama"},
|
|
"lmstudio": {"base_url": "http://host.docker.internal:1234/v1", "model": "local-model", "api_key": "lm-studio"},
|
|
},
|
|
"documents": {"max_pdf_bytes": 20 * 1024 * 1024},
|
|
}
|
|
|
|
_cache: dict | None = None
|
|
_cache_at: float = 0.0
|
|
_CACHE_TTL = 30.0
|
|
|
|
|
|
def _read_config_sync() -> dict:
|
|
path = Path(settings.CONFIG_PATH)
|
|
if not path.exists():
|
|
return _DEFAULT_CONFIG.copy()
|
|
with open(path) as f:
|
|
return json.load(f)
|
|
|
|
|
|
async def load_doc_config() -> dict:
|
|
global _cache, _cache_at
|
|
now = time.monotonic()
|
|
if _cache is not None and (now - _cache_at) < _CACHE_TTL:
|
|
return _cache
|
|
data = await asyncio.to_thread(_read_config_sync)
|
|
_cache = data
|
|
_cache_at = now
|
|
return data
|