





from ...configuration_utils import PretrainedConfig
from ...utils import logging


__A     =    logging.get_logger(__name__)

__A     =    {}



class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ):







	'''simple docstring'''
	lowercase_		=      """llama"""
	lowercase_		=      ["""past_key_values"""]

	def __init__(self    :       Optional[Any]	,			UpperCAmelCase_    :       str=32_000	,			UpperCAmelCase_    :       Optional[int]=4_096	,			UpperCAmelCase_    :       Dict=11_008	,			UpperCAmelCase_    :       str=32	,			UpperCAmelCase_    :       Tuple=32	,			UpperCAmelCase_    :       Tuple=None	,			UpperCAmelCase_    :       List[Any]="silu"	,			UpperCAmelCase_    :       str=2_048	,			UpperCAmelCase_    :       Tuple=0.02	,			UpperCAmelCase_    :       List[Any]=1E-6	,			UpperCAmelCase_    :       int=True	,			UpperCAmelCase_    :       List[str]=0	,			UpperCAmelCase_    :       str=1	,			UpperCAmelCase_    :       Optional[int]=2	,			UpperCAmelCase_    :       List[Any]=1	,			UpperCAmelCase_    :       Tuple=False	,			UpperCAmelCase_    :       Any=None	,			**UpperCAmelCase_    :       str	,			)	->Optional[Any]:



			'''simple docstring'''



			lowerCamelCase__:				List[Any]        =vocab_size
			lowerCamelCase__:				Union[str, Any]        =max_position_embeddings
			lowerCamelCase__:				Dict        =hidden_size
			lowerCamelCase__:				Dict        =intermediate_size
			lowerCamelCase__:				Any        =num_hidden_layers
			lowerCamelCase__:				str        =num_attention_heads

			# for backward compatibility
			if num_key_value_heads is None:
					lowerCamelCase__:				List[Any]        =num_attention_heads

			lowerCamelCase__:				Optional[Any]        =num_key_value_heads
			lowerCamelCase__:				List[str]        =hidden_act
			lowerCamelCase__:				Dict        =initializer_range
			lowerCamelCase__:				Tuple        =rms_norm_eps
			lowerCamelCase__:				Dict        =pretraining_tp
			lowerCamelCase__:				List[Any]        =use_cache
			lowerCamelCase__:				Tuple        =rope_scaling
			self._rope_scaling_validation()

			super().__init__(
			    pad_token_id=_lowercase	,			bos_token_id=_lowercase	,			eos_token_id=_lowercase	,			tie_word_embeddings=_lowercase	,			**_lowercase	,			)







	def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any])	->Union[str, Any]:



			'''simple docstring'''



			if self.rope_scaling is None:
					return

			if not isinstance(self.rope_scaling	,			_lowercase) or len(self.rope_scaling) != 2:
					raise ValueError(
					    "`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, "
					    F"""got {self.rope_scaling}""")
			lowerCamelCase__:				Optional[Any]        =self.rope_scaling.get("type"	,			_lowercase)
			lowerCamelCase__:				Optional[Any]        =self.rope_scaling.get("factor"	,			_lowercase)
			if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
					raise ValueError(
					    F"""`rope_scaling`'s name field must be one of ['linear', 'dynamic'], got {rope_scaling_type}""")
			if rope_scaling_factor is None or not isinstance(_lowercase	,			_lowercase) or rope_scaling_factor <= 1.0:
					raise ValueError(F"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}""")








from pathlib import Path
from typing import List

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import get_tests_dir, is_tool_test
from transformers.tools.agent_types import AGENT_TYPE_MAPPING, AgentAudio, AgentImage, AgentText


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image


__A     =    ["text", "image", "audio"]





