class_docstr: An `Adapter`, guided by the `AdapterSpec`, takes a `Scenario` and produces
  a `ScenarioState`. It has additional logic surrounding in-context examples.
docstr: The prompt consists of instructions, training instances, and the evaluation input.
  - First, we remove the fewest number of training instances as possible until the prompt fits.
  - Once we hit zero training instances, then we brutally truncate the
    prompt from the right (clearly suboptimal, but hopefully that doesn't
    happen too often).
  Return the prompt that fits.
docstr_tok: ["The","prompt","consists","of","instructions",",","training","instances",",","and","the","evaluation","input",".","-","First",",","we","remove","the","fewest","number","of","training","instances","as","possible","until","the","prompt","fits",".","-","Once","we","hit","zero","training","instances",",","then","we","brutally","truncate","the","prompt","from","the","right","(","clearly","suboptimal",",","but","hopefully","that","doesn't","happen","too","often",")",".","Return","the","prompt","that","fits","."]
code: def _make_prompt_fit(self, prompt: Prompt) -> Prompt:
      """
      The prompt consists of instructions, training instances, and the evaluation input.
      - First, we remove the fewest number of training instances as possible until the prompt fits.
      - Once we hit zero training instances, then we brutally truncate the
        prompt from the right (clearly suboptimal, but hopefully that doesn't
        happen too often).
      Return the prompt that fits.
      """
      # Following what was done for MMLU (https://arxiv.org/abs/2009.03300) to handle prompts that
      # exceed the max context length (https://github.com/hendrycks/test/blob/master/evaluate.py#L58),
      # we remove train instances one by one until it fits within the context window or
      # until we run out of train instances to remove.
      orig_train_instances_count: int = prompt.num_train_instances
      while prompt.num_train_instances > 0:
          if self.window_service.fits_within_context_window(
              text=prompt.text,
              expected_completion_token_length=self.adapter_spec.max_tokens,
          ):
              removed_train_instances_count: int = (
                  orig_train_instances_count
                  - prompt.num_train_instances
              )
              if removed_train_instances_count > 0:
                  hlog(
                      f"The original constructed prompt exceeded the max context length. "
                      f"Removed {removed_train_instances_count} in-context examples to fit "
                      f"it within the context window."
                  )
              return prompt
  
          # Remove the last training example
          prompt = replace(
              prompt,
              train_instance_blocks=prompt.train_instance_blocks[
                  : len(prompt.train_instance_blocks) - 1
              ],
          )
  
      # If removing the in-context example is still not enough, we simply truncate the prompt.
      # Following the default truncation strategy used by HuggingFace, we truncate the text from the right.
      text = prompt.text
      truncated_text = self.window_service.truncate_from_right(
          text, self.adapter_spec.max_tokens
      )
      if len(truncated_text) < len(text):
          prompt = replace(prompt, truncated_text=truncated_text)
      return prompt
  
imports: import random
  from abc import ABC
  from collections import defaultdict
  from dataclasses import replace
  from itertools import cycle
  from typing import List, Dict, Optional
  from helm.benchmark.adaptation.prompt import Prompt
  from helm.benchmark.adaptation.request_state import RequestState
  from helm.benchmark.adaptation.scenario_state import ScenarioState
  from helm.benchmark.scenarios.scenario import Instance, TRAIN_SPLIT, EVAL_SPLITS, Reference
  from helm.common.general import parallel_map
  from helm.common.hierarchical_logger import hlog, htrack, htrack_block
  from .adapter import Adapter
label_desc: Use image node_id 6 for calling the InContextLearningAdapter obj's underlying member method code with example usage: obj._make_prompt_fit(prompt) and returns: prompt, prompt