初始化提交

This commit is contained in:
2025-12-14 15:40:49 +08:00
commit 410b2f068d
72 changed files with 10460 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
from abc import ABC, abstractmethod
from typing import Dict, Any, Generator, Union, Tuple
import requests
class ModelService(ABC):
"""大模型服务基类"""
@abstractmethod
def get_api_config(self) -> Tuple[str, str]:
"""获取 API URL 和 Key"""
pass
@abstractmethod
def calculate_cost(self, usage: Dict[str, Any] = None, stream: bool = False) -> float:
"""计算费用"""
pass
@abstractmethod
def check_balance(self, balance: float) -> Tuple[bool, float, str]:
"""检查余额是否充足
Returns: (is_sufficient, estimated_cost, error_message)
"""
pass
@abstractmethod
def prepare_payload(self, data: Dict[str, Any]) -> Dict[str, Any]:
"""准备请求载荷"""
pass
@abstractmethod
def handle_response(self, response: requests.Response, stream: bool) -> Union[Dict[str, Any], Generator]:
"""处理响应"""
pass