Update 9 files
- /rag/config_models.py - /rag/utils/config_loader.py - /rag/auth.py - /rag/rag_server.py - /rag/rag_api.py - /rag/rag_orchestrator.py - /rag/__init__.py - /bots/xmpp/client.py - /bots/rag_client.py
This commit is contained in:
@@ -9,6 +9,7 @@ RAG-сервер – отдельный HTTP-сервис для обработ
|
||||
- Эндпоинт /rag/vision для распознавания текста на изображениях (OCR)
|
||||
- Эндпоинт /rag/transcribe для транскрибации аудио (SaluteSpeech)
|
||||
- Использование Pydantic-модели AppConfig для конфигурации.
|
||||
- Аутентификация через API-ключ (X-API-Key)
|
||||
"""
|
||||
|
||||
import logging
|
||||
@@ -38,6 +39,7 @@ from .services.kb_service import KBService
|
||||
from .services.giga_client import GigaClient
|
||||
from .services.file_service import FileService
|
||||
from .rag_orchestrator import RAGOrchestrator
|
||||
from .auth import verify_api_key, set_auth_config
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -253,11 +255,11 @@ async def shutdown_event():
|
||||
|
||||
|
||||
# ============================================================
|
||||
# ЭНДПОИНТЫ API
|
||||
# ЭНДПОИНТЫ API (все защищены аутентификацией, кроме /health)
|
||||
# ============================================================
|
||||
|
||||
@app.post("/rag/query", response_model=QueryResponse)
|
||||
async def rag_query(request: QueryRequest):
|
||||
async def rag_query(request: QueryRequest, _: str = Depends(verify_api_key)):
|
||||
"""
|
||||
Выполняет RAG-запрос.
|
||||
ИСТОРИЯ БЕРЁТСЯ СЕРВЕРОМ ИЗ БД (не передаётся в запросе).
|
||||
@@ -288,7 +290,7 @@ async def rag_query(request: QueryRequest):
|
||||
|
||||
|
||||
@app.post("/rag/index", response_model=IndexResponse)
|
||||
async def index_document(request: IndexRequest):
|
||||
async def index_document(request: IndexRequest, _: str = Depends(verify_api_key)):
|
||||
"""Индексирует документ в базу знаний."""
|
||||
orchestrator = get_orchestrator()
|
||||
|
||||
@@ -316,21 +318,16 @@ async def index_document(request: IndexRequest):
|
||||
|
||||
@app.get("/health")
|
||||
async def health_check():
|
||||
"""Проверка здоровья сервиса."""
|
||||
"""Проверка здоровья сервиса (без аутентификации)."""
|
||||
if _orchestrator is None:
|
||||
return {"status": "unhealthy", "message": "Orchestrator not initialized"}
|
||||
return {"status": "healthy"}
|
||||
|
||||
|
||||
# ============================================================
|
||||
# НОВЫЕ ЭНДПОИНТЫ: OCR и транскрибация
|
||||
# ============================================================
|
||||
|
||||
@app.post("/rag/vision", response_model=VisionResponse)
|
||||
async def vision_endpoint(
|
||||
file: UploadFile = FastAPIFile(...),
|
||||
user_jid: str = None,
|
||||
room_jid: str = None
|
||||
_: str = Depends(verify_api_key)
|
||||
):
|
||||
"""
|
||||
Распознаёт текст на изображении через OCR (Tesseract).
|
||||
@@ -370,8 +367,7 @@ async def vision_endpoint(
|
||||
@app.post("/rag/transcribe", response_model=TranscribeResponse)
|
||||
async def transcribe_endpoint(
|
||||
file: UploadFile = FastAPIFile(...),
|
||||
user_jid: str = None,
|
||||
room_jid: str = None
|
||||
_: str = Depends(verify_api_key)
|
||||
):
|
||||
"""
|
||||
Транскрибирует аудиофайл через SaluteSpeech.
|
||||
@@ -450,6 +446,9 @@ def main():
|
||||
logger.info(f"Запуск RAG-сервера с профилем {args.profile_dir}")
|
||||
logger.info(f"Хост: {args.host}, порт: {args.port}")
|
||||
|
||||
# Устанавливаем конфиг для аутентификации
|
||||
set_auth_config(config)
|
||||
|
||||
# Инициализируем оркестратор
|
||||
try:
|
||||
init_orchestrator(config)
|
||||
|
||||
Reference in New Issue
Block a user