refactor: 将 adapter 层的计费/模型抓取/行为变体能力下沉到 core.api_format 注册表

- 新增 core/api_format/capabilities.py,统一注册计费模板、模型抓取、
  total_input_context 计算和 provider behavior variant
- 新增 core/usage_tokens.py,抽取 cache token 解析逻辑到 core 层
- handler adapter 移除各自的 compute_total_input_context / fetch_models /
  BILLING_TEMPLATE 覆盖,改为委托 core 注册表解析
- provider/behavior.py 改为薄封装,底层委托 core registry
- 新增 tests/test_architecture_import_rules.py 架构导入约束测试
- 新增 tests/services/api_format/test_capabilities.py 能力注册表测试

Closes #207

Co-authored-by: AAEE86 <ppk0227@hotmail.com>
This commit is contained in:
fawney19
2026-03-09 18:26:53 +08:00
parent 4999a1a0a8
commit 0258d01ee6
43 changed files with 1313 additions and 630 deletions

View File

@@ -8,11 +8,11 @@ import pytest
from src.api.handlers.base.utils import (
build_json_response_for_client,
build_sse_headers,
extract_cache_creation_tokens,
filter_proxy_response_headers,
resolve_client_accept_encoding,
resolve_client_content_encoding,
)
from src.core.usage_tokens import extract_cache_creation_tokens
class TestExtractCacheCreationTokens:
@@ -60,7 +60,7 @@ class TestExtractCacheCreationTokens:
def test_empty_usage(self) -> None:
"""测试空字典"""
usage = {}
usage: dict[str, int] = {}
assert extract_cache_creation_tokens(usage) == 0
def test_all_zeros(self) -> None: