68 lines
1.5 KiB
Python
68 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
基础设施层接口定义
|
|
包括AI服务、配置服务等
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Dict, Any, Optional, Tuple
|
|
|
|
|
|
class IAIService(ABC):
|
|
"""AI服务接口"""
|
|
|
|
@abstractmethod
|
|
async def generate_text(
|
|
self,
|
|
system_prompt: str,
|
|
user_prompt: str,
|
|
temperature: Optional[float] = None,
|
|
**kwargs
|
|
) -> str:
|
|
"""生成文本"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def generate_with_stream(
|
|
self,
|
|
system_prompt: str,
|
|
user_prompt: str,
|
|
**kwargs
|
|
):
|
|
"""流式生成文本"""
|
|
pass
|
|
|
|
|
|
class IConfigService(ABC):
|
|
"""配置服务接口"""
|
|
|
|
@abstractmethod
|
|
def get_config(self, config_name: str, config_class: type) -> Any:
|
|
"""获取配置"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_setting(self, key: str, default: Any = None) -> Any:
|
|
"""获取设置项"""
|
|
pass
|
|
|
|
|
|
class IOutputService(ABC):
|
|
"""输出服务接口"""
|
|
|
|
@abstractmethod
|
|
def save_content(self, content: str, filename: str, subfolder: str = "") -> str:
|
|
"""保存内容到文件"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def save_json(self, data: Dict[str, Any], filename: str, subfolder: str = "") -> str:
|
|
"""保存JSON数据"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def get_output_path(self, filename: str, subfolder: str = "") -> str:
|
|
"""获取输出路径"""
|
|
pass |