mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-30 01:52:18 +00:00
refactor(proxy): keep tag rate limit helpers within type discipline budget
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
e45d65a0e9
commit
f94d3ea4a1
1 changed files with 12 additions and 10 deletions
|
|
@ -557,7 +557,17 @@ class TagRateLimit:
|
|||
tpm_limit: int | None
|
||||
|
||||
|
||||
TagRateLimitResolver: TypeAlias = Callable[[Sequence[str]], Awaitable[Mapping[str, TagRateLimit]]]
|
||||
class TagRateLimitResolver(Protocol):
|
||||
def __call__(self, tag_names: Sequence[str], /) -> Awaitable[Mapping[str, TagRateLimit]]: ...
|
||||
|
||||
|
||||
def _tag_rate_limit_descriptor(tag: str, limit: TagRateLimit, window_size: int) -> RateLimitDescriptor:
|
||||
rate_limit: Final[RateLimitDescriptorRateLimitObject] = {
|
||||
"requests_per_unit": limit.rpm_limit,
|
||||
"tokens_per_unit": limit.tpm_limit,
|
||||
"window_size": window_size,
|
||||
}
|
||||
return RateLimitDescriptor(key="tag", value=tag, rate_limit=rate_limit)
|
||||
|
||||
|
||||
async def resolve_tag_rate_limits_from_db(tag_names: Sequence[str]) -> Mapping[str, TagRateLimit]:
|
||||
|
|
@ -2727,15 +2737,7 @@ class _PROXY_MaxParallelRequestsHandler_v3(CustomLogger):
|
|||
return ()
|
||||
tag_limits: Final = await self._tag_rate_limit_resolver(tags)
|
||||
return tuple(
|
||||
RateLimitDescriptor(
|
||||
key="tag",
|
||||
value=tag,
|
||||
rate_limit={
|
||||
"requests_per_unit": limit.rpm_limit,
|
||||
"tokens_per_unit": limit.tpm_limit,
|
||||
"window_size": self.window_size,
|
||||
},
|
||||
)
|
||||
_tag_rate_limit_descriptor(tag, limit, self.window_size)
|
||||
for tag in tags
|
||||
if (limit := tag_limits.get(tag)) is not None
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue