Files
Aether/src/core/api_format/enums.py
fawney19 34272af711 feat: 跨格式转换时按 ApiFamily 优先级排序端点
- 为 ApiFamily 枚举添加 priority 属性 (OpenAI=1, Claude=2, Gemini=3)
- 新增 _sort_endpoints_by_family_priority 函数按优先级排序端点
- 在调度器中对各分组内的端点应用优先级排序
- 修正测试文件的 type ignore 注解 (attr-defined -> method-assign)
- 新增 7 个端点排序相关的单元测试
2026-02-05 02:01:06 +08:00

71 lines
1.8 KiB
Python
Raw 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.
"""API format enums.
新模式下系统使用结构化的 (ApiFamily, EndpointKind) / `family:kind` signature 作为唯一标识。
"""
from enum import Enum
class ApiFamily(str, Enum):
"""
协议族(兼容族)- 决定数据格式与认证方式的基础。
注意:不叫 Provider 避免与 ORM 的 Provider 模型撞名。
"""
OPENAI = "openai" # openai-compatible含 deepseek, grok, qwen 等)
CLAUDE = "claude" # claude-compatible
GEMINI = "gemini" # gemini-compatible
@property
def priority(self) -> int:
"""基础优先级(数字越小越优先)"""
return {
ApiFamily.OPENAI: 1,
ApiFamily.CLAUDE: 2,
ApiFamily.GEMINI: 3,
}.get(self, 99)
class EndpointKind(str, Enum):
"""
端点变体 - 决定 API 路径/认证变体/数据格式变体等。
注意:不复用现有 EndpointTypeEndpointType 用于请求上下文检测/功能分类)。
"""
CHAT = "chat"
CLI = "cli"
VIDEO = "video"
IMAGE = "image"
class AuthMethod(str, Enum):
"""认证方式 - 决定如何构造认证 Header"""
BEARER = "bearer" # Authorization: Bearer {token}
API_KEY = "api_key" # x-api-key: {key}
GOOG_API_KEY = "goog_key" # x-goog-api-key: {key}
OAUTH2 = "oauth2" # Google OAuth2 / Service Account
QUERY_KEY = "query_key" # ?key={key} (Gemini 备用)
class EndpointType(str, Enum):
"""端点类型 - 决定 API 功能类别"""
CHAT = "chat" # Chat/Completion API
VIDEO = "video" # Video Generation API
FILES = "files" # Files API
IMAGE = "image" # Image Generation API
AUDIO = "audio" # Audio API
EMBEDDING = "embedding" # Embedding API
MODELS = "models" # Models API
__all__ = [
"ApiFamily",
"EndpointKind",
"AuthMethod",
"EndpointType",
]