feat(azure-ai+gpu-ui): per-tenant Azure AI config + GPU health panel
- Per-tenant Azure AI config stored in tenants.tenant_config JSONB
- GET/PUT /api/tenants/{id}/ai-config + POST .../test connection
- api_key never returned to frontend (has_api_key: bool pattern)
- azure_ai.py resolves creds from tenant config when ai_enabled=True
- ai_tasks.py loads tenant config and passes it to validate_thumbnail
- Admin GPU Status section: probe button + status badge + last-checked time
- Notifications: _BELL_CHANNELS filter (notification+alert only in bell)
- Tenants.tsx: per-row Azure AI Config modal with URL auto-parse helper
- Remove duplicate in-memory /gpu-probe endpoints (kept DB-backed /probe/gpu)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,11 +7,34 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
@celery_app.task(bind=True, name="app.tasks.ai_tasks.validate_item", queue="ai_validation")
|
||||
def validate_item(self, order_item_id: str):
|
||||
"""Validate orientation of a rendered thumbnail via Azure GPT-4o Vision."""
|
||||
"""Validate orientation of a rendered thumbnail via Azure GPT-4o Vision.
|
||||
|
||||
Loads the order item's tenant config and passes it to validate_thumbnail()
|
||||
so that per-tenant Azure credentials are used when configured.
|
||||
"""
|
||||
logger.info(f"AI validation for item: {order_item_id}")
|
||||
try:
|
||||
from app.config import settings
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import Session
|
||||
from app.models.order_item import OrderItem
|
||||
from app.services.azure_ai import validate_thumbnail
|
||||
validate_thumbnail(order_item_id)
|
||||
|
||||
# Load tenant config for this order item
|
||||
tenant_config: dict | None = None
|
||||
try:
|
||||
engine = create_engine(settings.database_url_sync)
|
||||
with Session(engine) as session:
|
||||
item = session.get(OrderItem, __import__("uuid").UUID(order_item_id))
|
||||
if item and hasattr(item, "order") and item.order and item.order.tenant_id:
|
||||
from app.domains.tenants.models import Tenant
|
||||
tenant = session.get(Tenant, item.order.tenant_id)
|
||||
if tenant:
|
||||
tenant_config = tenant.tenant_config or {}
|
||||
except Exception as exc:
|
||||
logger.warning(f"Could not load tenant config for {order_item_id}: {exc}")
|
||||
|
||||
validate_thumbnail(order_item_id, tenant_config=tenant_config)
|
||||
except Exception as exc:
|
||||
logger.error(f"AI validation failed for {order_item_id}: {exc}")
|
||||
raise self.retry(exc=exc, countdown=30, max_retries=3)
|
||||
|
||||
Reference in New Issue
Block a user