docstr: Truncates text from the right to left to fit within the maximum context length given
  by `max_request_length`. Does not take into expected completion length because the
  the encoder-decoder models have separate max context lengths for the input prompts
  and completions.
docstr_tok: ["Truncates","text","from","the","right","to","left","to","fit","within","the","maximum","context","length","given","by","`","max_request_length","`",".","Does","not","take","into","expected","completion","length","because","the","the","encoder-decoder","models","have","separate","max","context","lengths","for","the","input","prompts","and","completions","."]
code: def truncate_from_right(
      self, text: str, expected_completion_token_length: int = 0
  ) -> str:
      """
      Truncates text from the right to left to fit within the maximum context length given
      by `max_request_length`. Does not take into expected completion length because the
      the encoder-decoder models have separate max context lengths for the input prompts
      and completions.
      """
      result: str = self.decode(
          self.encode(
              text, truncation=True, max_length=self.max_request_length
          ).tokens
      )
  
      # HACK: For the vast majority of cases, the above logic works, but there are a few where the
      # token count exceeds `max_length` by 1.
      while not self.fits_within_context_window(result):
          result = result[:-1]
  
      return result
  
file_path: H2O/h2o_hf/helm/src/helm/benchmark/window_services/encoder_decoder_window_service.py
imports: from abc import ABC
  from helm.common.hierarchical_logger import hlog
  from .local_window_service import LocalWindowService
  from .tokenizer_service import TokenizerService
label_desc: Use image node_id 5 for calling the EncoderDecoderWindowService obj's underlying member method code with example usage: obj.truncate_from_right(text, expected_completion_token_length) and returns: result