




from __future__ import annotations

import unittest

from transformers import OpenAIGPTConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
  import tensorflow as tf

  from transformers.models.openai.modeling_tf_openai import (
      TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFOpenAIGPTDoubleHeadsModel,
      TFOpenAIGPTForSequenceClassification,
      TFOpenAIGPTLMHeadModel,
      TFOpenAIGPTModel,
  )
class       _UpperCamelCase   :
      def __init__(      self :Optional[Any]			,   lowerCamelCase :int			,   )  ->      int:
       UpperCAmelCase__							=    parent
       UpperCAmelCase__							=    13
       UpperCAmelCase__							=    7
       UpperCAmelCase__							=    True
       UpperCAmelCase__							=    True
       UpperCAmelCase__							=    True
       UpperCAmelCase__							=    True
       UpperCAmelCase__							=    True
       UpperCAmelCase__							=    99
       UpperCAmelCase__							=    32
       UpperCAmelCase__							=    2
       UpperCAmelCase__							=    4
       UpperCAmelCase__							=    37
       UpperCAmelCase__							=    'gelu'
       UpperCAmelCase__							=    0.1
       UpperCAmelCase__							=    0.1
       UpperCAmelCase__							=    512
       UpperCAmelCase__							=    16
       UpperCAmelCase__							=    2
       UpperCAmelCase__							=    0.02
       UpperCAmelCase__							=    3
       UpperCAmelCase__							=    4
       UpperCAmelCase__							=    None
       UpperCAmelCase__							=    self.vocab_size - 1
      def 						UpperCAmelCase_    (      self :str   )  ->      Dict:
       UpperCAmelCase__							=    ids_tensor([self.batch_size, self.seq_length]			,   self.vocab_size   )

       UpperCAmelCase__							=    None
       if self.use_input_mask:
        UpperCAmelCase__							=    random_attention_mask([self.batch_size, self.seq_length]   )

       UpperCAmelCase__							=    None
       if self.use_token_type_ids:
        UpperCAmelCase__							=    ids_tensor([self.batch_size, self.seq_length]			,   self.type_vocab_size   )

       UpperCAmelCase__							=    None
       if self.use_mc_token_ids:
        UpperCAmelCase__							=    ids_tensor([self.batch_size, self.num_choices]			,   self.seq_length   )

       UpperCAmelCase__							=    None
       UpperCAmelCase__							=    None
       UpperCAmelCase__							=    None
       if self.use_labels:
        UpperCAmelCase__							=    ids_tensor([self.batch_size]			,   self.type_sequence_label_size   )
        UpperCAmelCase__							=    ids_tensor([self.batch_size, self.seq_length]			,   self.num_labels   )
        UpperCAmelCase__							=    ids_tensor([self.batch_size]			,   self.num_choices   )

       UpperCAmelCase__							=    OpenAIGPTConfig(
           vocab_size=self.vocab_size			,   n_embd=self.hidden_size			,   n_layer=self.num_hidden_layers			,   n_head=self.num_attention_heads			,   n_positions=self.max_position_embeddings			,   pad_token_id=self.pad_token_id			,   )

       UpperCAmelCase__							=    ids_tensor([self.num_hidden_layers, self.num_attention_heads]			,   2   )

       return (
           config,
           input_ids,
           input_mask,
           head_mask,
           token_type_ids,
           mc_token_ids,
           sequence_labels,
           token_labels,
           choice_labels,
       )
      def 						UpperCAmelCase_    (      self :List[str]			,   lowerCamelCase :str			,   lowerCamelCase :List[Any]			,   lowerCamelCase :Union[str, Any]			,   lowerCamelCase :int			,   lowerCamelCase :Tuple			,   *lowerCamelCase :Optional[int]   )  ->      Optional[int]:
       UpperCAmelCase__							=    TFOpenAIGPTModel(config=UpperCamelCase__   )
       UpperCAmelCase__							=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
       UpperCAmelCase__							=    model(UpperCamelCase__   )

       UpperCAmelCase__							=    [input_ids, input_mask]
       UpperCAmelCase__							=    model(UpperCamelCase__   )

       UpperCAmelCase__							=    model(UpperCamelCase__   )

       self.parent.assertEqual(result.last_hidden_state.shape			,   (self.batch_size, self.seq_length, self.hidden_size)   )
      def 						UpperCAmelCase_    (      self :Any			,   lowerCamelCase :List[Any]			,   lowerCamelCase :List[Any]			,   lowerCamelCase :Optional[int]			,   lowerCamelCase :str			,   lowerCamelCase :Dict			,   *lowerCamelCase :Tuple   )  ->      Any:
       UpperCAmelCase__							=    TFOpenAIGPTLMHeadModel(config=UpperCamelCase__   )
       UpperCAmelCase__							=    {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
       UpperCAmelCase__							=    model(UpperCamelCase__   )
       self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.seq_length, self.vocab_size)   )
      def 						UpperCAmelCase_    (      self :List[str]			,   lowerCamelCase :Optional[Any]			,   lowerCamelCase :Optional[int]			,   lowerCamelCase :List[Any]			,   lowerCamelCase :Union[str, Any]			,   lowerCamelCase :int			,   lowerCamelCase :Dict			,   *lowerCamelCase :Optional[int]   )  ->      Optional[int]:
       UpperCAmelCase__							=    TFOpenAIGPTDoubleHeadsModel(config=UpperCamelCase__   )

       UpperCAmelCase__							=    tf.tile(tf.expand_dims(UpperCamelCase__			,   1   )			,   (1, self.num_choices, 1)   )
       UpperCAmelCase__							=    tf.tile(tf.expand_dims(UpperCamelCase__			,   1   )			,   (1, self.num_choices, 1)   )
       UpperCAmelCase__							=    tf.tile(tf.expand_dims(UpperCamelCase__			,   1   )			,   (1, self.num_choices, 1)   )

       UpperCAmelCase__							=    {
           'input_ids': multiple_choice_inputs_ids,
           'mc_token_ids': mc_token_ids,
           'attention_mask': multiple_choice_input_mask,
           'token_type_ids': multiple_choice_token_type_ids,
       }
       UpperCAmelCase__							=    model(UpperCamelCase__   )
       self.parent.assertEqual(
           result.logits.shape			,   (self.batch_size, self.num_choices, self.seq_length, self.vocab_size)   )
       self.parent.assertEqual(result.mc_logits.shape			,   (self.batch_size, self.num_choices)   )
      def 						UpperCAmelCase_    (      self :Tuple			,   lowerCamelCase :Tuple			,   lowerCamelCase :Tuple			,   lowerCamelCase :Union[str, Any]			,   lowerCamelCase :Optional[Any]			,   lowerCamelCase :Optional[int]			,   *lowerCamelCase :List[Any]   )  ->      str:
       UpperCAmelCase__							=    self.num_labels
       UpperCAmelCase__							=    ids_tensor([self.batch_size]			,   self.type_sequence_label_size   )
       UpperCAmelCase__							=    {
           'input_ids': input_ids,
           'attention_mask': input_mask,
           'token_type_ids': token_type_ids,
           'labels': sequence_labels,
       }
       UpperCAmelCase__							=    TFOpenAIGPTForSequenceClassification(UpperCamelCase__   )
       UpperCAmelCase__							=    model(UpperCamelCase__   )
       self.parent.assertEqual(result.logits.shape			,   (self.batch_size, self.num_labels)   )







      def 						UpperCAmelCase_    (      self :Dict   )  ->      str:
       UpperCAmelCase__							=    self.prepare_config_and_inputs()

       (
           UpperCAmelCase__							
       )							=    config_and_inputs

       UpperCAmelCase__							=    {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
       return config, inputs_dict



@require_tf
class       _UpperCamelCase   (					__A						,							__A						,							unittest.TestCase		):
      UpperCAmelCase_          =		(
          (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification)
          if is_tf_available()
          else ()
      )
      UpperCAmelCase_          =		(
          (TFOpenAIGPTLMHeadModel,) if is_tf_available() else ()
      )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
      UpperCAmelCase_          =		(
          {
              """feature-extraction""": TFOpenAIGPTModel,
              """text-classification""": TFOpenAIGPTForSequenceClassification,
              """text-generation""": TFOpenAIGPTLMHeadModel,
              """zero-shot""": TFOpenAIGPTForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      UpperCAmelCase_          =		False
      UpperCAmelCase_          =		False
      def 						UpperCAmelCase_    (      self :Optional[Any]			,   lowerCamelCase :Any			,   lowerCamelCase :str			,   lowerCamelCase :Union[str, Any]			,   lowerCamelCase :int			,   lowerCamelCase :List[str]   )  ->      Dict:
       if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
        # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
        # `OpenAIGPTConfig` was never used in pipeline tests, either because of a missing checkpoint or because a
        # tiny config could not be created.
        return True

       return False
      def 						UpperCAmelCase_    (      self :List[Any]   )  ->      List[str]:
       UpperCAmelCase__							=    TFOpenAIGPTModelTester(self   )
       UpperCAmelCase__							=    ConfigTester(self			,   config_class=UpperCamelCase__			,   n_embd=37   )
      def 						UpperCAmelCase_    (      self :List[Any]   )  ->      Any:
       self.config_tester.run_common_tests()
      def 						UpperCAmelCase_    (      self :Tuple   )  ->      Any:
       UpperCAmelCase__							=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_model(*UpperCamelCase__   )
      def 						UpperCAmelCase_    (      self :List[str]   )  ->      Dict:
       UpperCAmelCase__							=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_lm_head(*UpperCamelCase__   )
      def 						UpperCAmelCase_    (      self :Dict   )  ->      Dict:
       UpperCAmelCase__							=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_double_head(*UpperCamelCase__   )
      def 						UpperCAmelCase_    (      self :Tuple   )  ->      List[Any]:
       UpperCAmelCase__							=    self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*UpperCamelCase__   )







      @slow
      def 						UpperCAmelCase_    (      self :Any   )  ->      Optional[Any]:
       for model_name in TF_OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        UpperCAmelCase__							=    TFOpenAIGPTModel.from_pretrained(UpperCamelCase__   )
        self.assertIsNotNone(UpperCamelCase__   )



@require_tf
class       _UpperCamelCase   (					unittest.TestCase		):
      @slow
      def 						UpperCAmelCase_    (      self :List[str]   )  ->      Any:
       UpperCAmelCase__							=    TFOpenAIGPTLMHeadModel.from_pretrained("openai-gpt"   )
       UpperCAmelCase__							=    tf.convert_to_tensor([[481, 4735, 544]]			,   dtype=tf.intaa   )  # the president is
       UpperCAmelCase__							=    [
           481,
           4735,
           544,
           246,
           963,
           870,
           762,
           239,
           244,
           4_0477,
           244,
           249,
           719,
           881,
           487,
           544,
           240,
           244,
           603,
           481,
       ]  # the president is a very good man. " \n " i\'m sure he is, " said the

       UpperCAmelCase__							=    model.generate(UpperCamelCase__			,   do_sample=UpperCamelCase__   )
       self.assertListEqual(output_ids[0].numpy().tolist()			,   UpperCamelCase__   )













import os
from shutil import copyfile
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


if TYPE_CHECKING:
				from transformers.pipelines.conversational import Conversation

A										=      logging.get_logger(__name__)

A										=      {'vocab_file': 'tokenizer.model'}

A										=      {
    'vocab_file': {
        'hf-internal-testing/llama-tokenizer': 'https://huggingface.co/hf-internal-testing/llama-tokenizer/resolve/main/tokenizer.model',
    },
    'tokenizer_file': {
        'hf-internal-testing/llama-tokenizer': 'https://huggingface.co/hf-internal-testing/llama-tokenizer/resolve/main/tokenizer_config.json',
    },
}
A										=      {
    'hf-internal-testing/llama-tokenizer': 2048,
}
A										=      '▁'

A			,	A										=      '[INST]', '[/INST]'
A			,	A										=      '<<SYS>>\n', '\n<</SYS>>\n\n'

# fmt: off
A										=      'You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your\\nanswers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure\\nthat your responses are socially unbiased and positive in nature.\n\nIf a question does not make any sense, or is not factually coherent, explain why instead of answering something not\\ncorrect. If you don\'t know the answer to a question, please don\'t share false information.'


class 				__a				(	__A    ):





		'''simple docstring'''



		UpperCAmelCase__   :					Optional[int]					     =    VOCAB_FILES_NAMES
		UpperCAmelCase__   :					Dict					     =    PRETRAINED_VOCAB_FILES_MAP
		UpperCAmelCase__   :					int					     =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
		UpperCAmelCase__   :					Union[str, Any]					     =    ["""input_ids""", """attention_mask"""]


		def __init__(    self			,     UpperCamelCase__			,     UpperCamelCase__="<unk>"			,     UpperCamelCase__="<s>"			,     UpperCamelCase__="</s>"			,     UpperCamelCase__=None			,     UpperCamelCase__ = None			,     UpperCamelCase__=True			,     UpperCamelCase__=False			,     UpperCamelCase__=False			,     UpperCamelCase__=True			,     **UpperCamelCase__			,     ):
						SCREAMING_SNAKE_CASE_ :						str    				= {} if sp_model_kwargs is None else sp_model_kwargs
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= AddedToken(UpperCamelCase__			,     lstrip=UpperCamelCase__			,     rstrip=UpperCamelCase__							) if isinstance(UpperCamelCase__			,     UpperCamelCase__							) else bos_token
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= AddedToken(UpperCamelCase__			,     lstrip=UpperCamelCase__			,     rstrip=UpperCamelCase__							) if isinstance(UpperCamelCase__			,     UpperCamelCase__							) else eos_token
						SCREAMING_SNAKE_CASE_ :						str    				= AddedToken(UpperCamelCase__			,     lstrip=UpperCamelCase__			,     rstrip=UpperCamelCase__							) if isinstance(UpperCamelCase__			,     UpperCamelCase__							) else unk_token
						SCREAMING_SNAKE_CASE_ :						int    				= AddedToken(UpperCamelCase__			,     lstrip=UpperCamelCase__			,     rstrip=UpperCamelCase__							) if isinstance(UpperCamelCase__			,     UpperCamelCase__							) else pad_token
						super().__init__(
						    bos_token=UpperCamelCase__			,     eos_token=UpperCamelCase__			,     unk_token=UpperCamelCase__			,     pad_token=UpperCamelCase__			,     add_bos_token=UpperCamelCase__			,     add_eos_token=UpperCamelCase__			,     sp_model_kwargs=self.sp_model_kwargs			,     clean_up_tokenization_spaces=UpperCamelCase__			,     legacy=UpperCamelCase__			,     **UpperCamelCase__			,     )
						if legacy:
										logger.warning_once(
										    F'''You are using the legacy behaviour of the {self.__class__}. This means that tokens that come after special tokens will not be properly handled. We recommend you to'''
										    ' read the related pull request available at https://github.com/huggingface/transformers/pull/24565'							)
						SCREAMING_SNAKE_CASE_ :						List[Any]    				= legacy
						SCREAMING_SNAKE_CASE_ :						Dict    				= vocab_file
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= add_bos_token
						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= add_eos_token
						SCREAMING_SNAKE_CASE_ :						Any    				= spm.SentencePieceProcessor(**self.sp_model_kwargs							)
						self.sp_model.Load(UpperCamelCase__							)


		def __getstate__(    self							):
						SCREAMING_SNAKE_CASE_ :						List[str]    				= self.__dict__.copy()
						SCREAMING_SNAKE_CASE_ :						List[Any]    				= None
						SCREAMING_SNAKE_CASE_ :						Any    				= self.sp_model.serialized_model_proto()
						return state


		def __setstate__(    self			,     UpperCamelCase__							):
						SCREAMING_SNAKE_CASE_ :						str    				= d
						SCREAMING_SNAKE_CASE_ :						str    				= spm.SentencePieceProcessor(**self.sp_model_kwargs							)
						self.sp_model.LoadFromSerializedProto(self.sp_model_proto							)


		@property
		def 	__snake_case      (    self							):
						return self.sp_model.get_piece_size()


		def 	__snake_case      (    self							):
						SCREAMING_SNAKE_CASE_ :						Tuple    				= {self.convert_ids_to_tokens(UpperCamelCase__							): i for i in range(self.vocab_size							)}
						vocab.update(self.added_tokens_encoder							)
						return vocab


		def 	__snake_case      (    self			,     UpperCamelCase__			,     **UpperCamelCase__							):
						# Replace the SPIECE_UNDERLINE with a space to make sure SPIECE_UNDERLINE is only used at
						# the beginning of the text
						if not self.legacy:
										SCREAMING_SNAKE_CASE_ :						List[str]    				= SPIECE_UNDERLINE + text.replace(UpperCamelCase__			,     ' '							)
						return super().tokenize(UpperCamelCase__			,     **UpperCamelCase__							)


		def 	__snake_case      (    self			,     UpperCamelCase__							):
						if not self.legacy:
										SCREAMING_SNAKE_CASE_ :						Any    				= text.startswith(UpperCamelCase__							)
										if is_first:
														SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= text[1:]

						SCREAMING_SNAKE_CASE_ :						Tuple    				= self.sp_model.encode(UpperCamelCase__			,     out_type=UpperCamelCase__							)

						if not self.legacy and not is_first and not text.startswith(' '							) and tokens[0].startswith(UpperCamelCase__							):
										SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= ([tokens[0][1:]] if len(tokens[0]							) > 1 else []) + tokens[1:]
						return tokens


		def 	__snake_case      (    self			,     UpperCamelCase__							):
						return self.sp_model.piece_to_id(UpperCamelCase__							)


		def 	__snake_case      (    self			,     UpperCamelCase__							):
						SCREAMING_SNAKE_CASE_ :						Optional[int]    				= self.sp_model.IdToPiece(UpperCamelCase__							)
						return token


		def 	__snake_case      (    self			,     UpperCamelCase__							):
						SCREAMING_SNAKE_CASE_ :						List[str]    				= []
						SCREAMING_SNAKE_CASE_ :						int    				= ''
						SCREAMING_SNAKE_CASE_ :						List[str]    				= False
						for i, token in enumerate(UpperCamelCase__							):
										# make sure that special tokens are not decoded using sentencepiece model
										if token in self.all_special_tokens:
														if not prev_is_special and i != 0:
																		out_string += " "
														out_string += self.sp_model.decode(UpperCamelCase__							) + token
														SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= True
														SCREAMING_SNAKE_CASE_ :						str    				= []
										else:
														current_sub_tokens.append(UpperCamelCase__							)
														SCREAMING_SNAKE_CASE_ :						int    				= False
						out_string += self.sp_model.decode(UpperCamelCase__							)
						return out_string


		def 	__snake_case      (    self			,     UpperCamelCase__			,     UpperCamelCase__ = None							):
						if not os.path.isdir(UpperCamelCase__							):
										logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''							)
										return
						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= os.path.join(
						    UpperCamelCase__			,     (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']							)

						if os.path.abspath(self.vocab_file							) != os.path.abspath(UpperCamelCase__							) and os.path.isfile(self.vocab_file							):
										copyfile(self.vocab_file			,     UpperCamelCase__							)
						elif not os.path.isfile(self.vocab_file							):
										with open(UpperCamelCase__			,     'wb'							) as fi:
														SCREAMING_SNAKE_CASE_ :						Dict    				= self.sp_model.serialized_model_proto()
														fi.write(UpperCamelCase__							)

						return (out_vocab_file,)


		def 	__snake_case      (    self			,     UpperCamelCase__			,     UpperCamelCase__=None							):
						SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= [self.bos_token_id] if self.add_bos_token else []
						SCREAMING_SNAKE_CASE_ :						List[str]    				= [self.eos_token_id] if self.add_eos_token else []

						SCREAMING_SNAKE_CASE_ :						int    				= bos_token_id + token_ids_a + eos_token_id

						if token_ids_a is not None:
										SCREAMING_SNAKE_CASE_ :						int    				= output + bos_token_id + token_ids_a + eos_token_id

						return output


		def 	__snake_case      (    self			,     UpperCamelCase__			,     UpperCamelCase__ = None			,     UpperCamelCase__ = False							):
						if already_has_special_tokens:
										return super().get_special_tokens_mask(
										    token_ids_a=UpperCamelCase__			,     token_ids_a=UpperCamelCase__			,     already_has_special_tokens=UpperCamelCase__							)

						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= [1] if self.add_bos_token else []
						SCREAMING_SNAKE_CASE_ :						Union[str, Any]    				= [1] if self.add_eos_token else []

						if token_ids_a is None:
										return bos_token_id + ([0] * len(UpperCamelCase__							)) + eos_token_id
						return (
						    bos_token_id
						    + ([0] * len(UpperCamelCase__							))
						    + eos_token_id
						    + bos_token_id
						    + ([0] * len(UpperCamelCase__							))
						    + eos_token_id
						)


		def 	__snake_case      (    self			,     UpperCamelCase__			,     UpperCamelCase__ = None							):
						SCREAMING_SNAKE_CASE_ :						Any    				= [self.bos_token_id] if self.add_bos_token else []
						SCREAMING_SNAKE_CASE_ :						Tuple    				= [self.eos_token_id] if self.add_eos_token else []

						SCREAMING_SNAKE_CASE_ :						Any    				= [0] * len(bos_token_id + token_ids_a + eos_token_id							)

						if token_ids_a is not None:
										output += [1] * len(bos_token_id + token_ids_a + eos_token_id							)

						return output






		def 	__snake_case      (    self			,     UpperCamelCase__							):
						SCREAMING_SNAKE_CASE_ :						int    				= list(conversation.iter_texts()							)
						if not all([is_user for is_user, msg in dialogue[::2]]							) or not all(
						    [not is_user for is_user, msg in dialogue[1::2]]							):
										raise ValueError(
										    'The model only supports \'user\' and \'assistant\' roles, starting with user and alternating (u/a/u/a/u...)'							)

						SCREAMING_SNAKE_CASE_ :						List[int]    				= []
						if len(conversation.past_user_inputs							) > 0:
										if not conversation.past_user_inputs[0].startswith(UpperCamelCase__							) or E_SYS not in conversation.past_user_inputs[0]:
														SCREAMING_SNAKE_CASE_ :						Optional[Any]    				= (
														    B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS + conversation.past_user_inputs[0]
														)
						elif not dialogue[0][1].startswith(UpperCamelCase__							) or E_SYS not in dialogue[0][1]:
										SCREAMING_SNAKE_CASE_ :						Tuple    				= (dialogue[0][0], B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS + dialogue[0][1])

						dialog_tokens += sum(
						    [
						        [self.bos_token_id]
						        + self.encode(
						            F'''{B_INST} {(prompt[1]).strip()} {E_INST} {(answer[1]).strip()} '''			,     add_special_tokens=UpperCamelCase__							)
						        + [self.eos_token_id]
						        for prompt, answer in zip(dialogue[::2]			,     dialogue[1::2]							)
						    ]			,     []			,     )
						if not (dialogue[-1][0]):
										raise ValueError(F'''Last message must be from user, got {dialogue[-1]['role']}'''							)
						dialog_tokens += [self.bos_token_id] + self.encode(
						    F'''{B_INST} {(dialogue[-1][1]).strip()} {E_INST}'''			,     add_special_tokens=UpperCamelCase__							)
						return dialog_tokens