code: def ollama_pt(
      model, messages
  ):  # https://github.com/jmorganca/ollama/blob/af4cf55884ac54b9e637cd71dadfe9b7a5685877/docs/modelfile.md#template
      if "instruct" in model:
          prompt = custom_prompt(
              role_dict={
                  "system": {
                      "pre_message": "### System:\n",
                      "post_message": "\n",
                  },
                  "user": {
                      "pre_message": "### User:\n",
                      "post_message": "\n",
                  },
                  "assistant": {
                      "pre_message": "### Response:\n",
                      "post_message": "\n",
                  },
              },
              final_prompt_value="### Response:",
              messages=messages,
          )
      elif "llava" in model:
          prompt = ""
          images = []
          for message in messages:
              if isinstance(message["content"], str):
                  prompt += message["content"]
              elif isinstance(message["content"], list):
                  # see https://docs.litellm.ai/docs/providers/openai#openai-vision-models
                  for element in message["content"]:
                      if isinstance(element, dict):
                          if element["type"] == "text":
                              prompt += element["text"]
                          elif element["type"] == "image_url":
                              image_url = element["image_url"]["url"]
                              images.append(image_url)
          return {"prompt": prompt, "images": images}
      else:
          prompt = "".join(
              m["content"]
              if isinstance(m["content"], str) is str
              else "".join(m["content"])
              for m in messages
          )
      return prompt
  
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 4 for calling a global function with example usage: ollama_pt(model, messages) and returns: prompt, dict