2026-05-18 16:32:42 +08:00
|
|
|
"""Define API routes for status."""
|
|
|
|
|
|
2026-05-14 15:07:34 +08:00
|
|
|
from fastapi import APIRouter
|
2026-05-18 16:32:42 +08:00
|
|
|
|
|
|
|
|
from app.config.settings import settings
|
|
|
|
|
from app.shared.bootstrap import get_document_query_service, get_vector_index
|
|
|
|
|
# Keep route handlers close to their transport-layer wiring for easier auditing.
|
|
|
|
|
|
2026-05-14 15:07:34 +08:00
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/status", tags=["系统状态"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/stats")
|
|
|
|
|
async def get_stats():
|
2026-05-18 16:32:42 +08:00
|
|
|
"""Return stats."""
|
|
|
|
|
documents = get_document_query_service().list_documents()
|
|
|
|
|
indexed = sum(1 for item in documents if item.status.value == "indexed")
|
|
|
|
|
failed = sum(1 for item in documents if item.status.value == "failed")
|
|
|
|
|
return {
|
|
|
|
|
"documents_total": len(documents),
|
|
|
|
|
"documents_indexed": indexed,
|
|
|
|
|
"documents_failed": failed,
|
|
|
|
|
"chunks_total": sum(item.chunk_count for item in documents),
|
|
|
|
|
}
|
2026-05-14 15:07:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/config")
|
|
|
|
|
async def get_config():
|
2026-05-18 16:32:42 +08:00
|
|
|
"""Return config."""
|
|
|
|
|
return {
|
|
|
|
|
"embedding_model": settings.embedding_model,
|
|
|
|
|
"embedding_dim": settings.embedding_dim,
|
|
|
|
|
"embedding_base_url": settings.embedding_base_url,
|
|
|
|
|
"milvus_collection": settings.milvus_collection,
|
|
|
|
|
"llm_provider": settings.llm_provider,
|
|
|
|
|
"llm_model": settings.llm_model,
|
|
|
|
|
"document_metadata_path": settings.document_metadata_path,
|
|
|
|
|
}
|
2026-05-14 15:07:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/milvus/health")
|
|
|
|
|
async def milvus_health():
|
2026-05-18 16:32:42 +08:00
|
|
|
"""Handle milvus health."""
|
|
|
|
|
return get_vector_index().health()
|