code: def _truncate_predicted_text(
      predicted_text: str,
      request_state: RequestState,
      adapter_spec: AdapterSpec,
  ) -> Optional[str]:
      method = adapter_spec.method
      prefix = ""
      if method in ADAPT_MULTIPLE_CHOICE_SEPARATE_METHODS:
          prefix = request_state.instance.input.text
      elif method == "language_modeling":
          if (
              request_state.result is not None
              and request_state.result.completions
          ):
              tokens = request_state.result.completions[0].tokens
              if tokens:
                  first_token = tokens[0]
                  if not first_token.top_logprobs:
                      prefix = first_token.text
      if prefix:
          predicted_text = predicted_text
          prefix = prefix
          if predicted_text.startswith(prefix):
              return predicted_text[len(prefix) :]
      return None
  
imports: from collections import OrderedDict, defaultdict
  from dataclasses import dataclass
  import os
  from typing import Dict, Iterable, List, Optional, Set, Tuple
  from helm.benchmark.adaptation.adapters.adapter_factory import ADAPT_MULTIPLE_CHOICE_SEPARATE_METHODS, ADAPT_MULTIPLE_CHOICE_SEPARATE_CALIBRATED
  from helm.benchmark.adaptation.adapter_spec import AdapterSpec
  from helm.benchmark.adaptation.request_state import RequestState
  from helm.benchmark.adaptation.scenario_state import ScenarioState
  from helm.benchmark.augmentations.perturbation_description import PerturbationDescription
  from helm.benchmark.metrics.metric import PerInstanceStats
  from helm.benchmark.presentation.schema import Schema
  from helm.benchmark.runner import RunSpec
  from helm.benchmark.scenarios.scenario import Instance
  from helm.common.general import write
  from helm.common.hierarchical_logger import htrack
  from helm.common.request import Request
  from helm.common.codec import from_json, to_json
label_desc: Use image node_id 3 for calling a global function with example usage: _truncate_predicted_text(predicted_text, request_state, adapter_spec) and returns: None, predicted_text