style: format adapters/llm.py
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+5
-11
@@ -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
|
||||
)
|
||||
|
||||
# 熔断器记成功
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user