


import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


lowerCamelCase						=		'''
Hugging 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.

In March 2021, Hugging Face raised $40 million in a Series B funding round.[3]

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.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]
'''





class  _a							(    unittest.TestCase					,						_lowercase):




	def 							UpperCAmelCase__( self						:		Any		)->	List[str]:
			lowerCAmelCase__       :      Union[str, Any]   					= load_tool('''text-question-answering'''		)
			self.tool.setup()
			lowerCAmelCase__       :      Any   					= load_tool('''text-question-answering'''		, remote=_SCREAMING_SNAKE_CASE		)




	def 							UpperCAmelCase__( self						:		str		)->	Dict:
			lowerCAmelCase__       :      Union[str, Any]   					= self.tool(_SCREAMING_SNAKE_CASE		, '''What did Hugging Face do in April 2021?'''		)
			self.assertEqual(_SCREAMING_SNAKE_CASE		, '''launched the BigScience Research Workshop'''		)




	def 							UpperCAmelCase__( self						:		str		)->	Optional[Any]:
			lowerCAmelCase__       :      Dict   					= self.remote_tool(_SCREAMING_SNAKE_CASE		, '''What did Hugging Face do in April 2021?'''		)
			self.assertEqual(_SCREAMING_SNAKE_CASE		, '''launched the BigScience Research Workshop'''		)




	def 							UpperCAmelCase__( self						:		Tuple		)->	List[str]:
			lowerCAmelCase__       :      Dict   					= self.tool(text=_SCREAMING_SNAKE_CASE		, question='''What did Hugging Face do in April 2021?'''		)
			self.assertEqual(_SCREAMING_SNAKE_CASE		, '''launched the BigScience Research Workshop'''		)




	def 							UpperCAmelCase__( self						:		Optional[int]		)->	str:
			lowerCAmelCase__       :      Optional[Any]   					= self.remote_tool(text=_SCREAMING_SNAKE_CASE		, question='''What did Hugging Face do in April 2021?'''		)
			self.assertEqual(_SCREAMING_SNAKE_CASE		, '''launched the BigScience Research Workshop'''		)








import timeit

import numpy as np

import datasets
from datasets.arrow_writer import ArrowWriter
from datasets.features.features import _ArrayXD






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		def wrapper(*_a     ,       **_a	):
				lowerCAmelCase__       :      List[str]   					= timeit.default_timer()
				lowerCAmelCase__       :      List[Any]   					= func(*_a     ,       **_a	)
				lowerCAmelCase__       :      Any   					= timeit.default_timer() - starttime
				return delta

		lowerCAmelCase__       :      Any   					= func.__name__

		return wrapper






def 					lowerCamelCase_   (	_a     ,       _a=100     ,       _a=None	):




		"""simple docstring"""






		lowerCAmelCase__       :      str   					= []
		lowerCAmelCase__       :      str   					= seq_shapes or {}
		for i in range(_a	):
				lowerCAmelCase__       :      List[str]   					= {}
				for col_id, (k, v) in enumerate(features.items()	):
						if isinstance(_a     ,       _ArrayXD	):
								lowerCAmelCase__       :      List[str]   					= np.random.rand(*v.shape	).astype(v.dtype	)
						elif isinstance(_a     ,       datasets.Value	):
								if v.dtype == "string":
										lowerCAmelCase__       :      Dict   					= '''The small grey turtle was surprisingly fast when challenged.'''
								else:
										lowerCAmelCase__       :      Any   					= np.random.randint(10     ,       size=1	).astype(v.dtype	).item()
						elif isinstance(_a     ,       datasets.Sequence	):
								while isinstance(_a     ,       datasets.Sequence	):
										lowerCAmelCase__       :      Optional[int]   					= v.feature
								lowerCAmelCase__       :      str   					= seq_shapes[k]
								lowerCAmelCase__       :      Any   					= np.random.rand(*_a	).astype(v.dtype	)
						lowerCAmelCase__       :      int   					= data

				dummy_data.append((i, example)	)

		return dummy_data






def 					lowerCamelCase_   (	_a     ,       _a     ,       _a=100     ,       _a=None	):




		"""simple docstring"""






		lowerCAmelCase__       :      Optional[Any]   					= generate_examples(_a     ,       num_examples=_a     ,       seq_shapes=_a	)

		with ArrowWriter(features=_a     ,       path=_a	) as writer:
				for key, record in dummy_data:
						lowerCAmelCase__       :      Optional[int]   					= features.encode_example(_a	)
						writer.write(_a	)

				lowerCAmelCase__					,     lowerCAmelCase__       :      List[str]   					= writer.finalize()

		if not num_final_examples == num_examples:
				raise ValueError(
				    f'Error writing the dataset, wrote {num_final_examples} examples but should have written {num_examples}.'	)

		lowerCAmelCase__       :      List[Any]   					= datasets.Dataset.from_file(filename=_a     ,       info=datasets.DatasetInfo(features=_a	)	)

		return dataset




