feat(products): добавить генератор названий букетов с ai и тесты

- Добавить модуль ai с генератором названий букетов
- Обновить __init__.py для экспорта нового сервиса
- Добавить тесты для проверки работы генератора
This commit is contained in:
2026-01-22 12:12:57 +03:00
parent 036b9d1634
commit 01873be15d
5 changed files with 356 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
from abc import ABC, abstractmethod
from typing import Tuple, Optional, Dict
from integrations.services.ai_services.glm_service import GLMIntegrationService
from integrations.services.ai_services.openrouter_service import OpenRouterIntegrationService
from integrations.models.ai_services.glm import GLMIntegration
from integrations.models.ai_services.openrouter import OpenRouterIntegration
import logging
logger = logging.getLogger(__name__)
class BaseAIProductService(ABC):
"""
Абстрактный базовый класс для AI-сервисов продуктов
"""
@abstractmethod
def generate(self, **kwargs) -> Tuple[bool, str, Optional[Dict]]:
"""
Основной метод генерации
"""
pass
@classmethod
def get_glm_service(cls) -> Optional[GLMIntegrationService]:
"""
Получить сервис GLM из активной интеграции
"""
try:
integration = GLMIntegration.objects.filter(is_active=True).first()
if integration:
return GLMIntegrationService(integration)
except Exception as e:
logger.error(f"Ошибка при получении GLM сервиса: {str(e)}")
return None
@classmethod
def get_openrouter_service(cls) -> Optional[OpenRouterIntegrationService]:
"""
Получить сервис OpenRouter из активной интеграции
"""
try:
integration = OpenRouterIntegration.objects.filter(is_active=True).first()
if integration:
return OpenRouterIntegrationService(integration)
except Exception as e:
logger.error(f"Ошибка при получении OpenRouter сервиса: {str(e)}")
return None