code: def convert_to_model_response_object(
      self,
      completion_response,
      model_response,
      task,
      optional_params,
      encoding,
      input_text,
      model,
  ):
      if task == "conversational":
          if len(completion_response["generated_text"]) > 0:  # type: ignore
              model_response["choices"][0]["message"][
                  "content"
              ] = completion_response[
                  "generated_text"
              ]  # type: ignore
      elif task == "text-generation-inference":
          if (
              not isinstance(completion_response, list)
              or not isinstance(completion_response[0], dict)
              or "generated_text" not in completion_response[0]
          ):
              raise HuggingfaceError(
                  status_code=422,
                  message=f"response is not in expected format - {completion_response}",
              )
  
          if len(completion_response[0]["generated_text"]) > 0:
              model_response["choices"][0]["message"][
                  "content"
              ] = output_parser(
                  completion_response[0]["generated_text"]
              )
          ## GETTING LOGPROBS + FINISH REASON
          if (
              "details" in completion_response[0]
              and "tokens" in completion_response[0]["details"]
          ):
              model_response.choices[
                  0
              ].finish_reason = completion_response[0]["details"][
                  "finish_reason"
              ]
              sum_logprob = 0
              for token in completion_response[0]["details"]["tokens"]:
                  if token["logprob"] != None:
                      sum_logprob += token["logprob"]
              model_response["choices"][0][
                  "message"
              ]._logprob = sum_logprob
          if (
              "best_of" in optional_params
              and optional_params["best_of"] > 1
          ):
              if (
                  "details" in completion_response[0]
                  and "best_of_sequences"
                  in completion_response[0]["details"]
              ):
                  choices_list = []
                  for idx, item in enumerate(
                      completion_response[0]["details"][
                          "best_of_sequences"
                      ]
                  ):
                      sum_logprob = 0
                      for token in item["tokens"]:
                          if token["logprob"] != None:
                              sum_logprob += token["logprob"]
                      if len(item["generated_text"]) > 0:
                          message_obj = Message(
                              content=output_parser(
                                  item["generated_text"]
                              ),
                              logprobs=sum_logprob,
                          )
                      else:
                          message_obj = Message(content=None)
                      choice_obj = Choices(
                          finish_reason=item["finish_reason"],
                          index=idx + 1,
                          message=message_obj,
                      )
                      choices_list.append(choice_obj)
                  model_response["choices"].extend(choices_list)
      else:
          if len(completion_response[0]["generated_text"]) > 0:
              model_response["choices"][0]["message"][
                  "content"
              ] = output_parser(
                  completion_response[0]["generated_text"]
              )
      ## CALCULATING USAGE
      prompt_tokens = 0
      try:
          prompt_tokens = len(
              encoding.encode(input_text)
          )  ##[TODO] use the llama2 tokenizer here
      except:
          # this should remain non blocking we should not block a response returning if calculating usage fails
          pass
      output_text = model_response["choices"][0]["message"].get(
          "content", ""
      )
      if output_text is not None and len(output_text) > 0:
          completion_tokens = 0
          try:
              completion_tokens = len(
                  encoding.encode(
                      model_response["choices"][0]["message"].get(
                          "content", ""
                      )
                  )
              )  ##[TODO] use the llama2 tokenizer here
          except:
              # this should remain non blocking we should not block a response returning if calculating usage fails
              pass
      else:
          completion_tokens = 0
  
      model_response["created"] = int(time.time())
      model_response["model"] = model
      usage = Usage(
          prompt_tokens=prompt_tokens,
          completion_tokens=completion_tokens,
          total_tokens=prompt_tokens + completion_tokens,
      )
      model_response.usage = usage
      model_response._hidden_params[
          "original_response"
      ] = completion_response
      return model_response
  
imports: import os, copy, types
  import json
  from enum import Enum
  import httpx, requests
  from .base import BaseLLM
  import time
  import litellm
  from typing import Callable, Dict, List, Any
  from litellm.utils import ModelResponse, Choices, Message, CustomStreamWrapper, Usage
  from typing import Optional
  from .prompt_templates.factory import prompt_factory, custom_prompt
label_desc: Use image node_id 3 for calling the Huggingface obj's underlying member method code with example usage: obj.convert_to_model_response_object(completion_response, model_response, task, optional_params, encoding, input_text, model) and returns: model_response