mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-13 08:52:02 +00:00
fix(caching): skip proxy-only Anthropic import in cache-hit defer check
Base SDK installs lack the proxy-only extras (fastapi), so the lazy import of the Anthropic Messages replay class crashes sync cache hits. Guard it; a base install can never hold that iterator.
This commit is contained in:
parent
caad4d6204
commit
dafadf3705
1 changed files with 14 additions and 6 deletions
|
|
@ -182,14 +182,22 @@ def _should_defer_streaming_cache_hit_callbacks(*, cached_result: object) -> boo
|
|||
spend and callback records. A plain (non-stream) replay logs here, since nothing
|
||||
else will.
|
||||
"""
|
||||
from litellm.llms.anthropic.pass_through.messages.response_cache import (
|
||||
CachedAnthropicMessagesStreamIterator,
|
||||
)
|
||||
from litellm.responses.streaming_iterator import BaseResponsesAPIStreamingIterator
|
||||
|
||||
return isinstance(
|
||||
cached_result, (CustomStreamWrapper, BaseResponsesAPIStreamingIterator, CachedAnthropicMessagesStreamIterator)
|
||||
)
|
||||
stream_replay_classes: tuple[type, ...] = (CustomStreamWrapper, BaseResponsesAPIStreamingIterator)
|
||||
try:
|
||||
from litellm.llms.anthropic.pass_through.messages.response_cache import (
|
||||
CachedAnthropicMessagesStreamIterator,
|
||||
)
|
||||
except ModuleNotFoundError:
|
||||
# The Anthropic Messages replay is only reachable through proxy-only
|
||||
# extras (fastapi). A base SDK install can never hold one, so the
|
||||
# isinstance check can safely go ahead without it.
|
||||
pass
|
||||
else:
|
||||
stream_replay_classes = (*stream_replay_classes, CachedAnthropicMessagesStreamIterator)
|
||||
|
||||
return isinstance(cached_result, stream_replay_classes)
|
||||
|
||||
|
||||
def _prompt_tokens_details_as_mapping(details: "PromptTokensDetailsWrapper") -> Mapping[str, object]:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue