docstr: Get the cache key for the given arguments.
  
  Args:
      *args: args to litellm.completion() or embedding()
      **kwargs: kwargs to litellm.completion() or embedding()
  
  Returns:
      str: The cache key generated from the arguments, or None if no cache key could be generated.
docstr_tok: ["Get","the","cache","key","for","the","given","arguments",".","Args",":","*","args",":","args","to","litellm.completion","(",")","or","embedding","(",")","*","*","kwargs",":","kwargs","to","litellm.completion","(",")","or","embedding","(",")","Returns",":","str",":","The","cache","key","generated","from","the","arguments",",","or","None","if","no","cache","key","could","be","generated","."]
code: def get_cache_key(self, *args, **kwargs):
      """
      Get the cache key for the given arguments.
  
      Args:
          *args: args to litellm.completion() or embedding()
          **kwargs: kwargs to litellm.completion() or embedding()
  
      Returns:
          str: The cache key generated from the arguments, or None if no cache key could be generated.
      """
      cache_key = ""
      print_verbose(f"\nGetting Cache key. Kwargs: {kwargs}")
  
      # for streaming, we use preset_cache_key. It's created in wrapper(), we do this because optional params like max_tokens, get transformed for bedrock -> max_new_tokens
      if (
          kwargs.get("litellm_params", {}).get("preset_cache_key", None)
          is not None
      ):
          print_verbose(f"\nReturning preset cache key: {cache_key}")
          return kwargs.get("litellm_params", {}).get(
              "preset_cache_key", None
          )
  
      # sort kwargs by keys, since model: [gpt-4, temperature: 0.2, max_tokens: 200] == [temperature: 0.2, max_tokens: 200, model: gpt-4]
      completion_kwargs = [
          "model",
          "messages",
          "temperature",
          "top_p",
          "n",
          "stop",
          "max_tokens",
          "presence_penalty",
          "frequency_penalty",
          "logit_bias",
          "user",
          "response_format",
          "seed",
          "tools",
          "tool_choice",
      ]
      embedding_only_kwargs = [
          "input",
          "encoding_format",
      ]  # embedding kwargs = model, input, user, encoding_format. Model, user are checked in completion_kwargs
  
      # combined_kwargs - NEEDS to be ordered across get_cache_key(). Do not use a set()
      combined_kwargs = completion_kwargs + embedding_only_kwargs
      for param in combined_kwargs:
          # ignore litellm params here
          if param in kwargs:
              # check if param == model and model_group is passed in, then override model with model_group
              if param == "model":
                  model_group = None
                  caching_group = None
                  metadata = kwargs.get("metadata", None)
                  litellm_params = kwargs.get("litellm_params", {})
                  if metadata is not None:
                      model_group = metadata.get("model_group")
                      model_group = metadata.get("model_group", None)
                      caching_groups = metadata.get(
                          "caching_groups", None
                      )
                      if caching_groups:
                          for group in caching_groups:
                              if model_group in group:
                                  caching_group = group
                                  break
                  if litellm_params is not None:
                      metadata = litellm_params.get("metadata", None)
                      if metadata is not None:
                          model_group = metadata.get(
                              "model_group", None
                          )
                          caching_groups = metadata.get(
                              "caching_groups", None
                          )
                          if caching_groups:
                              for group in caching_groups:
                                  if model_group in group:
                                      caching_group = group
                                      break
                  param_value = (
                      caching_group or model_group or kwargs[param]
                  )  # use caching_group, if set then model_group if it exists, else use kwargs["model"]
              else:
                  if kwargs[param] is None:
                      continue  # ignore None params
                  param_value = kwargs[param]
              cache_key += f"{str(param)}: {str(param_value)}"
      print_verbose(f"\nCreated cache key: {cache_key}")
      # Use hashlib to create a sha256 hash of the cache key
      hash_object = hashlib.sha256(cache_key.encode())
      # Hexadecimal representation of the hash
      hash_hex = hash_object.hexdigest()
      print_verbose(f"Hashed cache key (SHA-256): {hash_hex}")
      return hash_hex
  
imports: import litellm
  import time, logging
  import json, traceback, ast, hashlib
  from typing import Optional, Literal, List, Union, Any
  from openai._models import BaseModel
label_desc: Use image node_id 2 for calling the Cache obj's underlying member method code with example usage: obj.get_cache_key() and returns: hash_hex, kwargs