code: def count_tokens(messages, encoder, model_name="gpt-3.5-turbo-0301"):
      """Original token count implementation can be found in the OpenAI cookbook."""
      if (
          "gpt-3.5-turbo" in model_name
      ):  # note: future models may deviate from this (only 0301 really complies)
          num_tokens = 0
          for message in messages:
              num_tokens += 4  # every message follows <im_start>{role/name}\n{content}<im_end>\n
              for key, value in message.items():
                  num_tokens += len(encoder.encode(value))
                  if (
                      key == "name"
                  ):  # if there's a name, the role is omitted
                      num_tokens += (
                          -1
                      )  # role is always required and always 1 token
          num_tokens += (
              2  # every reply is primed with <im_start>assistant
          )
          return num_tokens
      else:
          raise NotImplementedError(
              f"""_count_tokens() is not presently implemented for model {model_name}."""
          )
  
file_path: mindsdb/mindsdb/integrations/handlers/openai_handler/helpers.py
imports: import os
  from typing import List
  import random
  import time
  import math
  import openai
  from openai import OpenAI
  import tiktoken
  import mindsdb.utilities.profiler
  from mindsdb.integrations.handlers.openai_handler.constants import OPENAI_API_BASE
label_desc: Use image node_id 3 for calling a global function with example usage: count_tokens(messages, encoder, model_name) and returns: num_tokens