
'''simple docstring'''



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    _a				(unittest.TestCase):





       """simple docstring"""




       SCREAMING_SNAKE_CASE      =  MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
       SCREAMING_SNAKE_CASE      =  TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING






       def        UpperCamelCase				(							self       ,							A__       ,							A__       ,							A__      )    ->			Optional[Any]:
          _SCREAMING_SNAKE_CASE      =				TextaTextGenerationPipeline(model=A__       ,							tokenizer=A__      )
          return generator, ["Something to write", "Something else"]






       def        UpperCamelCase				(							self       ,							A__       ,							A__      )    ->			Optional[int]:
          _SCREAMING_SNAKE_CASE      =				generator("""Something there"""      )
          self.assertEqual(A__       ,							[{"""generated_text""": ANY(A__      )}]      )
          # These are encoder decoder, they don't just append to incoming string
          self.assertFalse(outputs[0]["""generated_text"""].startswith("""Something there"""      )      )

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

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

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






       @require_torch
       def        UpperCamelCase				(							self      )    ->			Optional[int]:
          _SCREAMING_SNAKE_CASE      =				pipeline("""text2text-generation"""       ,							model="""patrickvonplaten/t5-tiny-random"""       ,							framework="""pt"""      )
          # do_sample=False necessary for reproducibility
          _SCREAMING_SNAKE_CASE      =				generator("""Something there"""       ,							do_sample=A__      )
          self.assertEqual(A__       ,							[{"""generated_text""": """"""}]      )

          _SCREAMING_SNAKE_CASE      =				3
          _SCREAMING_SNAKE_CASE      =				generator(
              """Something there"""       ,							num_return_sequences=A__       ,							num_beams=A__       ,							)
          _SCREAMING_SNAKE_CASE      =				[
              {"""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(A__       ,							A__      )

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








'''simple docstring'''



import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline
@pytest.mark.integration
def    lowerCAmelCase_	(				)     ->     List[Any]:




   """simple docstring"""
   with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT						):
      with pytest.raises(SCREAMING_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    lowerCAmelCase_	(				)     ->     int:




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







def    lowerCAmelCase_	(				)     ->     Optional[Any]:




   """simple docstring"""
   with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1						):
      with pytest.raises(SCREAMING_SNAKE_CASE_						):
         http_head("""https://huggingface.co"""						)






