9cbf1ab367
- pyproject.toml -> 0.3.0 (significant changes since 0.2.0: full Phase 1-7 KB stack, classifier+labels, batch-upload UI, pending-review panel, bucket rename to legal-kb) - api/__init__.py reads version from pyproject at import time so /api/health and OpenAPI both reflect reality without a second hardcoded copy - api/services/kb/voyage.py: _post_with_retry wraps embed/rerank POSTs with exponential backoff on 429+5xx (max 5 retries, base 2s, capped 30s, +25% jitter, honors Retry-After header). Dev and prod share a single VOYAGE_API_KEY today, so a simultaneous bulk re-ingest on both used to fail half the calls; now the burst is absorbed in seconds. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
"""shira-hermes — FastAPI application."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from api import __version__
|
|
from api.routes.admin_kb import router as admin_kb_router
|
|
from api.routes.health import router as health_router
|
|
from api.routes.kb_public import router as kb_public_router
|
|
from api.routes.smart_assistant import router as smart_assistant_router
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s [%(name)s] %(levelname)s: %(message)s",
|
|
)
|
|
|
|
logger = logging.getLogger("shira.app")
|
|
|
|
app = FastAPI(
|
|
title="shira-hermes",
|
|
description="Shira AI Assistant — Hermes Agent backend for EspoCRM SmartAssistant",
|
|
version=__version__,
|
|
)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_methods=["GET", "POST", "OPTIONS"],
|
|
allow_headers=["Content-Type", "X-Api-Key"],
|
|
)
|
|
|
|
app.include_router(health_router)
|
|
app.include_router(smart_assistant_router)
|
|
app.include_router(admin_kb_router)
|
|
app.include_router(kb_public_router)
|
|
|
|
|
|
@app.on_event("startup")
|
|
async def ensure_data_dirs():
|
|
"""Create persistent data directories if they don't exist."""
|
|
data_dir = os.environ.get("SHIRA_DATA_DIR", "/opt/data")
|
|
dirs = [
|
|
f"{data_dir}/skills",
|
|
f"{data_dir}/profiles",
|
|
f"{data_dir}/cases",
|
|
]
|
|
for d in dirs:
|
|
Path(d).mkdir(parents=True, exist_ok=True)
|
|
logger.info("Data directories ready at %s", data_dir)
|