code: def test_text_history_append_segment(self):
      text = "Hello there!"
      tokens = torch.tensor([1, 2, 3])
  
      history = TextHistory(text, tokens)
      history.append_segment(
          "General Kenobi!", torch.tensor([4, 5, 6]), system=False
      )
      self.assertEqual(history.text, text + "General Kenobi!")
      self.assertTrue(
          torch.equal(history.tokens, torch.tensor([1, 2, 3, 4, 5, 6]))
      )
      self.assertTrue(
          torch.equal(
              history.token_masks, torch.tensor([0, 0, 0, 1, 1, 1])
          )
      )
  
      history.append_segment(
          "You are a bold one!", torch.tensor([7, 8, 9])
      )
      self.assertEqual(
          history.text, text + "General Kenobi!" + "You are a bold one!"
      )
      self.assertTrue(
          torch.equal(
              history.tokens, torch.tensor([1, 2, 3, 4, 5, 6, 7, 8, 9])
          )
      )
      self.assertTrue(
          torch.equal(
              history.token_masks,
              torch.tensor([0, 0, 0, 1, 1, 1, 0, 0, 0]),
          )
      )
  
imports: import unittest
  from unittest.mock import patch
  import torch
  from transformers import AutoTokenizer
  from trl import AutoModelForCausalLMWithValueHead, TextEnvironment, TextHistory
label_desc: Use image node_id 2 for calling the TextHistoryTest obj's underlying member method code with example usage: obj.test_text_history_append_segment() without return types