code: def _token_count_eval_fn(predictions, targets=None, metrics=None):
      import tiktoken
  
      # ref: https://github.com/openai/tiktoken/issues/75
      os.environ["TIKTOKEN_CACHE_DIR"] = ""
      encoding = tiktoken.get_encoding("cl100k_base")
  
      num_tokens = []
      for prediction in predictions:
          if isinstance(prediction, str):
              num_tokens.append(len(encoding.encode(prediction)))
          else:
              num_tokens.append(None)
  
      return MetricValue(
          scores=num_tokens,
          aggregate_results={},
      )
  
imports: import functools
  import logging
  import os
  import numpy
  from mlflow.metrics.base import MetricValue, standard_aggregations
label_desc: Use image node_id 4 for calling a global function with example usage: _token_count_eval_fn(predictions, targets, metrics) and returns: MetricValue