
    tni                         d Z ddlZddlmZmZmZmZ dZdZdZ	dZ
dZd	Zd
Zdee         deddfdZd Zd Zd Zd Zdeeef         deeef         deeeeeef         ee         f         f         fdZdS )zd
runpod | serverless | utils | validator.py
Provides a function to validate the input to the model.
    N)AnyDictListUnionz1Unexpected input. {} is not a valid input option.z{} is a required input.z+Schema error, missing default value for {}.z"Schema error, missing type for {}.z{} should be {} type, not {}.z!{} does not meet the constraints.z%Schema error, {} is not a dictionary.
error_listmessagereturnc                 0    |                      |           d S N)append)r   r   s     a/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/runpod/serverless/utils/rp_validator.py
_add_errorr      s    g    c                 h    | D ].}||vr(t          |t                              |                     /d S r   )r   UNEXPECTED_INPUT_ERRORformat)	raw_inputschemar   keys       r   _check_for_unexpected_inputsr      sJ     G Gfz#9#@#@#E#EFFFG Gr   c                    |                                  D ]u\  }}t          |t                    s[	 t          j        |          | |<   3# t          j        j        $ r+ t          |t          	                    |                     Y qw xY wvd S r   )
items
isinstancedictjsonloadsdecoderJSONDecodeErrorr   SCHEMA_ERRORr   )r   r   r   ruless       r   $_validate_and_transform_schema_itemsr!      s    llnn A A
U%&& 	AA"j//s</ A A A:|':':3'?'?@@@@@A	AA As   A<BBc                    |                                 D ]\  }}d|vr(t          |t                              |                     d|vr)t          |t                              |                     ^|d         r-|| vr)t          |t                              |                     |d         s<|| vr8d|v r|d         ||<   t          |t
                              |                     d S )Ntyperequireddefault)r   r   MISSING_TYPE_ERRORr   MISSING_REQUIRED_ERRORMISSING_DEFAULT_ERROR)r   r   validated_inputr   r   r    s         r   *_validate_required_inputs_and_set_defaultsr*   (   s    llnn J J
Uz#5#<#<S#A#ABBBU""z#9#@#@#E#EFFFF: 	J3i#7#7z#9#@#@#E#EFFFFz" 	Js)';';E!!',Y'7$$:'<'C'CC'H'HIIIJ Jr   c                    |                                  D ]4\  }}||v r	 |d         t          u r;t          ||                   t          t          fv rt          ||                   ||<   n# t          $ r Y bw xY wd|v r*t          ||         t          |d                             rt          ||         |d                   }|s2t          || d|d          dt          ||                    d           d|v rL |d         |                    |                    s(t          |t          	                    |                     6d S )Nr#   r%   z should be z type, not .constraints)
r   floatr#   int	TypeErrorr   r   getCONSTRAINTS_ERRORr   )r   r)   r   r   r    is_instances         r   _validate_input_against_schemar4   :   s   llnn B B
U/!!=E))d?33G.H.HM / / ,11E+F+FOC(    E!!j1EtER[L\G]G]&^&^! %_S%95=IIK ^^uV}^^oVYFZA[A[^^^   E!!*>%*>$$+
 +
! z#4#;#;C#@#@AAA9B Bs   A
A++
A87A8r   r   c                     g }|                                  }t          | ||           t          ||           t          | |||           t	          |||           d|i}|rd|i}|S )a  
    Validates the input.
    Checks to see if the provided inputs match the expected types.
    Checks to see if the required inputs are included.
    Sets the default values for the inputs that are not provided.
    Validates the inputs using the lambda constraints.

    Returns either the list of errors or a validated_job_input.
    {"errors": ["error1", "error2"]}
    or
    {"validated_input": {"input1": "value1", "input2": "value2"}
    r)   errors)copyr   r!   r*   r4   )r   r   r   r)   validation_returns        r   validater9   Z   s     Jnn&&O !FJ???(<<<.6?J   #6?JGGG*O< 3%z2r   )__doc__r   typingr   r   r   r   r   r'   r(   r&   INVALID_TYPE_ERRORr2   r   strr   r   r!   r*   r4   r9    r   r   <module>r?      sF     ) ) ) ) ) ) ) ) ) ) ) ) M 2 E 9 4 7 649 s t    G G GA A AJ J J$B B B@CH~'+CH~	#uT#s(^T#Y./
/0     r   