class_docstr: An `Adapter`, guided by the `AdapterSpec`, takes a `Scenario` and produces
  a `ScenarioState`. It has additional logic surrounding in-context examples.
docstr: Returns a prompt given:
  - the `self.adapter_spec.instructions`
  - the `train_instances` (in-context training examples)
  - the input part of the `eval_instance`
  - the `reference` if `include_output` is true (if reference_index is not None, the reference
  at the given index; otherwise, the first correct reference)
  
  Fits the prompt within the context window by removing in-context training examples.
docstr_tok: ["Returns","a","prompt","given",":","-","the","`","self.adapter_spec.instructions","`","-","the","`","train_instances","`","(","in-context","training","examples",")","-","the","input","part","of","the","`","eval_instance","`","-","the","`","reference","`","if","`","include_output","`","is","true","(","if","reference_index","is","not","None",",","the","reference","at","the","given","index",";","otherwise",",","the","first","correct","reference",")","Fits","the","prompt","within","the","context","window","by","removing","in-context","training","examples","."]
code: def construct_prompt(
      self,
      train_instances: List[Instance],
      eval_instance: Instance,
      include_output: bool,
      reference_index: Optional[int],
  ) -> Prompt:
      """
      Returns a prompt given:
      - the `self.adapter_spec.instructions`
      - the `train_instances` (in-context training examples)
      - the input part of the `eval_instance`
      - the `reference` if `include_output` is true (if reference_index is not None, the reference
      at the given index; otherwise, the first correct reference)
  
      Fits the prompt within the context window by removing in-context training examples.
      """
      # Instruction text
      instructions_block: str = self.adapter_spec.instructions
  
      # Text for in-context training instances
      train_instance_blocks: List[str] = [
          self.construct_example_prompt(
              inst, include_output=True, reference_index=None
          )
          for inst in train_instances
      ]
  
      # Example text
      eval_instance_block: str = self.construct_example_prompt(
          eval_instance,
          include_output=include_output,
          reference_index=reference_index,
      )
  
      # Prompt
      prompt = Prompt(
          global_prefix=self.adapter_spec.global_prefix,
          instructions_block=instructions_block,
          train_instance_blocks=train_instance_blocks,
          eval_instance_block=eval_instance_block,
          instance_prefix=self.adapter_spec.instance_prefix,
          substitutions=self.adapter_spec.substitutions,
      )
  
      # Make prompt fit within the context window
      prompt = self._make_prompt_fit(prompt)
      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 4 for calling the InContextLearningAdapter obj's underlying member method code with example usage: obj.construct_prompt(train_instances, eval_instance, include_output, reference_index) and returns: prompt