mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
feat: 跨格式转换时按 ApiFamily 优先级排序端点
- 为 ApiFamily 枚举添加 priority 属性 (OpenAI=1, Claude=2, Gemini=3) - 新增 _sort_endpoints_by_family_priority 函数按优先级排序端点 - 在调度器中对各分组内的端点应用优先级排序 - 修正测试文件的 type ignore 注解 (attr-defined -> method-assign) - 新增 7 个端点排序相关的单元测试
This commit is contained in:
@@ -17,6 +17,15 @@ class ApiFamily(str, Enum):
|
||||
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):
|
||||
"""
|
||||
|
||||
25
src/services/cache/aware_scheduler.py
vendored
25
src/services/cache/aware_scheduler.py
vendored
@@ -34,12 +34,13 @@ import hashlib
|
||||
import random
|
||||
import re
|
||||
import time
|
||||
from collections.abc import Sequence
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from sqlalchemy.orm import Session, selectinload
|
||||
|
||||
from src.core.api_format.enums import EndpointKind
|
||||
from src.core.api_format.enums import ApiFamily, EndpointKind
|
||||
from src.core.api_format.signature import make_signature_key, parse_signature_key
|
||||
from src.core.exceptions import ModelNotSupportedException, ProviderNotAvailableException
|
||||
from src.core.logger import logger
|
||||
@@ -103,6 +104,21 @@ class ConcurrencySnapshot:
|
||||
)
|
||||
|
||||
|
||||
def _sort_endpoints_by_family_priority(
|
||||
eps: Sequence[ProviderEndpoint],
|
||||
) -> list[ProviderEndpoint]:
|
||||
"""按 ApiFamily 优先级对端点排序(同分组内使用)。"""
|
||||
|
||||
def sort_key(ep: ProviderEndpoint) -> int:
|
||||
family_str = str(getattr(ep, "api_family", "") or "").strip().lower()
|
||||
try:
|
||||
return ApiFamily(family_str).priority
|
||||
except ValueError:
|
||||
return 99
|
||||
|
||||
return sorted(eps, key=sort_key)
|
||||
|
||||
|
||||
class CacheAwareScheduler:
|
||||
"""
|
||||
缓存感知调度器
|
||||
@@ -1149,7 +1165,12 @@ class CacheAwareScheduler:
|
||||
else:
|
||||
fallback_other_family.append(ep)
|
||||
|
||||
endpoints = preferred + preferred_other_family + fallback + fallback_other_family
|
||||
endpoints = (
|
||||
_sort_endpoints_by_family_priority(preferred)
|
||||
+ _sort_endpoints_by_family_priority(preferred_other_family)
|
||||
+ _sort_endpoints_by_family_priority(fallback)
|
||||
+ _sort_endpoints_by_family_priority(fallback_other_family)
|
||||
)
|
||||
|
||||
for endpoint in endpoints:
|
||||
logger.debug(
|
||||
|
||||
Reference in New Issue
Block a user