docstr: Truncates text from the right to fit within the context window given by `max_request_length`
  minus the expected completion length (defaults to 0).
  
  By default, Hugging Face uses the 'longest_first' truncation strategy:
  "Iteratively reduce the inputs sequence until the input is under max_length starting from the longest one
  at each token (when there is a pair of input sequences)."
  
  Since we are only passing in a single string, the tokenizer will simply truncate from the right.
docstr_tok: ["Truncates","text","from","the","right","to","fit","within","the","context","window","given","by","`","max_request_length","`","minus","the","expected","completion","length","(","defaults","to","0",")",".","By","default",",","Hugging","Face","uses","the","'longest_first","'","truncation","strategy",":","''","Iteratively","reduce","the","inputs","sequence","until","the","input","is","under","max_length","starting","from","the","longest","one","at","each","token","(","when","there","is","a","pair","of","input","sequences",")",".","''","Since","we","are","only","passing","in","a","single","string",",","the","tokenizer","will","simply","truncate","from","the","right","."]
code: def truncate_from_right(
      self, text: str, expected_completion_token_length: int = 0
  ) -> str:
      """
      Truncates text from the right to fit within the context window given by `max_request_length`
      minus the expected completion length (defaults to 0).
  
      By default, Hugging Face uses the 'longest_first' truncation strategy:
      "Iteratively reduce the inputs sequence until the input is under max_length starting from the longest one
      at each token (when there is a pair of input sequences)."
  
      Since we are only passing in a single string, the tokenizer will simply truncate from the right.
      """
      max_length: int = (
          self.max_request_length - expected_completion_token_length
      )
      result: str = self.decode(
          self.encode(
              text, truncation=True, max_length=max_length
          ).tokens
      )
  
      # HACK: For the vast majority of cases, the above logic works, but it sometimes doesn't work
      # for non-English, non-Chinese text (e.g., Russian from multi_eurlex. See more
      # in https://github.com/stanford-crfm/helm/issues/1448).
      # Truncate by removing character by character until the prompt fits within the context window.
      while not self.fits_within_context_window(
          result, expected_completion_token_length
      ):
          result = result[:-1]
      return result
  
file_path: H2O/h2o_hf/helm/src/helm/benchmark/window_services/local_window_service.py
imports: from typing import List, Optional, cast
  from .window_service import WindowService, EncodeResult
  from .tokenizer_service import TokenizerService
  from helm.common.tokenization_request import DecodeRequest, DecodeRequestResult, TokenizationRequest, TokenizationRequestResult, TokenizationToken
label_desc: Use image node_id 7 for calling the LocalWindowService obj's underlying member method code with example usage: obj.truncate_from_right(text, expected_completion_token_length) and returns: result