




import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


a_										=       "\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n"

class 	_lowerCamelCase  (     unittest.TestCase							,     _SCREAMING_SNAKE_CASE				):

      """simple docstring"""

      def  snake_case		(       self   :	Tuple			):
          __UpperCamelCase											=  load_tool('''summarization'''			)
          self.tool.setup()
          __UpperCamelCase											=  load_tool('''summarization'''	,    remote=snake_case			)







      def  snake_case		(       self   :	Union[str, Any]			):
          __UpperCamelCase											=  self.tool(snake_case			)
          self.assertEqual(
              snake_case	,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''	,    )







      def  snake_case		(       self   :	Optional[Any]			):
          __UpperCamelCase											=  self.remote_tool(snake_case			)
          self.assertEqual(
              snake_case	,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''	,    )







      def  snake_case		(       self   :	Dict			):
          __UpperCamelCase											=  self.tool(text=snake_case			)
          self.assertEqual(
              snake_case	,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''	,    )







      def  snake_case		(       self   :	Tuple			):
          __UpperCamelCase											=  self.remote_tool(text=snake_case			)
          self.assertEqual(
              snake_case	,    '''Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'''	,    )












# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..models.auto import AutoModelForSeqaSeqLM, AutoTokenizer
from .base import PipelineTool


a_										=       "Here is a text containing a lot of information: '''{text}'''.\n\nCan you answer this question about the text: '{question}'"

class 	_lowerCamelCase  (     _SCREAMING_SNAKE_CASE				):

      """simple docstring"""

      lowerCAmelCase__     :	Union[str, Any]      =   "google/flan-t5-base"
      lowerCAmelCase__     :	Union[str, Any]      =   (
          "This is a tool that answers questions related to a text. It takes two arguments named `text`, which is the "
          "text where to find the answer, and `question`, which is the question, and returns the answer to the question."
      )
      lowerCAmelCase__     :	List[Any]      =   "text_qa"
      lowerCAmelCase__     :	int      =   AutoTokenizer
      lowerCAmelCase__     :	Optional[Any]      =   AutoModelForSeqaSeqLM

      lowerCAmelCase__     :	Tuple      =   ["text", "text"]
      lowerCAmelCase__     :	Any      =   ["text"]







      def  snake_case		(       self   :	Union[str, Any]	,    snake_case   :	str	,    snake_case   :	str			):
          __UpperCamelCase											=  QA_PROMPT.format(text=snake_case	,    question=snake_case			)
          return self.pre_processor(snake_case	,    return_tensors='''pt'''			)







      def  snake_case		(       self   :	Any	,    snake_case   :	Optional[int]			):
          __UpperCamelCase											=  self.model.generate(**snake_case			)

          __UpperCamelCase						, __UpperCamelCase											=  inputs['''input_ids'''].shape
          __UpperCamelCase											=  output_ids.shape[0]

          return output_ids.reshape(snake_case	,    out_b // in_b	,    *output_ids.shape[1:]			)[0][0]







      def  snake_case		(       self   :	Tuple	,    snake_case   :	Optional[Any]			):
          return self.pre_processor.decode(snake_case	,    skip_special_tokens=snake_case	,    clean_up_tokenization_spaces=snake_case			)






