code: 
  
  
  import shutil
  import tempfile
  import unittest
  
  import pytest
  
  from transformers import WhisperTokenizer, is_speech_available
  from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio
  
  from .test_feature_extraction_whisper import floats_list
  
  
  if is_speech_available():
  		from transformers import WhisperFeatureExtractor, WhisperProcessor
  
  
  A_														=      5_0_3_5_8
  A_														=      5_0_3_6_2
  
  @require_torch
  @require_torchaudio
  @require_sentencepiece
  class 						snake_case			(       unittest.TestCase	):
  			'''simple docstring'''
  
  			def _lowercase (	self     :     Optional[Any]					)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       '''openai/whisper-small.en'''
  								SCREAMING_SNAKE_CASE_	      =       tempfile.mkdtemp()
  
  			def _lowercase (	self     :     Tuple							,							**lowerCAmelCase_     :     List[str]					)					->					Any:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								return WhisperTokenizer.from_pretrained(self.checkpoint							,							**lowerCAmelCase_					)
  
  			def _lowercase (	self     :     int							,							**lowerCAmelCase_     :     int					)					->					Any:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								return WhisperFeatureExtractor.from_pretrained(self.checkpoint							,							**lowerCAmelCase_					)
  
  			def _lowercase (	self     :     int					)					->					Any:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								shutil.rmtree(self.tmpdirname					)
  
  			def _lowercase (	self     :     Dict					)					->					Any:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.get_tokenizer()
  								SCREAMING_SNAKE_CASE_	      =       self.get_feature_extractor()
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=lowerCAmelCase_							,							feature_extractor=lowerCAmelCase_					)
  
  								processor.save_pretrained(self.tmpdirname					)
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor.from_pretrained(self.tmpdirname					)
  
  								self.assertEqual(processor.tokenizer.get_vocab()							,							tokenizer.get_vocab()					)
  								self.assertIsInstance(processor.tokenizer							,							lowerCAmelCase_					)
  
  								self.assertEqual(processor.feature_extractor.to_json_string()							,							feature_extractor.to_json_string()					)
  								self.assertIsInstance(processor.feature_extractor							,							lowerCAmelCase_					)
  
  			def _lowercase (	self     :     Dict					)					->					List[str]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=self.get_tokenizer()							,							feature_extractor=self.get_feature_extractor()					)
  								processor.save_pretrained(self.tmpdirname					)
  
  								SCREAMING_SNAKE_CASE_	      =       self.get_tokenizer(bos_token='''(BOS)'''							,							eos_token='''(EOS)'''					)
  								SCREAMING_SNAKE_CASE_	      =       self.get_feature_extractor(do_normalize=lowerCAmelCase_							,							padding_value=1.0					)
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor.from_pretrained(
  								    self.tmpdirname							,							bos_token='''(BOS)'''							,							eos_token='''(EOS)'''							,							do_normalize=lowerCAmelCase_							,							padding_value=1.0					)
  
  								self.assertEqual(processor.tokenizer.get_vocab()							,							tokenizer_add_kwargs.get_vocab()					)
  								self.assertIsInstance(processor.tokenizer							,							lowerCAmelCase_					)
  
  								self.assertEqual(processor.feature_extractor.to_json_string()							,							feature_extractor_add_kwargs.to_json_string()					)
  								self.assertIsInstance(processor.feature_extractor							,							lowerCAmelCase_					)
  
  			def _lowercase (	self     :     int					)					->					Union[str, Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.get_feature_extractor()
  								SCREAMING_SNAKE_CASE_	      =       self.get_tokenizer()
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=lowerCAmelCase_							,							feature_extractor=lowerCAmelCase_					)
  
  								SCREAMING_SNAKE_CASE_	      =       floats_list((3, 1_000)					)
  
  								SCREAMING_SNAKE_CASE_	      =       feature_extractor(lowerCAmelCase_							,							return_tensors='''np'''					)
  								SCREAMING_SNAKE_CASE_	      =       processor(lowerCAmelCase_							,							return_tensors='''np'''					)
  
  								for key in input_feat_extract.keys():
  													self.assertAlmostEqual(input_feat_extract[key].sum()							,							input_processor[key].sum()							,							delta=1e-2					)
  
  			def _lowercase (	self     :     Any					)					->					Union[str, Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.get_feature_extractor()
  								SCREAMING_SNAKE_CASE_	      =       self.get_tokenizer()
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=lowerCAmelCase_							,							feature_extractor=lowerCAmelCase_					)
  
  								SCREAMING_SNAKE_CASE_	      =       '''This is a test string'''
  
  								SCREAMING_SNAKE_CASE_	      =       processor(text=lowerCAmelCase_					)
  
  								SCREAMING_SNAKE_CASE_	      =       tokenizer(lowerCAmelCase_					)
  
  								for key in encoded_tok.keys():
  													self.assertListEqual(encoded_tok[key]							,							encoded_processor[key]					)
  
  			def _lowercase (	self     :     List[Any]					)					->					Optional[int]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.get_feature_extractor()
  								SCREAMING_SNAKE_CASE_	      =       self.get_tokenizer()
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=lowerCAmelCase_							,							feature_extractor=lowerCAmelCase_					)
  
  								SCREAMING_SNAKE_CASE_	      =       [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
  								SCREAMING_SNAKE_CASE_	      =       processor.batch_decode(lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       tokenizer.batch_decode(lowerCAmelCase_					)
  
  								self.assertListEqual(lowerCAmelCase_							,							lowerCAmelCase_					)
  
  			def _lowercase (	self     :     List[Any]					)					->					str:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.get_feature_extractor()
  								SCREAMING_SNAKE_CASE_	      =       self.get_tokenizer()
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=lowerCAmelCase_							,							feature_extractor=lowerCAmelCase_					)
  
  								self.assertListEqual(
  								    processor.model_input_names							,							feature_extractor.model_input_names							,							msg='''`processor` and `feature_extractor` model input names do not match'''							,							)
  
  			def _lowercase (	self     :     str					)					->					Any:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.get_feature_extractor()
  								SCREAMING_SNAKE_CASE_	      =       self.get_tokenizer()
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=lowerCAmelCase_							,							feature_extractor=lowerCAmelCase_					)
  								SCREAMING_SNAKE_CASE_	      =       processor.get_decoder_prompt_ids(task='''transcribe'''							,							no_timestamps=lowerCAmelCase_					)
  
  								self.assertIsInstance(lowerCAmelCase_							,							lowerCAmelCase_					)
  								for ids in forced_decoder_ids:
  													self.assertIsInstance(lowerCAmelCase_							,							(list, tuple)					)
  
  								SCREAMING_SNAKE_CASE_	      =       [TRANSCRIBE, NOTIMESTAMPS]
  								self.assertListEqual([ids[-1] for ids in forced_decoder_ids]							,							lowerCAmelCase_					)
  
  			def _lowercase (	self     :     int					)					->					Any:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=self.get_tokenizer()							,							feature_extractor=self.get_feature_extractor()					)
  								SCREAMING_SNAKE_CASE_	      =       processor.get_prompt_ids('''Mr. Quilter'''					)
  								SCREAMING_SNAKE_CASE_	      =       processor.tokenizer.decode(lowerCAmelCase_					)
  
  								self.assertListEqual(prompt_ids.tolist()							,							[50_360, 1_770, 13, 2_264, 346, 353]					)
  								self.assertEqual(lowerCAmelCase_							,							'''<|startofprev|> Mr. Quilter'''					)
  
  			def _lowercase (	self     :     Any					)					->					Any:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=self.get_tokenizer()							,							feature_extractor=self.get_feature_extractor()					)
  								SCREAMING_SNAKE_CASE_	      =       processor.get_prompt_ids(''''''					)
  								SCREAMING_SNAKE_CASE_	      =       processor.tokenizer.decode(lowerCAmelCase_					)
  
  								self.assertListEqual(prompt_ids.tolist()							,							[50_360, 220]					)
  								self.assertEqual(lowerCAmelCase_							,							'''<|startofprev|> '''					)
  
  
  
  
  			def _lowercase (	self     :     Any					)					->					List[str]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       WhisperProcessor(tokenizer=self.get_tokenizer()							,							feature_extractor=self.get_feature_extractor()					)
  
  								def _test_prompt_error_raised_helper(lowerCAmelCase_     :     Union[str, Any]							,							lowerCAmelCase_     :     Tuple					):
  													with pytest.raises(lowerCAmelCase_					) as excinfo:
  																		processor.get_prompt_ids(lowerCAmelCase_					)
  													SCREAMING_SNAKE_CASE_	      =       F'''Encountered text in the prompt corresponding to disallowed special token: {special_token}.'''
  													self.assertEqual(lowerCAmelCase_							,							str(excinfo.value					)					)
  
  								_test_prompt_error_raised_helper('''<|startofprev|> test'''							,							'''<|startofprev|>'''					)
  								_test_prompt_error_raised_helper('''test <|notimestamps|>'''							,							'''<|notimestamps|>'''					)
  								_test_prompt_error_raised_helper('''test <|zh|> test <|transcribe|>'''							,							'''<|zh|>'''					)
  
  
  
