mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
style: 统一使用 PEP 604/585 现代类型语法
- Optional[X] → X | None - Dict[X, Y] → dict[X, Y] - List[X] → list[X] - Tuple[X, Y] → tuple[X, Y] - Set[X] → set[X] 涉及 10 个文件,共约 50 处改动。
This commit is contained in:
@@ -295,7 +295,7 @@ def calculate_request_cost(
|
||||
"cache_cost": float,
|
||||
"request_cost": float,
|
||||
"total_cost": float,
|
||||
"tier_index": Optional[int],
|
||||
"tier_index": int | None,
|
||||
}
|
||||
"""
|
||||
# 构建标准化 usage
|
||||
|
||||
@@ -34,7 +34,7 @@ async def store_file_key_mapping(file_name: str, key_id: str) -> None:
|
||||
await CacheService.set(cache_key, str(key_id), ttl_seconds=FILE_MAPPING_TTL_SECONDS)
|
||||
|
||||
|
||||
async def get_file_key_mapping(file_name: str) -> Optional[str]:
|
||||
async def get_file_key_mapping(file_name: str) -> str | None:
|
||||
cache_key = build_file_mapping_key(file_name)
|
||||
if not cache_key:
|
||||
return None
|
||||
@@ -50,7 +50,7 @@ async def delete_file_key_mapping(file_name: str) -> None:
|
||||
await CacheService.delete(cache_key)
|
||||
|
||||
|
||||
def _extract_file_name_from_uri(file_uri: str) -> Optional[str]:
|
||||
def _extract_file_name_from_uri(file_uri: str) -> str | None:
|
||||
"""
|
||||
从 fileUri 提取 files/xxx 名称。
|
||||
|
||||
@@ -70,11 +70,11 @@ def _extract_file_name_from_uri(file_uri: str) -> Optional[str]:
|
||||
return None
|
||||
|
||||
|
||||
def extract_file_names_from_request(payload: Optional[Dict[str, Any]]) -> Set[str]:
|
||||
def extract_file_names_from_request(payload: dict[str, Any] | None) -> set[str]:
|
||||
"""
|
||||
从 Gemini 请求体中提取 fileUri 使用到的 files/xxx 名称集合。
|
||||
"""
|
||||
results: Set[str] = set()
|
||||
results: set[str] = set()
|
||||
|
||||
def walk(node: Any) -> None:
|
||||
if isinstance(node, dict):
|
||||
|
||||
@@ -72,8 +72,8 @@ def build_provider_url(
|
||||
query_params: dict[str, Any] | None = None,
|
||||
path_params: dict[str, Any] | None = None,
|
||||
is_stream: bool = False,
|
||||
key: Optional["ProviderAPIKey"] = None,
|
||||
decrypted_auth_config: Optional[Dict[str, Any]] = None,
|
||||
key: "ProviderAPIKey" | None = None,
|
||||
decrypted_auth_config: dict[str, Any] | None = None,
|
||||
) -> str:
|
||||
"""
|
||||
根据 endpoint 配置生成请求 URL
|
||||
@@ -175,7 +175,7 @@ def _resolve_default_path(api_format: str | None) -> str:
|
||||
|
||||
# Vertex AI 模型默认 region 映射
|
||||
# 用户可以通过 auth_config.model_regions 覆盖
|
||||
VERTEX_AI_DEFAULT_MODEL_REGIONS: Dict[str, str] = {
|
||||
VERTEX_AI_DEFAULT_MODEL_REGIONS: dict[str, str] = {
|
||||
# Gemini 3 系列(使用 global)
|
||||
"gemini-3-pro-image-preview": "global",
|
||||
# Gemini 2.0 系列
|
||||
@@ -200,10 +200,10 @@ VERTEX_AI_DEFAULT_MODEL_REGIONS: Dict[str, str] = {
|
||||
def _build_vertex_ai_url(
|
||||
key: "ProviderAPIKey",
|
||||
*,
|
||||
path_params: Optional[Dict[str, Any]] = None,
|
||||
query_params: Optional[Dict[str, Any]] = None,
|
||||
path_params: dict[str, Any] | None = None,
|
||||
query_params: dict[str, Any] | None = None,
|
||||
is_stream: bool = False,
|
||||
decrypted_auth_config: Optional[Dict[str, Any]] = None,
|
||||
decrypted_auth_config: dict[str, Any] | None = None,
|
||||
) -> str:
|
||||
"""
|
||||
构建 Vertex AI URL
|
||||
@@ -236,7 +236,7 @@ def _build_vertex_ai_url(
|
||||
from src.core.crypto import crypto_service
|
||||
|
||||
# 优先使用传入的已解密配置,避免重复解密
|
||||
auth_config: Dict[str, Any] = {}
|
||||
auth_config: dict[str, Any] = {}
|
||||
if decrypted_auth_config:
|
||||
auth_config = decrypted_auth_config
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user