mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
refactor: type fresh proxy cache and routing hooks, drop private-import suppression
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
26a449a3f3
commit
e86e1b150e
4 changed files with 13 additions and 9 deletions
|
|
@ -179,15 +179,15 @@ from litellm.litellm_core_utils.prompt_templates.tool_call_json_repair import (
|
|||
from litellm.litellm_core_utils.prompt_templates.tool_call_json_repair import (
|
||||
split_concatenated_json_objects as split_concatenated_json_objects, # noqa: PLC0414 # public compatibility re-export
|
||||
)
|
||||
from litellm.litellm_core_utils.prompt_templates.tpm_media_utils import (
|
||||
_image_part_url, # pyright: ignore[reportPrivateUsage] # Shared implementation for as_openai_image_part
|
||||
)
|
||||
from litellm.litellm_core_utils.prompt_templates.tpm_media_utils import (
|
||||
anthropic_image_source_to_openai_url as anthropic_image_source_to_openai_url, # noqa: PLC0414 # public compatibility re-export
|
||||
)
|
||||
from litellm.litellm_core_utils.prompt_templates.tpm_media_utils import (
|
||||
embedding_input_is_all_media as embedding_input_is_all_media, # noqa: PLC0414 # public compatibility re-export
|
||||
)
|
||||
from litellm.litellm_core_utils.prompt_templates.tpm_media_utils import (
|
||||
image_part_url,
|
||||
)
|
||||
from litellm.litellm_core_utils.prompt_templates.tpm_media_utils import (
|
||||
split_embedding_media_for_tpm as split_embedding_media_for_tpm, # noqa: PLC0414 # public compatibility re-export
|
||||
)
|
||||
|
|
@ -537,7 +537,7 @@ def as_openai_image_part(part: Mapping[str, object]) -> ChatCompletionImageObjec
|
|||
|
||||
Rebuilt rather than forwarded so no caller-controlled key beyond the URL rides along.
|
||||
"""
|
||||
url: Final = _image_part_url(part)
|
||||
url: Final = image_part_url(part)
|
||||
return {"type": "image_url", "image_url": {"url": url}} if url else None
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ def _tpm_media_leaf(value: object) -> _TPMMediaProjection:
|
|||
image: Final = as_str_mapping(part.get("image_url"))
|
||||
source: Final = as_str_mapping(part.get("source"))
|
||||
canonical: Final = _tpm_image_part(
|
||||
_image_part_url({**part, "type": "input_image"} if kind == "computer_screenshot" else part) or "",
|
||||
image_part_url({**part, "type": "input_image"} if kind == "computer_screenshot" else part) or "",
|
||||
(image or part).get("detail", part.get("detail", "auto")),
|
||||
)
|
||||
projected: Final = (
|
||||
|
|
@ -243,7 +243,7 @@ def anthropic_image_source_to_openai_url(image_source: Mapping[str, object]) ->
|
|||
return None
|
||||
|
||||
|
||||
def _image_part_url(part: Mapping[str, object]) -> str | None:
|
||||
def image_part_url(part: Mapping[str, object]) -> str | None:
|
||||
"""The image URL carried by one content part, whichever of the three dialects wrote it."""
|
||||
part_type: Final = part.get("type")
|
||||
if part_type in ("image_url", "input_image"):
|
||||
|
|
|
|||
|
|
@ -289,7 +289,7 @@ class UserApiKeyCache(DualCache):
|
|||
verbose_proxy_logger.error("UserApiKeyCache.async_get_cache failed for key=%r: %s", key, e)
|
||||
return None
|
||||
|
||||
def set_cache(self, key: str | None, value: CacheValue, local_only: bool = False, **kwargs: object):
|
||||
def set_cache(self, key: str | None, value: CacheValue, local_only: bool = False, **kwargs: object) -> None:
|
||||
model_type: Final = cast(type[BaseModel] | None, kwargs.pop("model_type", None))
|
||||
payload: Final[object] = CacheCodec.serialize(value, model_type=model_type)
|
||||
shared: Final = self._shared
|
||||
|
|
@ -308,7 +308,9 @@ class UserApiKeyCache(DualCache):
|
|||
return self.key_object_cache.set_cache(key=key, value=payload, local_only=local_only, **kwargs)
|
||||
return super().set_cache(key=key, value=payload, local_only=local_only, **kwargs)
|
||||
|
||||
async def async_set_cache(self, key: str | None, value: CacheValue, local_only: bool = False, **kwargs: object):
|
||||
async def async_set_cache(
|
||||
self, key: str | None, value: CacheValue, local_only: bool = False, **kwargs: object
|
||||
) -> None:
|
||||
"""Inside a request the Redis SET rides the request's pipeline (memory is written at once); anywhere
|
||||
else, or with options the pipeline does not carry, it goes to Redis directly as before."""
|
||||
model_type: Final = cast(type[BaseModel] | None, kwargs.pop("model_type", None))
|
||||
|
|
|
|||
|
|
@ -41,7 +41,9 @@ class _PROXY_SensitiveDataRoutingHandler(CustomLogger):
|
|||
model field if a routing override exists for the session.
|
||||
"""
|
||||
|
||||
def __init__(self, internal_usage_cache: InternalUsageCache, route_pins: SensitiveRoutePinStore | None = None):
|
||||
def __init__(
|
||||
self, internal_usage_cache: InternalUsageCache, route_pins: SensitiveRoutePinStore | None = None
|
||||
) -> None:
|
||||
self.route_pins: Final = route_pins or SensitiveRoutePinStore(
|
||||
connect(internal_usage_cache.dual_cache.redis_cache).sensitive_route_pins()
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue