code: def completion(
      model: str,
      messages: list,
      model_response: ModelResponse,
      print_verbose: Callable,
      api_key,
      encoding,
      logging_obj,
      optional_params=None,
      litellm_params=None,
      logger_fn=None,
  ):
      try:
          import google.generativeai as palm
      except:
          raise Exception(
              "Importing google.generativeai failed, please run 'pip install -q google-generativeai"
          )
      palm.configure(api_key=api_key)
  
      model = model
  
      ## Load Config
      inference_params = copy.deepcopy(optional_params)
      inference_params.pop(
          "stream", None
      )  # palm does not support streaming, so we handle this by fake streaming in main.py
      config = litellm.PalmConfig.get_config()
      for k, v in config.items():
          if (
              k not in inference_params
          ):  # completion(top_k=3) > palm_config(top_k=3) <- allows for dynamic variables to be passed in
              inference_params[k] = v
  
      prompt = ""
      for message in messages:
          if "role" in message:
              if message["role"] == "user":
                  prompt += f"{message['content']}"
              else:
                  prompt += f"{message['content']}"
          else:
              prompt += f"{message['content']}"
  
      ## LOGGING
      logging_obj.pre_call(
          input=prompt,
          api_key="",
          additional_args={
              "complete_input_dict": {
                  "inference_params": inference_params
              }
          },
      )
      ## COMPLETION CALL
      try:
          response = palm.generate_text(
              prompt=prompt, **inference_params
          )
      except Exception as e:
          raise PalmError(
              message=str(e),
              status_code=500,
          )
  
      ## LOGGING
      logging_obj.post_call(
          input=prompt,
          api_key="",
          original_response=response,
          additional_args={"complete_input_dict": {}},
      )
      print_verbose(f"raw model_response: {response}")
      ## RESPONSE OBJECT
      completion_response = response
      try:
          choices_list = []
          for idx, item in enumerate(completion_response.candidates):
              if len(item["output"]) > 0:
                  message_obj = Message(content=item["output"])
              else:
                  message_obj = Message(content=None)
              choice_obj = Choices(index=idx + 1, message=message_obj)
              choices_list.append(choice_obj)
          model_response["choices"] = choices_list
      except Exception as e:
          traceback.print_exc()
          raise PalmError(
              message=traceback.format_exc(),
              status_code=response.status_code,
          )
  
      try:
          completion_response = model_response["choices"][0][
              "message"
          ].get("content")
      except:
          raise PalmError(
              status_code=400,
              message=f"No response received. Original response - {response}",
          )
  
      ## CALCULATING USAGE - baseten charges on time, not tokens - have some mapping of cost here.
      prompt_tokens = len(encoding.encode(prompt))
      completion_tokens = len(
          encoding.encode(
              model_response["choices"][0]["message"].get("content", "")
          )
      )
  
      model_response["created"] = int(time.time())
      model_response["model"] = "palm/" + model
      usage = Usage(
          prompt_tokens=prompt_tokens,
          completion_tokens=completion_tokens,
          total_tokens=prompt_tokens + completion_tokens,
      )
      model_response.usage = usage
      return model_response
  
file_path: litellm/litellm/llms/palm.py
imports: import os, types, traceback, copy
  import json
  from enum import Enum
  import time
  from typing import Callable, Optional
  from litellm.utils import ModelResponse, get_secret, Choices, Message, Usage
  import litellm
  import sys, httpx
label_desc: Use image node_id 1 for calling a global function with example usage: completion(model, messages, model_response, print_verbose, api_key, encoding, logging_obj, optional_params, litellm_params, logger_fn) and returns: model_response