mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
fix(budget): avoid remote image fetch in projected cost
This commit is contained in:
parent
81f19176fc
commit
11addf2de0
1 changed files with 4 additions and 1 deletions
|
|
@ -100,7 +100,10 @@ class BudgetManager:
|
|||
return self.user_dict[user]
|
||||
|
||||
def projected_cost(self, model: str, messages: list, user: str):
|
||||
prompt_tokens: Final = litellm.token_counter(model=model, messages=messages)
|
||||
# Fixed image estimate: a budget check must never fetch remote
|
||||
# image URLs (unbounded/chunked bodies exhaust memory, and a check
|
||||
# should not do network I/O at all).
|
||||
prompt_tokens: Final = litellm.token_counter(model=model, messages=messages, use_default_image_token_count=True)
|
||||
prompt_cost, _ = litellm.cost_per_token(model=model, prompt_tokens=prompt_tokens, completion_tokens=0)
|
||||
current_cost: Final = self.user_dict[user].get("current_cost", 0)
|
||||
projected_cost: Final = prompt_cost + current_cost
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue