- gateway/proxy/ 十文件:config(ProxyConfig:元->毫元加载期换算 D-P1、差异化售价、 桶/峰谷/限流/semcache 配置)/ errors(8 类 HTTP 语义异常)/ ledger(四表两索引 DDL, WAL,ReviewQueue 连接纪律)/ auth·pricing·normalizer·semcache·upstream(§6 签名占位) / routes(/proxy/v1/models OpenAI 形状)/ __init__(build_proxy_router 组装点) - settings DEFAULTS 增 proxy 段(enabled 默认 False,D-P7) - api.py 首次 include_router(enabled 门控 + 装配失败不拖垮主应用) - serve.py workers>1 拒绝启动(D-P9:WEB_CONCURRENCY/UVICORN_WORKERS 校验) - 测试 +4(门控 404/DDL 幂等/毫元换算/池模型列表),全量 322 passed
22 lines
866 B
Python
22 lines
866 B
Python
"""上游客户端(T-P2 落地;本文件先立签名)。
|
||
|
||
规格(§6):模块级 httpx.AsyncClient 单例(keepalive,max_connections=100),
|
||
超时 connect=10s/read=120s/write=10s/pool=30s;始终注入
|
||
stream_options.include_usage(客户端未要求 usage 时过滤该 chunk 不下发);
|
||
首 token 前 failover(D-P4)。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
from typing import Any, AsyncIterator, Dict
|
||
|
||
|
||
async def stream(body: dict, entry: Dict[str, Any], usage_sink) -> AsyncIterator[bytes]:
|
||
"""流式派发到上游,逐块 yield(T-P2 实现)。"""
|
||
raise NotImplementedError("T-P2")
|
||
yield b"" # pragma: no cover
|
||
|
||
|
||
def normalize_usage(provider: str, usage_dict: Dict[str, Any]) -> Dict[str, int]:
|
||
"""三家 usage 字段 -> 统一 {in_miss, in_hit, out}(T-P2 实现)。"""
|
||
raise NotImplementedError("T-P2")
|