mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
style: fix lint issues
This commit is contained in:
parent
b8047f1c6d
commit
7dbd808bd1
2 changed files with 11 additions and 11 deletions
|
|
@ -5,9 +5,9 @@ import json
|
|||
import traceback
|
||||
from collections import deque
|
||||
from collections.abc import AsyncIterator, Iterator, Mapping
|
||||
from typing import TYPE_CHECKING, Any, Final, cast
|
||||
from typing import TYPE_CHECKING, Any, Final, cast # noqa: TID251 # untyped upstream event payloads
|
||||
|
||||
from typing_extensions import TypeIs
|
||||
from typing_extensions import TypeIs # noqa: TID251 # runtime isinstance-narrowing of attr-or-dict event payloads
|
||||
|
||||
from litellm import verbose_logger
|
||||
from litellm._uuid import uuid
|
||||
|
|
@ -31,7 +31,7 @@ if TYPE_CHECKING:
|
|||
|
||||
# Map upstream HTTP status codes to the Anthropic error types from
|
||||
# https://docs.anthropic.com/en/api/errors — anything unmapped is an api_error.
|
||||
_STATUS_TO_ANTHROPIC_ERROR_TYPE: Final[dict[int, str]] = {
|
||||
_STATUS_TO_ANTHROPIC_ERROR_TYPE: Final[dict[int, str]] = { # mutable-ok: constant, never mutated
|
||||
400: "invalid_request_error",
|
||||
401: "authentication_error",
|
||||
403: "permission_error",
|
||||
|
|
@ -79,7 +79,7 @@ class AnthropicResponsesStreamWrapper:
|
|||
self._pending_tool_ids: dict[str, str] = {} # item_id -> call_id / name accumulator
|
||||
self._sent_message_start = False
|
||||
self._sent_message_stop = False
|
||||
self._chunk_queue: deque[dict[str, object]] = deque()
|
||||
self._chunk_queue: deque[dict[str, object]] = deque() # mutable-ok: SSE frame queue, drained via popleft
|
||||
self._refusal_text: str = ""
|
||||
self._sync_responses_iterator: Iterator[object] | None = None
|
||||
|
||||
|
|
@ -104,11 +104,13 @@ class AnthropicResponsesStreamWrapper:
|
|||
}
|
||||
|
||||
@staticmethod
|
||||
def _make_error_event(error_type: str | None, error_message: str | None) -> dict[str, object]:
|
||||
def _make_error_event(
|
||||
error_type: str | None, error_message: str | None
|
||||
) -> dict[str, object]: # mutable-ok: SSE frame payload shape
|
||||
"""The Anthropic streaming spec's terminal error frame."""
|
||||
event: dict[str, object] = {
|
||||
event: dict[str, object] = { # mutable-ok: terminal error frame payload
|
||||
"type": "error",
|
||||
"error": {
|
||||
"error": { # mutable-ok: nested Anthropic error object
|
||||
"type": error_type or "api_error",
|
||||
"message": error_message or "Upstream response failed",
|
||||
},
|
||||
|
|
@ -326,7 +328,7 @@ class AnthropicResponsesStreamWrapper:
|
|||
|
||||
# ---- response failed -> terminal error event ----
|
||||
if event_type == "response.failed":
|
||||
event_obj = cast("object", event)
|
||||
event_obj = cast("object", event) # cast-ok: pins Any event to object
|
||||
failed_response: object | None
|
||||
if _is_json_object(event_obj):
|
||||
failed_response = event_obj.get("response")
|
||||
|
|
|
|||
|
|
@ -234,9 +234,7 @@ class TestEncryptedReasoningIsStreamedForReplay:
|
|||
]
|
||||
chunks = _process_all(events)
|
||||
|
||||
thinking = "".join(
|
||||
c["delta"]["thinking"] for c in chunks if c.get("delta", {}).get("type") == "thinking_delta"
|
||||
)
|
||||
thinking = "".join(c["delta"]["thinking"] for c in chunks if c.get("delta", {}).get("type") == "thinking_delta")
|
||||
assert thinking == "First.\n\nSecond."
|
||||
assert [c["type"] for c in chunks].count("content_block_start") == 1
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue