Unit Tests / test (push) Successful in 13s
## Summary Implements [chat_backend#6](#6) Part A: - **uv** packaging (`pyproject.toml` + `uv.lock`), Docker/compose (dev + prod), entrypoint/validate-env, Gitea unit-test + auto-deploy workflows (mirror `scha`) - Env-driven Django settings (`DJANGO_*`, `DATABASE_URL`, CSRF/CORS) - **`OLLAMA_BASE_URL`** wired through all Ollama/LangChain clients (prod → `http://10.0.0.128:11434`) - **DatabaseStorage** — prompt/document file blobs in Postgres (`StoredFile`), not container FS; RAG materializes temp paths for loaders - ASGI via `gunicorn` + `UvicornWorker` (HTTP + WebSockets) Companion server-infra PR registers `app_catalog` / `host_apps` (port **8003**). ## Test plan - [ ] `uv sync && cd llm_be && SKIP_RAG_INIT=1 uv run python manage.py test` - [ ] `docker compose build && docker compose up` against bundled Postgres - [ ] Confirm Ollama calls use `OLLAMA_BASE_URL` (not hardcoded localhost) - [ ] Upload a document / prompt file → row in `chat_backend_storedfile`, no disk under `media/` - [ ] After server-infra merge + secret/Postgres/NPM: deploy via `deploy.sh --app chat_backend --env prod`Reviewed-on: #7
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
from django.apps import AppConfig
|
|
from django.conf import settings
|
|
from django.db import OperationalError, ProgrammingError
|
|
import os
|
|
import sys
|
|
|
|
|
|
class ChatBackendConfig(AppConfig):
|
|
default_auto_field = "django.db.models.BigAutoField"
|
|
name = "chat_backend"
|
|
|
|
def ready(self):
|
|
import chat_backend.signals
|
|
|
|
# Skip heavy Ollama/Chroma init during migrate/collectstatic/test/CI.
|
|
management_cmds = {
|
|
"migrate",
|
|
"makemigrations",
|
|
"collectstatic",
|
|
"test",
|
|
"shell",
|
|
"check",
|
|
}
|
|
if any(cmd in sys.argv for cmd in management_cmds):
|
|
return
|
|
if os.environ.get("SKIP_RAG_INIT", "").lower() in {"1", "true", "yes"}:
|
|
return
|
|
|
|
FORCE_RELOAD = False
|
|
|
|
try:
|
|
from .services.rag_services import AsyncRAGService
|
|
from chat_backend.models import Document
|
|
|
|
if Document.objects.exists():
|
|
rag_service = AsyncRAGService()
|
|
|
|
if rag_service.vector_store._collection.count() == 0:
|
|
print("Initializing ChromaDB with existing documents...")
|
|
rag_service.ingest_documents()
|
|
if FORCE_RELOAD:
|
|
print("Force Reload ChromaDB with existing documents...")
|
|
rag_service.clear_vector_store()
|
|
except (OperationalError, ProgrammingError):
|
|
# Database tables might not exist yet during migration
|
|
pass
|
|
except Exception as exc:
|
|
# Ollama/Chroma unreachable must not block process start.
|
|
print(f"Skipping RAG init at startup: {exc}")
|