def 					lowerCAmelCase_			(	__a		)					->		Optional[Any]:







  """simple docstring"""





  lowerCamelCase__:				Tuple        =[]

  for input_type in input_types:
    if input_type == "text":
      inputs.append("Text input"		)
    elif input_type == "image":
      inputs.append(
          Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"		)		) / "000000039769.png"		).resize((512, 512)		)		)
    elif input_type == "audio":
      inputs.append(torch.ones(3000		)		)
    elif isinstance(__a     ,   __a		):
      inputs.append(create_inputs(__a		)		)
    else:
      raise ValueError(F"""Invalid type requested: {input_type}"""		)

  return inputs





def 					lowerCAmelCase_			(	__a		)					->		Union[str, Any]:







  """simple docstring"""





  lowerCamelCase__:				Union[str, Any]        =[]

  for output in outputs:
    if isinstance(__a     ,   (str, AgentText)		):
      output_types.append("text"		)
    elif isinstance(__a     ,   (Image.Image, AgentImage)		):
      output_types.append("image"		)
    elif isinstance(__a     ,   (torch.Tensor, AgentAudio)		):
      output_types.append("audio"		)
    else:
      raise ValueError(F"""Invalid output: {output}"""		)

  return output_types






@is_tool_test
class        _SCREAMING_SNAKE_CASE						:







 '''simple docstring'''

 def 							SCREAMING_SNAKE_CASE_ (self    :       List[str])	->Dict:



   '''simple docstring'''



   self.assertTrue(hasattr(self.tool	,			"inputs"))
   self.assertTrue(hasattr(self.tool	,			"outputs"))

   lowerCamelCase__:				Tuple        =self.tool.inputs
   for _input in inputs:
     if isinstance(_input	,			UpperCAmelCase_):
       for __input in _input:
         self.assertTrue(__input in authorized_types)
     else:
       self.assertTrue(_input in authorized_types)

   lowerCamelCase__:				Optional[Any]        =self.tool.outputs
   for _output in outputs:
     self.assertTrue(_output in authorized_types)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[Any])	->str:



   '''simple docstring'''



   lowerCamelCase__:				List[str]        =create_inputs(self.tool.inputs)
   lowerCamelCase__:				str        =self.tool(*UpperCAmelCase_)

   # There is a single output
   if len(self.tool.outputs) == 1:
     lowerCamelCase__:				Optional[Any]        =[outputs]

   self.assertListEqual(output_types(UpperCAmelCase_)	,			self.tool.outputs)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->Any:



   '''simple docstring'''



   self.assertTrue(hasattr(self.tool	,			"description"))
   self.assertTrue(hasattr(self.tool	,			"default_checkpoint"))
   self.assertTrue(self.tool.description.startswith("This is a tool that"))

 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any])	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				str        =create_inputs(self.tool.inputs)
   lowerCamelCase__:				Dict        =self.tool(*UpperCAmelCase_)

   if not isinstance(UpperCAmelCase_	,			UpperCAmelCase_):
     lowerCamelCase__:				Tuple        =[outputs]

   self.assertEqual(len(UpperCAmelCase_)	,			len(self.tool.outputs))

   for output, output_type in zip(UpperCAmelCase_	,			self.tool.outputs):
     lowerCamelCase__:				Any        =AGENT_TYPE_MAPPING[output_type]
     self.assertTrue(isinstance(UpperCAmelCase_	,			UpperCAmelCase_))







 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->str:



   '''simple docstring'''



   lowerCamelCase__:				Any        =create_inputs(self.tool.inputs)

   lowerCamelCase__:				int        =[]

   for _input, input_type in zip(UpperCAmelCase_	,			self.tool.inputs):
     if isinstance(UpperCAmelCase_	,			UpperCAmelCase_):
       _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
   lowerCamelCase__:				Union[str, Any]        =self.tool(*UpperCAmelCase_)

   if not isinstance(UpperCAmelCase_	,			UpperCAmelCase_):
     lowerCamelCase__:				str        =[outputs]

   self.assertEqual(len(UpperCAmelCase_)	,			len(self.tool.outputs))

