



import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TextaTextGenerationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from transformers.utils import is_torch_available

from .test_pipelines_common import ANY


if is_torch_available():
	import torch





@is_pipeline_test
class 					__lowerCAmelCase (     unittest.TestCase       ):
				__lowerCamelCase =				MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
				__lowerCamelCase =				TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING




				def 							snake_case   (							self						,				_snake_case						,				_snake_case						,				_snake_case		):



									"""simple docstring"""





									_lowerCAmelCase						=    TextaTextGenerationPipeline(model=_snake_case						,				tokenizer=_snake_case		)
									return generator, ["Something to write", "Something else"]




				def 							snake_case   (							self						,				_snake_case						,				_snake_case		):



									"""simple docstring"""





									_lowerCAmelCase						=    generator("""Something there"""		)
									self.assertEqual(_snake_case						,				[{"""generated_text""": ANY(_snake_case		)}]		)
									# These are encoder decoder, they don't just append to incoming string
									self.assertFalse(outputs[0]["""generated_text"""].startswith("""Something there"""		)		)

									_lowerCAmelCase						=    generator(["""This is great !""", """Something else"""]						,				num_return_sequences=2						,				do_sample=_snake_case		)
									self.assertEqual(
									    _snake_case						,				[
									        [{"""generated_text""": ANY(_snake_case		)}, {"""generated_text""": ANY(_snake_case		)}],
									        [{"""generated_text""": ANY(_snake_case		)}, {"""generated_text""": ANY(_snake_case		)}],
									    ]						,				)

									_lowerCAmelCase						=    generator(
									    ["""This is great !""", """Something else"""]						,				num_return_sequences=2						,				batch_size=2						,				do_sample=_snake_case		)
									self.assertEqual(
									    _snake_case						,				[
									        [{"""generated_text""": ANY(_snake_case		)}, {"""generated_text""": ANY(_snake_case		)}],
									        [{"""generated_text""": ANY(_snake_case		)}, {"""generated_text""": ANY(_snake_case		)}],
									    ]						,				)

									with self.assertRaises(_snake_case		):
														generator(4		)




				@require_torch
				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    pipeline("""text2text-generation"""						,				model="""patrickvonplaten/t5-tiny-random"""						,				framework="""pt"""		)
									# do_sample=False necessary for reproducibility
									_lowerCAmelCase						=    generator("""Something there"""						,				do_sample=_snake_case		)
									self.assertEqual(_snake_case						,				[{"""generated_text""": """"""}]		)

									_lowerCAmelCase						=    3
									_lowerCAmelCase						=    generator(
									    """Something there"""						,				num_return_sequences=_snake_case						,				num_beams=_snake_case						,				)
									_lowerCAmelCase						=    [
									    {"""generated_text""": """Beide Beide Beide Beide Beide Beide Beide Beide Beide"""},
									    {"""generated_text""": """Beide Beide Beide Beide Beide Beide Beide Beide"""},
									    {"""generated_text""": """"""},
									]
									self.assertEqual(_snake_case						,				_snake_case		)

									_lowerCAmelCase						=    generator("""This is a test"""						,				do_sample=_snake_case						,				num_return_sequences=2						,				return_tensors=_snake_case		)
									self.assertEqual(
									    _snake_case						,				[
									        {"""generated_token_ids""": ANY(torch.Tensor		)},
									        {"""generated_token_ids""": ANY(torch.Tensor		)},
									    ]						,				)
									_lowerCAmelCase						=    generator.model.config.eos_token_id
									_lowerCAmelCase						=    """<pad>"""
									_lowerCAmelCase						=    generator(
									    ["""This is a test""", """This is a second test"""]						,				do_sample=_snake_case						,				num_return_sequences=2						,				batch_size=2						,				return_tensors=_snake_case						,				)
									self.assertEqual(
									    _snake_case						,				[
									        [
									            {"""generated_token_ids""": ANY(torch.Tensor		)},
									            {"""generated_token_ids""": ANY(torch.Tensor		)},
									        ],
									        [
									            {"""generated_token_ids""": ANY(torch.Tensor		)},
									            {"""generated_token_ids""": ANY(torch.Tensor		)},
									        ],
									    ]						,				)




				@require_tf
				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    pipeline("""text2text-generation"""						,				model="""patrickvonplaten/t5-tiny-random"""						,				framework="""tf"""		)
									# do_sample=False necessary for reproducibility
									_lowerCAmelCase						=    generator("""Something there"""						,				do_sample=_snake_case		)
									self.assertEqual(_snake_case						,				[{"""generated_text""": """"""}]		)









def SCREAMING_SNAKE_CASE				(       lowercase_ ,				lowercase_						)   ->       int:



       """simple docstring"""

       return int(input_a == input_a == 0						)







def SCREAMING_SNAKE_CASE				(       )   ->       None:



       """simple docstring"""

       print('''Truth Table of NOR Gate:'''						)
       print('''|   Input 1   |  Input 2  | Output |'''						)
       print(f"""|      0      |    0      |  {nor_gate(0 ,				0						)}     |"""						)
       print(f"""|      0      |    1      |  {nor_gate(0 ,				1						)}     |"""						)
       print(f"""|      1      |    0      |  {nor_gate(1 ,				0						)}     |"""						)
       print(f"""|      1      |    1      |  {nor_gate(1 ,				1						)}     |"""						)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  main()


