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 GPT model with added tokens like bos,eos, and speaker's tokens.
  
  Example
  -------
  >>> from speechbrain.inference.text import GPTResponseGenerator
  
  >>> tmpdir = getfixture("tmpdir")
  >>> res_gen_model = GPTResponseGenerator.from_hparams(source="speechbrain/MultiWOZ-GPT-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  GPT model.
      It appends all previous history and input and truncates it based on max_history value.
      It then tokenizes the input and generates additional input that determines the type of each token (Sytem or User).
  
  Arguments
  ---------
  
  Returns
  -------
  history_bos:
      Tokenized history+input values with appropriate speaker token appended before each turn.
  history_token_type:
      Type of each token basd on who is uttered that token (either User or Sytem)
docstr_tok: ["Convert","user","input","and","previous","histories","to","the","format","acceptable","for","GPT","model",".","It","appends","all","previous","history","and","input","and","truncates","it","based","on","max_history","value",".","It","then","tokenizes","the","input","and","generates","additional","input","that","determines","the","type","of","each","token","(","Sytem","or","User",")",".","Arguments","--","--","--","--","-","Returns","--","--","--","-","history_bos",":","Tokenized","history+input","values","with","appropriate","speaker","token","appended","before","each","turn",".","history_token_type",":","Type","of","each","token","basd","on","who","is","uttered","that","token","(","either","User","or","Sytem",")"]
code: def prepare_input(self):
      """Convert user input and previous histories to the format acceptable for  GPT model.
          It appends all previous history and input and truncates it based on max_history value.
          It then tokenizes the input and generates additional input that determines the type of each token (Sytem or User).
  
      Arguments
      ---------
  
      Returns
      -------
      history_bos:
          Tokenized history+input values with appropriate speaker token appended before each turn.
      history_token_type:
          Type of each token basd on who is uttered that token (either User or Sytem)
      """
      history_tokens_lists = [
          self.model.tokenizer.encode(turn) for turn in self.history
      ]
      # add speaker tokens to the history turns (user is even, system is odd)
      # BEFORE:  [Hi how are you?], [I'm fine, thanks]
      # AFTER:   [SPK_1 Hi how are you?], [SPK_2 I'm fine, thanks]
      history_input_lists = [
          [self.user if i % 2 == 0 else self.system] + encoded_turn
          for i, encoded_turn in enumerate(history_tokens_lists)
      ]
      history_ids = history_input_lists[-self.history_window :]
      # concatenate every token into a single list
      # list(chain(*[[1, 2], [3, 4], [5]]))
      # >>> [1, 2, 3, 4, 5]
      history_ids = torch.LongTensor(list(chain(*history_ids)))
      # create bos version for the input
      history_bos = torch.cat(
          (
              torch.tensor([self.bos]),
              history_ids,
              torch.tensor([self.system]),
          )
      )
      # create a mapping that associates each token in the input to a speaker
      # INPUT: [SPK_1 Hi    how   are   you? ], [SPK_2 I'm   fine, thanks]
      # TYPE:  [SPK_1 SPK_1 SPK_1 SPK_1 SPK_1], [SPK_2 SPK_2 SPK_2 SPK_2 ]
      history_token_type_lists = [
          [self.user if i % 2 == 0 else self.system] * len(encoded_turn)
          for i, encoded_turn in enumerate(history_input_lists)
      ]
      history_token_type = torch.LongTensor(
          list(
              chain(
                  *(
                      [[self.system]]
                      + history_token_type_lists[-self.history_window :]
                      + [[self.system]]
                  )
              )
          )
      )
      return history_bos.unsqueeze(0), history_token_type.unsqueeze(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 GPTResponseGenerator obj's underlying member method code with example usage: obj.prepare_input() and returns: history_bos,  history_token_type