class_docstr: LiteLLMHandler is a MindsDB handler for litellm - https://docs.litellm.ai/docs/
class_docstr_tok: ["LiteLLMHandler","is","a","MindsDB","handler","for","litellm","-","https",":","\/\/docs.litellm.ai\/docs\/"]
docstr: Build messages for completion
docstr_tok: ["Build","messages","for","completion"]
code: def _build_messages(self, args: dict, df: pd.DataFrame):
      """
      Build messages for completion
      """
  
      prompt_kwargs = df.iloc[0].to_dict()
  
      if "prompt_template" in prompt_kwargs:
          # if prompt_template is passed in predict query, use it
          logger.info(
              "Using 'prompt_template' passed in SELECT Predict query. "
              "Note this will overwrite a 'prompt_template' passed in create MODEL query."
          )
  
          args["prompt_template"] = prompt_kwargs.pop("prompt_template")
  
      if "mock_response" in prompt_kwargs:
          # used for testing to save on real completion api calls
          args["mock_response"]: str = prompt_kwargs.pop(
              "mock_response"
          )
  
      if "messages" in prompt_kwargs and len(prompt_kwargs) > 1:
          # if user passes in messages, no other args can be passed in
          raise Exception(
              "If 'messages' is passed in SELECT Predict query, no other args can be passed in."
          )
  
      # if user passes in messages, use those instead
      if "messages" in prompt_kwargs:
          logger.info(
              "Using messages passed in SELECT Predict query. 'prompt_template' will be ignored."
          )
  
          args["messages"]: List = ast.literal_eval(
              df["messages"].iloc[0]
          )
  
      else:
          # if user passes in prompt_template, use that to create messages
          if len(prompt_kwargs) == 1:
              args["messages"] = (
                  self._prompt_to_messages(
                      args["prompt_template"], **prompt_kwargs
                  )
                  if args["prompt_template"]
                  else self._prompt_to_messages(df.iloc[0][0])
              )
  
          elif len(prompt_kwargs) > 1:
              try:
                  args["messages"] = self._prompt_to_messages(
                      args["prompt_template"], **prompt_kwargs
                  )
              except KeyError as e:
                  raise Exception(
                      f"{e}: Please pass in either a prompt_template on create MODEL or "
                      f"a single where clause in predict query."
                      f""
                  )
  
file_path: mindsdb/mindsdb/integrations/handlers/litellm_handler/litellm_handler.py
imports: import ast
  from typing import Dict, Optional, List
  import pandas
  from mindsdb.integrations.libs.base import BaseMLEngine
  from mindsdb.utilities import log
  from mindsdb.integrations.handlers.litellm_handler.settings import CompletionParameters
  from litellm import completion, batch_completion
label_desc: Use image node_id 6 for calling the LiteLLMHandler obj's underlying member method code with example usage: obj._build_messages(args, df) without return types