mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-22 10:40:46 +00:00
fix(proxy): declare the redis family on the tool discovery buffer and drop the blind except and cast
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
e7848a7d4a
commit
e78eab9d69
2 changed files with 10 additions and 4 deletions
|
|
@ -581,7 +581,7 @@ class RedisUpdateBuffer:
|
|||
RedisPipelineRpushOperation(key=REDIS_TOOL_DISCOVERY_BUFFER_KEY, values=[safe_dumps(items)])
|
||||
]
|
||||
)
|
||||
except Exception as e:
|
||||
except (RedisError, OSError, asyncio.TimeoutError) as e:
|
||||
verbose_proxy_logger.error(
|
||||
"Tool discovery - failed to push %d tool rows to Redis, restoring them for the next tick. Error: %s",
|
||||
len(items),
|
||||
|
|
@ -590,6 +590,7 @@ class RedisUpdateBuffer:
|
|||
for item in items:
|
||||
tool_discovery_queue.add_update(item)
|
||||
|
||||
@with_service_target(SPEND_QUEUE_TARGET)
|
||||
async def get_all_tool_discoveries_from_redis_buffer(self) -> tuple[ToolDiscoveryQueueItem, ...]:
|
||||
"""Drain every worker's tool rows and fold them to one row per tool_name."""
|
||||
if self.redis_cache is None:
|
||||
|
|
@ -605,6 +606,7 @@ class RedisUpdateBuffer:
|
|||
batches: Final = tuple(_TOOL_DISCOVERY_ITEMS.validate_json(entry) for entry in entries)
|
||||
return aggregate_tool_discoveries(item for batch in batches for item in batch)
|
||||
|
||||
@with_service_target(SPEND_QUEUE_TARGET)
|
||||
async def store_spend_logs_in_redis(
|
||||
self,
|
||||
rows: Sequence[SpendLogRow],
|
||||
|
|
|
|||
|
|
@ -4,18 +4,22 @@ tool with the number of times it was invoked since the previous flush.
|
|||
"""
|
||||
|
||||
from collections.abc import Iterable
|
||||
from typing import Final, cast
|
||||
from typing import Final
|
||||
|
||||
from pydantic import TypeAdapter
|
||||
|
||||
from litellm._logging import verbose_proxy_logger
|
||||
from litellm.proxy._types import ToolDiscoveryQueueItem
|
||||
|
||||
_ITEM: Final = TypeAdapter(ToolDiscoveryQueueItem)
|
||||
|
||||
|
||||
def _merged(existing: ToolDiscoveryQueueItem | None, item: ToolDiscoveryQueueItem) -> ToolDiscoveryQueueItem:
|
||||
"""The first sighting keeps its origin and caller fields, later sightings only add to call_count."""
|
||||
increment: Final = item.get("call_count", 1)
|
||||
if existing is None:
|
||||
return cast(ToolDiscoveryQueueItem, {**item, "call_count": increment})
|
||||
return cast(ToolDiscoveryQueueItem, {**existing, "call_count": existing.get("call_count", 1) + increment})
|
||||
return _ITEM.validate_python({**item, "call_count": increment})
|
||||
return _ITEM.validate_python({**existing, "call_count": existing.get("call_count", 1) + increment})
|
||||
|
||||
|
||||
def aggregate_tool_discoveries(items: Iterable[ToolDiscoveryQueueItem]) -> tuple[ToolDiscoveryQueueItem, ...]:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue