class_docstr: The TextHistory class keeps track of the history of an interaction between the language model and the environment.
docstr: Initialize TextHistory.
  
  args:
      text (`str`): The text of the first segment.
      tokens (`torch.LongTensor`): The tokens of the first segment.
      system (`bool`, *optional*): Whether the first segment is a system or user segment.
docstr_tok: ["Initialize","TextHistory",".","args",":","text","(","`","str","`",")",":","The","text","of","the","first","segment",".","tokens","(","`","torch.LongTensor","`",")",":","The","tokens","of","the","first","segment",".","system","(","`","bool","`",",","*","optional","*",")",":","Whether","the","first","segment","is","a","system","or","user","segment","."]
code: def __init__(self, text, tokens, system=True):
      """
      Initialize TextHistory.
  
      args:
          text (`str`): The text of the first segment.
          tokens (`torch.LongTensor`): The tokens of the first segment.
          system (`bool`, *optional*): Whether the first segment is a system or user segment.
      """
      self.system_spans = []
      self.text_spans = []
      self.token_spans = []
      self.token_masks = torch.tensor([], dtype=torch.long).to(
          tokens.device
      )
      self.text = ""
      self.tokens = torch.tensor([], dtype=torch.long).to(tokens.device)
      self.completed = False
      self.truncated = False
      self.reward = 0.0
  
      self.prompt_color = "black on grey85"
      self.system_color = "black on cyan3"
      self.model_color = "black on deep_sky_blue1"
      self.reward_color = "black on plum1"
  
      self.append_segment(text, tokens, system=system)
  
imports: import re
  import warnings
  import torch
  from accelerate.utils import extract_model_from_parallel
  from transformers import StoppingCriteria, StoppingCriteriaList
  from ..import_utils import is_rich_available
label_desc: Use image node_id 1 to create a new TextHistory object  with example: obj = TextHistory(text, tokens, system)