diff --git a/litellm/budget_manager.py b/litellm/budget_manager.py index 9eb8ffd037..ddfae14d19 100644 --- a/litellm/budget_manager.py +++ b/litellm/budget_manager.py @@ -1,7 +1,7 @@ import os, json import litellm from litellm.utils import ModelResponse -import requests +import requests, threading from typing import Optional class BudgetManager: @@ -64,6 +64,7 @@ class BudgetManager: self.user_dict[user]["model_cost"][model] = cost + self.user_dict[user]["model_cost"].get(model, 0) else: self.user_dict[user]["model_cost"] = {model: cost} + self._save_data_thread() # [Non-Blocking] Update persistent storage without blocking execution return {"user": self.user_dict[user]} def get_current_cost(self, user): @@ -82,6 +83,10 @@ class BudgetManager: self.user_dict[user]["current_cost"] = 0 self.user_dict[user]["model_cost"] = {} return {"user": self.user_dict[user]} + + def _save_data_thread(self): + thread = threading.Thread(target=self.save_data) # [Non-Blocking]: saves data without blocking execution + thread.start() def save_data(self): if self.client_type == "local": diff --git a/pyproject.toml b/pyproject.toml index ac9723d0b6..13f83e81e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "litellm" -version = "0.1.596" +version = "0.1.597" description = "Library to easily interface with LLM API providers" authors = ["BerriAI"] license = "MIT License"