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()):
|
if self._breaker.is_open(self._provider, time.monotonic()):
|
||||||
raise CircuitOpenError(
|
raise CircuitOpenError(f"熔断器已开启,拒绝调用 provider={self._provider}")
|
||||||
f"熔断器已开启,拒绝调用 provider={self._provider}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# ② 缓存查询
|
# ② 缓存查询
|
||||||
cached = await self._cache.get(self._model, messages)
|
cached = await self._cache.get(self._model, messages)
|
||||||
@@ -337,8 +335,8 @@ class GovernedLLMClient:
|
|||||||
attempt_start = time.monotonic()
|
attempt_start = time.monotonic()
|
||||||
try:
|
try:
|
||||||
sse_lines = await self._stream_request(messages)
|
sse_lines = await self._stream_request(messages)
|
||||||
content, thinking_text, ttft_ms, max_itoken_ms, usage = (
|
content, thinking_text, ttft_ms, max_itoken_ms, usage = await self._consume_stream(
|
||||||
await self._consume_stream(sse_lines)
|
sse_lines
|
||||||
)
|
)
|
||||||
|
|
||||||
# 熔断器记成功
|
# 熔断器记成功
|
||||||
@@ -480,9 +478,7 @@ class GovernedLLMClient:
|
|||||||
assert last_exc is not None
|
assert last_exc is not None
|
||||||
raise last_exc
|
raise last_exc
|
||||||
|
|
||||||
async def _stream_request(
|
async def _stream_request(self, messages: list[dict[str, Any]]) -> list[str]:
|
||||||
self, messages: list[dict[str, Any]]
|
|
||||||
) -> list[str]:
|
|
||||||
"""发起流式 HTTP 请求并收集全部 SSE 行。
|
"""发起流式 HTTP 请求并收集全部 SSE 行。
|
||||||
|
|
||||||
此方法为主要的 HTTP 交互点,测试通过 patch 替换以注入假 SSE 行。
|
此方法为主要的 HTTP 交互点,测试通过 patch 替换以注入假 SSE 行。
|
||||||
@@ -507,9 +503,7 @@ class GovernedLLMClient:
|
|||||||
payload.update(_build_thinking_body(self._provider))
|
payload.update(_build_thinking_body(self._provider))
|
||||||
|
|
||||||
collected_lines: list[str] = []
|
collected_lines: list[str] = []
|
||||||
async with self._http.stream(
|
async with self._http.stream("POST", "/chat/completions", json=payload) as resp:
|
||||||
"POST", "/chat/completions", json=payload
|
|
||||||
) as resp:
|
|
||||||
if resp.status_code >= 400:
|
if resp.status_code >= 400:
|
||||||
await resp.aread()
|
await resp.aread()
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|||||||
Reference in New Issue
Block a user