class_docstr: (openai<1) A class for OpenAI completion API.
  
  It also supports: ChatCompletion, Azure OpenAI API.
code: def _construct_params(
      cls,
      context,
      config,
      prompt=None,
      messages=None,
      allow_format_str_template=False,
  ):
      params = config.copy()
      model = config["model"]
      prompt = config.get("prompt") if prompt is None else prompt
      messages = (
          config.get("messages") if messages is None else messages
      )
      # either "prompt" should be in config (for being compatible with non-chat models)
      # or "messages" should be in config (for tuning chat models only)
      if prompt is None and (
          model in cls.chat_models or issubclass(cls, ChatCompletion)
      ):
          if messages is None:
              raise ValueError(
                  "Either prompt or messages should be in config for chat models."
              )
      if prompt is None:
          params["messages"] = (
              [
                  {
                      **m,
                      "content": cls.instantiate(
                          m["content"],
                          context,
                          allow_format_str_template,
                      ),
                  }
                  if m.get("content")
                  else m
                  for m in messages
              ]
              if context
              else messages
          )
      elif model in cls.chat_models or issubclass(cls, ChatCompletion):
          # convert prompt to messages
          params["messages"] = [
              {
                  "role": "user",
                  "content": cls.instantiate(
                      prompt, context, allow_format_str_template
                  ),
              },
          ]
          params.pop("prompt", None)
      else:
          params["prompt"] = cls.instantiate(
              prompt, context, allow_format_str_template
          )
      return params
  
imports: from time import sleep
  import logging
  import time
  from typing import List, Optional, Dict, Callable, Union
  import sys
  import shutil
  import numpy
  from flaml import tune, BlendSearch
  from flaml.tune.space import is_constant
  from flaml.automl.logger import logger_formatter
  from .openai_utils import get_key
  from collections import defaultdict
label_desc: Use image node_id 15 for calling the Completion obj's underlying member method code with example usage: obj._construct_params(cls, context, config, prompt, messages, allow_format_str_template) and returns: params