class_docstr: Class to resolve the request/response from the Cohere API and convert it to a dictionary that can be logged.
class_docstr_tok: ["Class","to","resolve","the","request\/response","from","the","Cohere","API","and","convert","it","to","a","dictionary","that","can","be","logged","."]
docstr: Process the response from the Cohere API and convert it to a dictionary that can be logged.
  
  :param args: The arguments of the original function.
  :param kwargs: The keyword arguments of the original function.
  :param response: The response from the Cohere API.
  :param start_time: The start time of the request.
  :param time_elapsed: The time elapsed for the request.
  :return: A dictionary containing the parsed response and timing information.
docstr_tok: ["Process","the","response","from","the","Cohere","API","and","convert","it","to","a","dictionary","that","can","be","logged",".",":","param","args",":","The","arguments","of","the","original","function",".",":","param","kwargs",":","The","keyword","arguments","of","the","original","function",".",":","param","response",":","The","response","from","the","Cohere","API",".",":","param","start_time",":","The","start","time","of","the","request",".",":","param","time_elapsed",":","The","time","elapsed","for","the","request",".",":","return",":","A","dictionary","containing","the","parsed","response","and","timing","information","."]
code: def __call__(
      self,
      args: Sequence[Any],
      kwargs: Dict[str, Any],
      response: Response,
      start_time: float,
      time_elapsed: float,
  ) -> Optional[Dict[str, Any]]:
      """Process the response from the Cohere API and convert it to a dictionary that can be logged.
  
      :param args: The arguments of the original function.
      :param kwargs: The keyword arguments of the original function.
      :param response: The response from the Cohere API.
      :param start_time: The start time of the request.
      :param time_elapsed: The time elapsed for the request.
      :return: A dictionary containing the parsed response and timing information.
      """
      try:
          # Each of the different endpoints map to one specific response type
          # We want to 'type check' the response without directly importing the packages type
          # It may make more sense to pass the invoked symbol from the AutologAPI instead
          response_type = (
              str(type(response)).split("'")[1].split(".")[-1]
          )
  
          # Initialize parsed_response to None to handle the case where the response type is unsupported
          parsed_response = None
          if response_type == "Generations":
              parsed_response = self._resolve_generate_response(
                  response
              )
              # TODO: Remove hard-coded default model name
              table_column_order = [
                  "start_time",
                  "query_id",
                  "model",
                  "prompt",
                  "text",
                  "token_likelihoods",
                  "likelihood",
                  "time_elapsed_(seconds)",
                  "end_time",
              ]
              default_model = "command"
          elif response_type == "Chat":
              parsed_response = self._resolve_chat_response(response)
              table_column_order = [
                  "start_time",
                  "query_id",
                  "model",
                  "conversation_id",
                  "response_id",
                  "query",
                  "text",
                  "prompt",
                  "preamble",
                  "chat_history",
                  "chatlog",
                  "time_elapsed_(seconds)",
                  "end_time",
              ]
              default_model = "command"
          elif response_type == "Classifications":
              parsed_response = self._resolve_classify_response(
                  response
              )
              kwargs = self._resolve_classify_kwargs(kwargs)
              table_column_order = [
                  "start_time",
                  "query_id",
                  "model",
                  "id",
                  "input",
                  "prediction",
                  "confidence",
                  "time_elapsed_(seconds)",
                  "end_time",
              ]
              default_model = "embed-english-v2.0"
          elif response_type == "SummarizeResponse":
              parsed_response = self._resolve_summarize_response(
                  response
              )
              table_column_order = [
                  "start_time",
                  "query_id",
                  "model",
                  "response_id",
                  "text",
                  "additional_command",
                  "summary",
                  "time_elapsed_(seconds)",
                  "end_time",
                  "length",
                  "format",
              ]
              default_model = "summarize-xlarge"
          elif response_type == "Reranking":
              parsed_response = self._resolve_rerank_response(response)
              table_column_order = [
                  "start_time",
                  "query_id",
                  "model",
                  "id",
                  "query",
                  "top_n",
                  # This is a nested dict key that got flattened
                  "document-text",
                  "relevance_score",
                  "index",
                  "time_elapsed_(seconds)",
                  "end_time",
              ]
              default_model = "rerank-english-v2.0"
          else:
              logger.info(
                  f"Unsupported Cohere response object: {response}"
              )
  
          return self._resolve(
              args,
              kwargs,
              parsed_response,
              start_time,
              time_elapsed,
              response_type,
              table_column_order,
              default_model,
          )
      except Exception as e:
          logger.warning(f"Failed to resolve request/response: {e}")
      return None
  
file_path: wandb/wandb/integration/cohere/resolver.py
imports: import logging
  from datetime import datetime
  from typing import Any, Dict, List, Optional, Sequence, Tuple
  import wandb
  from wandb.sdk.integration_utils.auto_logging import Response
  from wandb.sdk.lib.runid import generate_id
label_desc: Use image node_id 1 for calling the CohereRequestResponseResolver obj's underlying member method code with example usage: obj.__call__(args, kwargs, response, start_time, time_elapsed) and returns: None, self