






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			):
				a__       							=	MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
				a__       							=	TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:Dict   =   TextaTextGenerationPipeline(model=__lowerCAmelCase							,       tokenizer=__lowerCAmelCase  )
								return generator, ["Something to write", "Something else"]







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:List[Any]   =   generator('''Something there'''  )
								self.assertEqual(__lowerCAmelCase							,       [{'''generated_text''': ANY(__lowerCAmelCase  )}]  )
								# These are encoder decoder, they don't just append to incoming string
								self.assertFalse(outputs[0]['''generated_text'''].startswith('''Something there'''  )  )

								__magic_name__		:Union[str, Any]   =   generator(['''This is great !''', '''Something else''']							,       num_return_sequences=2							,       do_sample=__lowerCAmelCase  )
								self.assertEqual(
								    __lowerCAmelCase							,       [
								        [{'''generated_text''': ANY(__lowerCAmelCase  )}, {'''generated_text''': ANY(__lowerCAmelCase  )}],
								        [{'''generated_text''': ANY(__lowerCAmelCase  )}, {'''generated_text''': ANY(__lowerCAmelCase  )}],
								    ]							,       )

								__magic_name__		:List[str]   =   generator(
								    ['''This is great !''', '''Something else''']							,       num_return_sequences=2							,       batch_size=2							,       do_sample=__lowerCAmelCase  )
								self.assertEqual(
								    __lowerCAmelCase							,       [
								        [{'''generated_text''': ANY(__lowerCAmelCase  )}, {'''generated_text''': ANY(__lowerCAmelCase  )}],
								        [{'''generated_text''': ANY(__lowerCAmelCase  )}, {'''generated_text''': ANY(__lowerCAmelCase  )}],
								    ]							,       )

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







				@require_torch
				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Optional[int]   =   pipeline('''text2text-generation'''							,       model='''patrickvonplaten/t5-tiny-random'''							,       framework='''pt'''  )
								# do_sample=False necessary for reproducibility
								__magic_name__		:Any   =   generator('''Something there'''							,       do_sample=__lowerCAmelCase  )
								self.assertEqual(__lowerCAmelCase							,       [{'''generated_text''': ''''''}]  )

								__magic_name__		:str   =   3
								__magic_name__		:Optional[Any]   =   generator(
								    '''Something there'''							,       num_return_sequences=__lowerCAmelCase							,       num_beams=__lowerCAmelCase							,       )
								__magic_name__		:str   =   [
								    {'''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(__lowerCAmelCase							,       __lowerCAmelCase  )

								__magic_name__		:int   =   generator('''This is a test'''							,       do_sample=__lowerCAmelCase							,       num_return_sequences=2							,       return_tensors=__lowerCAmelCase  )
								self.assertEqual(
								    __lowerCAmelCase							,       [
								        {'''generated_token_ids''': ANY(torch.Tensor  )},
								        {'''generated_token_ids''': ANY(torch.Tensor  )},
								    ]							,       )
								__magic_name__		:str   =   generator.model.config.eos_token_id
								__magic_name__		:Dict   =   '''<pad>'''
								__magic_name__		:List[str]   =   generator(
								    ['''This is a test''', '''This is a second test''']							,       do_sample=__lowerCAmelCase							,       num_return_sequences=2							,       batch_size=2							,       return_tensors=__lowerCAmelCase							,       )
								self.assertEqual(
								    __lowerCAmelCase							,       [
								        [
								            {'''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       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Any   =   pipeline('''text2text-generation'''							,       model='''patrickvonplaten/t5-tiny-random'''							,       framework='''tf'''  )
								# do_sample=False necessary for reproducibility
								__magic_name__		:Union[str, Any]   =   generator('''Something there'''							,       do_sample=__lowerCAmelCase  )
								self.assertEqual(__lowerCAmelCase							,       [{'''generated_text''': ''''''}]  )














import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline

@pytest.mark.integration
def   __lowercase       (			):







				"""simple docstring"""






				with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT			):
								with pytest.raises(snake_case			):
												requests.request('''GET''',	'''https://huggingface.co'''			)
								with pytest.raises(requests.exceptions.ConnectTimeout			):
												requests.request('''GET''',	'''https://huggingface.co''',	timeout=1.0			)

@pytest.mark.integration
def   __lowercase       (			):







				"""simple docstring"""






				with offline(OfflineSimulationMode.CONNECTION_FAILS			):
								with pytest.raises(requests.exceptions.ConnectionError			):
												requests.request('''GET''',	'''https://huggingface.co'''			)

def   __lowercase       (			):







				"""simple docstring"""






				with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1			):
								with pytest.raises(snake_case			):
												http_head('''https://huggingface.co'''			)






