Repository navigation
chore(release): backport #39631, #39729, #40639 to stable/1.98.x #43130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c6024f3
54fe3f5
f2c9c6e
e62946f
9a8231f
cbc14c5
dec53d0
106d722
918c1c2
e70af49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,6 +115,14 @@ def _tag_cache_keys(row: _TagRow) -> tuple[str, ...]: | |
| return (f"tag:{row.tag_name}",) | ||
|
|
||
|
|
||
| def _enduser_counter_key(row: _EndUserRow) -> str: | ||
| return f"spend:end_user:{row.user_id}" | ||
|
|
||
|
|
||
| def _enduser_cache_keys(row: _EndUserRow) -> tuple[str, ...]: | ||
| return (f"end_user_id:{row.user_id}",) | ||
|
|
||
|
|
||
| def _budget_link_where( | ||
| budget_ids: Sequence[str], | ||
| extra: Mapping[str, object] = MappingProxyType({}), | ||
|
|
@@ -346,6 +354,7 @@ async def _collect_budget_cascade(self, budgets_to_reset: Sequence[LiteLLM_Budge | |
| where=_budget_link_where(budget_ids, _SPENT_ROWS_WHERE), | ||
| log_subject="tags", | ||
| ) | ||
| endusers: Final[tuple[_EndUserRow, ...]] = await self._collect_endusers_to_reset(budget_ids) | ||
| return _BudgetCascade( | ||
| budgets=tuple(budgets_to_reset), | ||
| budget_ids=budget_ids, | ||
|
|
@@ -357,18 +366,20 @@ async def _collect_budget_cascade(self, budgets_to_reset: Sequence[LiteLLM_Budge | |
| for b in budgets_to_reset | ||
| if b.budget_id is not None and b.budget_duration is not None | ||
| ), | ||
| endusers=await self._collect_endusers_to_reset(budget_ids), | ||
| endusers=endusers, | ||
| counter_keys=( | ||
| *(_team_membership_counter_key(row) for row in team_memberships), | ||
| *(_key_counter_key(row) for row in keys), | ||
| *(_org_counter_key(row) for row in orgs), | ||
| *(_tag_counter_key(row) for row in tags), | ||
| *(_enduser_counter_key(row) for row in endusers), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Knowledge Base Used: Spend, budgets, and rate limits |
||
| ), | ||
| cache_keys=( | ||
| *(key for row in team_memberships for key in _team_membership_cache_keys(row)), | ||
| *(key for row in keys for key in _key_cache_keys(row)), | ||
| *(key for row in orgs for key in _org_cache_keys(row)), | ||
| *(key for row in tags for key in _tag_cache_keys(row)), | ||
| *(key for row in endusers for key in _enduser_cache_keys(row)), | ||
|
Comment on lines
+375
to
+382
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| ), | ||
| ) | ||
|
|
||
|
|
@@ -383,14 +394,14 @@ async def _commit_budget_cascade(self, cascade: _BudgetCascade) -> None: | |
| if not cascade.budget_ids: | ||
| return | ||
|
|
||
| enduser_ids: Final = tuple(row.user_id for row in cascade.endusers) | ||
| async with budget_cascade_unit_of_work(self.prisma_client.db.batch_) as uow: | ||
| uow.team_memberships.queue_spend_zero(where=_budget_link_where(cascade.budget_ids)) | ||
| uow.keys.queue_spend_zero(where=_budget_link_where(cascade.budget_ids, _LINKED_KEYS_WHERE)) | ||
| uow.organizations.queue_spend_zero(where=_budget_link_where(cascade.budget_ids, _SPENT_ROWS_WHERE)) | ||
| uow.tags.queue_spend_zero(where=_budget_link_where(cascade.budget_ids, _SPENT_ROWS_WHERE)) | ||
| if enduser_ids: | ||
| uow.endusers.queue_spend_zero(where={"user_id": {"in": list(enduser_ids)}}) | ||
| uow.endusers.queue_spend_zero(where=_budget_link_where(cascade.budget_ids, _SPENT_ROWS_WHERE)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Knowledge Base Used: Spend, budgets, and rate limits |
||
| if litellm.max_end_user_budget_id in cascade.budget_ids: | ||
| uow.endusers.queue_spend_zero(where={"budget_id": None, **_SPENT_ROWS_WHERE}) | ||
| for budget_id, budget_reset_at in cascade.budget_resets: | ||
| uow.budgets.queue_window_advance(budget_id=budget_id, budget_reset_at=budget_reset_at) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule Used: What: Do not hardcode model-specific flags in the codebase. Instead, put them in model_prices_and_context_window.json and then read them in via get_model_info Why: Prevents need for users to upgrade litellm each time a new model supports this featu... (source)
Knowledge Base Used: Provider adapters and capabilities