style_context: 
  
  
  import unittest
  
  from transformers import load_tool
  from transformers.tools.agent_types import AGENT_TYPE_MAPPING
  
  from .test_tools_common import ToolTesterMixin, output_types
  
  class 						snake_case			(       unittest.TestCase	, lowerCAmelCase__	):
  			'''simple docstring'''
  
  			def _lowercase (	self     :     List[Any]					)					->					Optional[Any]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       load_tool('''translation'''					)
  								self.tool.setup()
  								SCREAMING_SNAKE_CASE_	      =       load_tool('''translation'''							,							remote=lowerCAmelCase_					)
  
  			def _lowercase (	self     :     Tuple					)					->					str:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.tool('''Hey, what\'s up?'''							,							src_lang='''English'''							,							tgt_lang='''French'''					)
  								self.assertEqual(lowerCAmelCase_							,							'''- Hé, comment ça va?'''					)
  
  			def _lowercase (	self     :     Optional[Any]					)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.remote_tool('''Hey, what\'s up?'''							,							src_lang='''English'''							,							tgt_lang='''French'''					)
  								self.assertEqual(lowerCAmelCase_							,							'''- Hé, comment ça va?'''					)
  
  			def _lowercase (	self     :     Optional[int]					)					->					str:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.tool(text='''Hey, what\'s up?'''							,							src_lang='''English'''							,							tgt_lang='''French'''					)
  								self.assertEqual(lowerCAmelCase_							,							'''- Hé, comment ça va?'''					)
  
  			def _lowercase (	self     :     str					)					->					List[str]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       self.remote_tool(text='''Hey, what\'s up?'''							,							src_lang='''English'''							,							tgt_lang='''French'''					)
  								self.assertEqual(lowerCAmelCase_							,							'''- Hé, comment ça va?'''					)
  
  			def _lowercase (	self     :     Optional[int]					)					->					Dict:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       ['''Hey, what\'s up?''', '''English''', '''Spanish''']
  								SCREAMING_SNAKE_CASE_	      =       self.tool(*lowerCAmelCase_					)
  
  								# There is a single output
  								if len(self.tool.outputs					) == 1:
  													SCREAMING_SNAKE_CASE_	      =       [outputs]
  
  								self.assertListEqual(output_types(lowerCAmelCase_					)							,							self.tool.outputs					)
  
  			def _lowercase (	self     :     Optional[int]					)					->					List[str]:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       ['''Hey, what\'s up?''', '''English''', '''Spanish''']
  								SCREAMING_SNAKE_CASE_	      =       self.tool(*lowerCAmelCase_					)
  
  								if not isinstance(lowerCAmelCase_							,							lowerCAmelCase_					):
  													SCREAMING_SNAKE_CASE_	      =       [outputs]
  
  								self.assertEqual(len(lowerCAmelCase_					)							,							len(self.tool.outputs					)					)
  
  								for output, output_type in zip(lowerCAmelCase_							,							self.tool.outputs					):
  													SCREAMING_SNAKE_CASE_	      =       AGENT_TYPE_MAPPING[output_type]
  													self.assertTrue(isinstance(lowerCAmelCase_							,							lowerCAmelCase_					)					)
  
  
  
  
  			def _lowercase (	self     :     Tuple					)					->					int:
  
  
  
  
  								"""simple docstring"""
  
  
  
  
  
  
  								SCREAMING_SNAKE_CASE_	      =       ['''Hey, what\'s up?''', '''English''', '''Spanish''']
  
  								SCREAMING_SNAKE_CASE_	      =       []
  
  								for _input, input_type in zip(lowerCAmelCase_							,							self.tool.inputs					):
  													if isinstance(lowerCAmelCase_							,							lowerCAmelCase_					):
  																		_inputs.append([AGENT_TYPE_MAPPING[_input_type](_input					) for _input_type in input_type]					)
  													else:
  																		_inputs.append(AGENT_TYPE_MAPPING[input_type](_input					)					)
  
          # Should not raise an error
  								SCREAMING_SNAKE_CASE_	      =       self.tool(*lowerCAmelCase_					)
  
  								if not isinstance(lowerCAmelCase_							,							lowerCAmelCase_					):
  													SCREAMING_SNAKE_CASE_	      =       [outputs]
  
  								self.assertEqual(len(lowerCAmelCase_					)							,							len(self.tool.outputs					)					)
  
  
  