feat(03-04): retire flat-file settings; wire per-user AI config via DB lookup
- config.py: Remove SETTINGS_FILE, DEFAULT_SYSTEM_PROMPT, DEFAULT_SETTINGS constants; add system_prompt, default_ai_provider, default_ai_model to Settings - services/classifier.py: Add _DEFAULT_SYSTEM_PROMPT module constant; classify_document and suggest_topics_for_document accept ai_provider/ai_model kwargs; no longer calls storage.load_settings() — uses app_settings defaults with DB-supplied overrides (D-14, D-15) - services/storage.py: Delete load_settings, save_settings, mask_api_key, settings_masked; remove from __all__; remove import copy, json, DEFAULT_SETTINGS, SETTINGS_FILE (D-12) - tasks/document_tasks.py: _run resolves user.ai_provider/ai_model via session.get(User, doc.user_id) and passes through to classifier; task signature unchanged (T-03-19) - api/settings.py: Deleted — /api/settings endpoint removed (D-12) - main.py: Remove settings_router import and include_router call - tests/test_settings.py: Replace all tests with test_settings_endpoint_removed (404, green) - tests/test_classifier.py: Implement test_per_user_provider, test_celery_task_uses_user_provider, test_default_provider_fallback; remove xfail markers (DOC-03, DOC-05)
This commit is contained in:
@@ -52,6 +52,13 @@ async def _run(document_id: str) -> dict:
|
||||
if not doc.object_key:
|
||||
return {"document_id": document_id, "status": "missing_object"}
|
||||
|
||||
# ── Resolve per-user AI config (D-14, D-15) ────────────────────────────
|
||||
from db.models import User
|
||||
from config import settings as app_settings
|
||||
user = await session.get(User, doc.user_id) if doc.user_id else None
|
||||
ai_provider = (user.ai_provider if user else None) or app_settings.default_ai_provider
|
||||
ai_model = (user.ai_model if user else None) or app_settings.default_ai_model
|
||||
|
||||
# ── Step 2: retrieve bytes from MinIO ──────────────────────────────────
|
||||
try:
|
||||
backend = get_storage_backend()
|
||||
@@ -77,7 +84,7 @@ async def _run(document_id: str) -> dict:
|
||||
|
||||
# ── Step 4: classify document (non-fatal) ──────────────────────────────
|
||||
try:
|
||||
topics = await classifier.classify_document(session, document_id)
|
||||
topics = await classifier.classify_document(session, document_id, ai_provider=ai_provider, ai_model=ai_model)
|
||||
return {
|
||||
"document_id": document_id,
|
||||
"status": "classified",
|
||||
|
||||
Reference in New Issue
Block a user