docstr: Returns a deployment with the lowest TPM/RPM usage.
docstr_tok: ["Returns","a","deployment","with","the","lowest","TPM\/RPM","usage","."]
code: def get_available_deployments(
      self,
      model_group: str,
      healthy_deployments: list,
      messages: Optional[List[Dict[str, str]]] = None,
      input: Optional[Union[str, List]] = None,
  ):
      """
      Returns a deployment with the lowest TPM/RPM usage.
      """
      # get list of potential deployments
      current_minute = datetime.now().strftime("%H-%M")
      tpm_key = f"{model_group}:tpm:{current_minute}"
      rpm_key = f"{model_group}:rpm:{current_minute}"
  
      tpm_dict = self.router_cache.get_cache(key=tpm_key)
      rpm_dict = self.router_cache.get_cache(key=rpm_key)
  
      # -----------------------
      # Find lowest used model
      # ----------------------
      lowest_tpm = float("inf")
      deployment = None
      if tpm_dict is None:  # base case
          item = random.choice(healthy_deployments)
          return item
  
      all_deployments = tpm_dict
      for d in healthy_deployments:
          ## if healthy deployment not yet used
          if d["model_info"]["id"] not in all_deployments:
              all_deployments[d["model_info"]["id"]] = 0
  
      try:
          input_tokens = token_counter(messages=messages, text=input)
      except:
          input_tokens = 0
  
      for item, item_tpm in all_deployments.items():
          ## get the item from model list
          _deployment = None
          for m in healthy_deployments:
              if item == m["model_info"]["id"]:
                  _deployment = m
  
          if _deployment is None:
              continue  # skip to next one
  
          _deployment_tpm = (
              _deployment.get("tpm", None)
              or _deployment.get("litellm_params", {}).get("tpm", None)
              or _deployment.get("model_info", {}).get("tpm", None)
              or float("inf")
          )
  
          _deployment_rpm = (
              _deployment.get("rpm", None)
              or _deployment.get("litellm_params", {}).get("rpm", None)
              or _deployment.get("model_info", {}).get("rpm", None)
              or float("inf")
          )
  
          if item_tpm == 0:
              deployment = _deployment
              break
          elif (
              item_tpm + input_tokens > _deployment_tpm
              or rpm_dict[item] + 1 > _deployment_rpm
          ):  # if user passed in tpm / rpm in the model_list
              continue
          elif item_tpm < lowest_tpm:
              lowest_tpm = item_tpm
              deployment = _deployment
      return deployment
  
file_path: litellm/litellm/router_strategy/lowest_tpm_rpm.py
imports: import dotenv, os, requests, random
  from typing import Optional, Union, List, Dict
  from datetime import datetime
  import traceback
  from litellm import token_counter
  from litellm.caching import DualCache
  from litellm.integrations.custom_logger import CustomLogger
label_desc: Use image node_id 3 for calling the LowestTPMLoggingHandler obj's underlying member method code with example usage: obj.get_available_deployments(model_group, healthy_deployments, messages, input) and returns: deployment, item