docstr: Returns a deployment with the lowest latency
docstr_tok: ["Returns","a","deployment","with","the","lowest","latency"]
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 latency
      """
      # get list of potential deployments
      latency_key = f"{model_group}_map"
  
      request_count_dict = (
          self.router_cache.get_cache(key=latency_key) or {}
      )
  
      # -----------------------
      # Find lowest used model
      # ----------------------
      lowest_latency = float("inf")
  
      current_date = datetime.now().strftime("%Y-%m-%d")
      current_hour = datetime.now().strftime("%H")
      current_minute = datetime.now().strftime("%M")
      precise_minute = f"{current_date}-{current_hour}-{current_minute}"
  
      deployment = None
  
      if request_count_dict is None:  # base case
          return
  
      all_deployments = request_count_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"]] = {
                  "latency": [0],
                  precise_minute: {"tpm": 0, "rpm": 0},
              }
  
      try:
          input_tokens = token_counter(messages=messages, text=input)
      except:
          input_tokens = 0
  
      for item, item_map 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")
          )
          item_latency = item_map.get("latency", [])
          item_rpm = item_map.get(precise_minute, {}).get("rpm", 0)
          item_tpm = item_map.get(precise_minute, {}).get("tpm", 0)
  
          # get average latency
          total: float = 0.0
          for _call_latency in item_latency:
              if isinstance(_call_latency, float):
                  total += _call_latency
          item_latency = total / len(item_latency)
          if item_latency == 0:
              deployment = _deployment
              break
          elif (
              item_tpm + input_tokens > _deployment_tpm
              or item_rpm + 1 > _deployment_rpm
          ):  # if user passed in tpm / rpm in the model_list
              continue
          elif item_latency < lowest_latency:
              lowest_latency = item_latency
              deployment = _deployment
      if deployment is None:
          deployment = random.choice(healthy_deployments)
      return deployment
  
file_path: litellm/litellm/router_strategy/lowest_latency.py
imports: from pydantic import BaseModel, Extra, Field, root_validator
  import dotenv, os, requests, random
  from typing import Optional, Union, List, Dict
  from datetime import datetime, timedelta
  import traceback
  from litellm.caching import DualCache
  from litellm.integrations.custom_logger import CustomLogger
  from litellm import ModelResponse
  from litellm import token_counter
label_desc: Use image node_id 3 for calling the LowestLatencyLoggingHandler obj's underlying member method code with example usage: obj.get_available_deployments(model_group, healthy_deployments, messages, input) and returns: deployment