code: def prompt_factory(
      model: str,
      messages: list,
      custom_llm_provider: Optional[str] = None,
      api_key: Optional[str] = None,
  ):
      original_model_name = model
      model = model.lower()
      if custom_llm_provider == "ollama":
          return ollama_pt(model=model, messages=messages)
      elif custom_llm_provider == "anthropic":
          if any(_ in model for _ in ["claude-2.1", "claude-v2:1"]):
              return claude_2_1_pt(messages=messages)
          else:
              return anthropic_pt(messages=messages)
      elif custom_llm_provider == "together_ai":
          prompt_format, chat_template = get_model_info(
              token=api_key, model=model
          )
          return format_prompt_togetherai(
              messages=messages,
              prompt_format=prompt_format,
              chat_template=chat_template,
          )
      elif custom_llm_provider == "gemini":
          if model == "gemini-pro-vision":
              return _gemini_vision_convert_messages(messages=messages)
          else:
              return gemini_text_image_pt(messages=messages)
      try:
          if "meta-llama/llama-2" in model and "chat" in model:
              return llama_2_chat_pt(messages=messages)
          elif (
              "tiiuae/falcon" in model
          ):  # Note: for the instruct models, it's best to use a User: .., Assistant:.. approach in your prompt template.
              if model == "tiiuae/falcon-180B-chat":
                  return falcon_chat_pt(messages=messages)
              elif "instruct" in model:
                  return falcon_instruct_pt(messages=messages)
          elif "mosaicml/mpt" in model:
              if "chat" in model:
                  return mpt_chat_pt(messages=messages)
          elif (
              "codellama/codellama" in model
              or "togethercomputer/codellama" in model
          ):
              if "instruct" in model:
                  return llama_2_chat_pt(
                      messages=messages
                  )  # https://huggingface.co/blog/codellama#conversational-instructions
          elif "wizardlm/wizardcoder" in model:
              return wizardcoder_pt(messages=messages)
          elif "phind/phind-codellama" in model:
              return phind_codellama_pt(messages=messages)
          elif "togethercomputer/llama-2" in model and (
              "instruct" in model or "chat" in model
          ):
              return llama_2_chat_pt(messages=messages)
          elif model in [
              "gryphe/mythomax-l2-13b",
              "gryphe/mythomix-l2-13b",
              "gryphe/mythologic-l2-13b",
          ]:
              return alpaca_pt(messages=messages)
          else:
              return hf_chat_template(original_model_name, messages)
      except Exception as e:
          return default_pt(messages=messages)
  
imports: from enum import Enum
  import requests, traceback
  import json
  from jinja2 import Template, exceptions, Environment, meta
  from typing import Optional, Any
label_desc: Use image node_id 21 for calling a global function with example usage: prompt_factory(model, messages, custom_llm_provider, api_key) and returns: ollama_pt, llama_2_chat_pt, default_pt, claude_2_1_pt, anthropic_pt, format_prompt_togetherai, falcon_chat_pt, _gemini_vision_convert_messages, gemini_text_image_pt, falcon_instruct_pt, mpt_chat_pt, llama_2_chat_pt, wizardcoder_pt, phind_codellama_pt, llama_2_chat_pt, alpaca_pt, hf_chat_template