Files
octopus/myproject/products/services/ai/base.py
Andrey Smakotin 01873be15d feat(products): добавить генератор названий букетов с ai и тесты
- Добавить модуль ai с генератором названий букетов
- Обновить __init__.py для экспорта нового сервиса
- Добавить тесты для проверки работы генератора
2026-01-22 12:12:57 +03:00

49 lines
1.8 KiB
Python

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