class_docstr: A ready-to-use Response Generator  model
  
  The class can be used to generate and continue dialogue given the user input.
  The given YAML must contain the fields specified in the *_NEEDED[] lists.
  It needs to be used with custom.py to load the expanded Llama2 model with added tokens like bos,eos, and speaker's tokens.
  
  Example
  -------
  >>> from speechbrain.inference.text import Llama2ResponseGenerator
  
  >>> tmpdir = getfixture("tmpdir")
  >>> res_gen_model = Llama2ResponseGenerator.from_hparams(source="speechbrain/MultiWOZ-Llama2-Response_Generation",
  ... savedir="tmpdir",
  ... pymodule_file="custom.py")  # doctest: +SKIP
  >>> response = res_gen_model.generate_response("I want to book a table for dinner")  # doctest: +SKIP
docstr: Convert user input and previous histories to the format acceptable for  Llama2 model.
      It appends all previous history and input and truncates it based on max_history value.
      It then tokenizes the input and add propmts.
  
  Arguments
  ---------
  
  Returns
  -------
  prompt_bos:
      Tokenized history+input values with appropriate prompt.
docstr_tok: ["Convert","user","input","and","previous","histories","to","the","format","acceptable","for","Llama2","model",".","It","appends","all","previous","history","and","input","and","truncates","it","based","on","max_history","value",".","It","then","tokenizes","the","input","and","add","propmts",".","Arguments","--","--","--","--","-","Returns","--","--","--","-","prompt_bos",":","Tokenized","history+input","values","with","appropriate","prompt","."]
code: def prepare_input(self):
      """Convert user input and previous histories to the format acceptable for  Llama2 model.
          It appends all previous history and input and truncates it based on max_history value.
          It then tokenizes the input and add propmts.
  
      Arguments
      ---------
  
      Returns
      -------
      prompt_bos:
          Tokenized history+input values with appropriate prompt.
      """
  
      def generate_prompt(idx_and_item):
          """add [INST] and [/INST] prompt to the start and end ogf item.
  
          Arguments
          ---------
          idx_and_item:
              id and its corresponding text. If the id is even, it is user turn and [ INST] is added.
          Returns
          -------
          prompt_bos:
              prompted text  for one item.
          """
          index, item = idx_and_item
          if index % 2 == 0:
              return "[INST] " + item + " [/INST]"
          else:
              return item
  
      prompts = list(map(generate_prompt, enumerate(self.history)))
  
      # encode each turn of the history
      propmt_tokens_lists = [
          self.tokenizer.encode(turn) for turn in prompts
      ]
  
      prompt_ids = propmt_tokens_lists[-self.history_window :]
      # concatenate every token into a single list
      # list(chain(*[[1, 2], [3, 4], [5]]))
      # >>> [1, 2, 3, 4, 5]
      prompt_ids = torch.LongTensor(list(chain(*prompt_ids)))
      # without bos for lm_labels
  
      # # create bos version for the input
      prompt_bos = torch.cat(
          (torch.tensor([self.tokenizer.bos_token_id]), prompt_ids)
      )
      return prompt_bos.unsqueeze(0).unsqueeze(dim=0)
  
imports: import torch
  from itertools import chain
  from speechbrain.inference.interfaces import Pretrained, EncodeDecodePipelineMixin
label_desc: Use image node_id 3 for calling the Llama2ResponseGenerator obj's underlying member method code with example usage: obj.prepare_input() and returns: prompt_bos, unknown, item