code: def prune_history(
      user_messages_sizes, bot_messages_sizes, max_history_size
  ):
      """Prune the history from the beginning not to exceed the maximum context length."""
      nb_rounds = len(user_messages_sizes)
      # Put messages sizes in antichronological order
      reversed_user_messages_sizes = user_messages_sizes[::-1]
      reversed_bot_messages_sizes = bot_messages_sizes[::-1]
      reversed_rounds_indices = list(range(nb_rounds))[::-1]
      # Caluculate antichronological history sizes
      reversed_round_sizes = [
          sum(i)
          for i in zip(
              reversed_user_messages_sizes, reversed_bot_messages_sizes
          )
      ]
      reversed_history_sizes = np.cumsum(reversed_round_sizes)
      keep_rounds_indices = []
      # Prune the history from the beginning
      for i, n in enumerate(np.cumsum(reversed_history_sizes)):
          if n < max_history_size:
              keep_rounds_indices.append(reversed_rounds_indices[i])
      # Put back indices in chronological order.
      keep_rounds_indices.reverse()
      return keep_rounds_indices
  
file_path: OpenNMT-py/docs/source/examples/replicate_vicuna/chatbot.py
imports: import argparse
  import gradio
  import numpy
  import time
  import onmt.opts
  from onmt.transforms.tokenize import SentencePieceTransform
  from onmt.utils.parse import ArgumentParser
  from onmt.utils.misc import use_gpu, set_random_seed
label_desc: Use image node_id 2 for calling a global function with example usage: prune_history(user_messages_sizes, bot_messages_sizes, max_history_size) and returns: keep_rounds_indices