bangbang-aigc-server/api/interfaces/content_interfaces.py
2025-07-31 15:35:23 +08:00

91 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
内容生成相关接口定义
采用依赖倒置原则API层依赖接口而非具体实现
"""
from abc import ABC, abstractmethod
from typing import Dict, List, Any, Optional, Tuple
from dataclasses import dataclass
@dataclass
class TopicRequest:
"""主题生成请求"""
user_requirements: str
count: int = 5
style: str = "default"
@dataclass
class ContentRequest:
"""内容生成请求"""
topic: Dict[str, Any]
style: str = "default"
length: str = "medium"
@dataclass
class ContentResult:
"""内容生成结果"""
content: str
metadata: Dict[str, Any]
success: bool
error_message: Optional[str] = None
class ITopicGenerator(ABC):
"""主题生成器接口"""
@abstractmethod
async def generate_topics(self, request: TopicRequest) -> List[Dict[str, Any]]:
"""生成主题列表"""
pass
class IContentGenerator(ABC):
"""内容生成器接口"""
@abstractmethod
async def generate_content(self, request: ContentRequest) -> ContentResult:
"""生成内容"""
pass
class IContentJudger(ABC):
"""内容审核器接口"""
@abstractmethod
async def judge_content(self, content: str) -> Tuple[bool, str, float]:
"""审核内容质量"""
pass
class IContentService(ABC):
"""内容服务接口 - 应用服务层"""
@abstractmethod
async def create_complete_content(
self,
user_requirements: str,
count: int = 5,
style: str = "default"
) -> Dict[str, Any]:
"""完整的内容创作流程"""
pass
@abstractmethod
async def generate_topics_only(self, request: TopicRequest) -> List[Dict[str, Any]]:
"""仅生成主题"""
pass
@abstractmethod
async def generate_content_from_topic(
self,
topic: Dict[str, Any],
style: str = "default"
) -> ContentResult:
"""根据主题生成内容"""
pass