style: format adapters/llm.py

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-06 23:01:06 -04:00
parent f1a0414be8
commit cfd3277f80
+7 -13
View File
@@ -60,7 +60,7 @@ def _sse_data_payload(raw: str) -> str | None:
line = raw.strip()
if not line or line.startswith(":") or not line.startswith("data:"):
return None
return line[len("data:"):].strip()
return line[len("data:") :].strip()
def _sse_delta(chunk: dict, usage_sink: dict) -> tuple[bool, str] | None:
@@ -292,9 +292,7 @@ class GovernedLLMClient:
# ① 熔断器检查
if self._breaker.is_open(self._provider, time.monotonic()):
raise CircuitOpenError(
f"熔断器已开启,拒绝调用 provider={self._provider}"
)
raise CircuitOpenError(f"熔断器已开启,拒绝调用 provider={self._provider}")
# ② 缓存查询
cached = await self._cache.get(self._model, messages)
@@ -337,8 +335,8 @@ class GovernedLLMClient:
attempt_start = time.monotonic()
try:
sse_lines = await self._stream_request(messages)
content, thinking_text, ttft_ms, max_itoken_ms, usage = (
await self._consume_stream(sse_lines)
content, thinking_text, ttft_ms, max_itoken_ms, usage = await self._consume_stream(
sse_lines
)
# 熔断器记成功
@@ -449,7 +447,7 @@ class GovernedLLMClient:
)
if attempt < self._max_retries - 1:
delay = min(
self._retry_base_delay_s * (2 ** attempt),
self._retry_base_delay_s * (2**attempt),
self._retry_max_delay_s,
)
if delay > 0:
@@ -480,9 +478,7 @@ class GovernedLLMClient:
assert last_exc is not None
raise last_exc
async def _stream_request(
self, messages: list[dict[str, Any]]
) -> list[str]:
async def _stream_request(self, messages: list[dict[str, Any]]) -> list[str]:
"""发起流式 HTTP 请求并收集全部 SSE 行。
此方法为主要的 HTTP 交互点,测试通过 patch 替换以注入假 SSE 行。
@@ -507,9 +503,7 @@ class GovernedLLMClient:
payload.update(_build_thinking_body(self._provider))
collected_lines: list[str] = []
async with self._http.stream(
"POST", "/chat/completions", json=payload
) as resp:
async with self._http.stream("POST", "/chat/completions", json=payload) as resp:
if resp.status_code >= 400:
await resp.aread()
resp.raise_for_status()