
    AHj                         d dl mZmZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ er	d dlmZ eZneZ G d de      Z G d d	      Zy
)    )TYPE_CHECKINGAnyListOptionalTupleget_secret_str)AllMessageValues)BaseLLMException)Loggingc                       e Zd ZdZy)SnowflakeExceptionz/Snowflake AI Endpoints exception handling classN)__name__
__module____qualname____doc__     T/root/tools/cai/cai_env/lib/python3.12/site-packages/litellm/llms/snowflake/utils.pyr   r      s    9r   r   c                       e Zd Zdedee   fdZdededededef
dZd Z		 	 dd
ededee
   dededee   dee   defdZdee   dee   deee   ee   f   fdZy	)SnowflakeBaseConfigmodelreturnc                 
    g dS )N)temperature
max_tokenstop_presponse_formattoolstool_choicer   )selfr   s     r   get_supported_openai_paramsz/SnowflakeBaseConfig.get_supported_openai_params   s    
 	
r   non_default_paramsoptional_paramsdrop_paramsc                 l    | j                  |      }|j                         D ]  \  }}||v s|||<    |S )a  
        If any supported_openai_params are in non_default_params, add them to optional_params, so they are used in API call

        Args:
            non_default_params (dict): Non-default parameters to filter.
            optional_params (dict): Optional parameters to update.
            model (str): Model name for parameter support check.

        Returns:
            dict: Updated optional_params with supported non-default parameters.
        )r"   items)r!   r#   r$   r   r%   supported_openai_paramsparamvalues           r   map_openai_paramsz%SnowflakeBaseConfig.map_openai_params    sL    $ #'"B"B5"I.446 	/LE5//).&	/ r   c                     |s4d|v r|j                  d      }nt        d      }|t        d      d| d}|j                  d      }|j	                  d      s|dz  }|S )N
account_idSNOWFLAKE_ACCOUNT_IDzMissing snowflake account_idzhttps://z.snowflakecomputing.com/api/v2/z/api/v2)popr	   
ValueErrorrstripendswith)r!   api_baser$   r-   s       r   _get_api_basez!SnowflakeBaseConfig._get_api_base8   st    .,00>
+,BC
! !?@@!*-KLH??3'  +	!Hr   Nheadersmessageslitellm_paramsapi_keyr4   c                     d}|t        d      d}	|j                  |	      r|t        |	      d }d}|j                  ddd|z   |d       |S )	a  
        Return headers to use for Snowflake completion request

        Snowflake REST API Ref: https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-llm-rest-api#api-reference
        Expected headers:
        {
            "Content-Type": "application/json",
            "Accept": "application/json",
            "Authorization": "Bearer " + <JWT>,
            "X-Snowflake-Authorization-Token-Type": "KEYPAIR_JWT"
        }
        KEYPAIR_JWTNzMissing Snowflake JWT keyzpat/PROGRAMMATIC_ACCESS_TOKENzapplication/jsonzBearer )zContent-TypeAcceptAuthorizationz$X-Snowflake-Authorization-Token-Type)r1   
startswithlenupdate)
r!   r6   r   r7   r$   r8   r9   r4   	auth_typepat_key_prefixs
             r   validate_environmentz(SnowflakeBaseConfig.validate_environmentG   sm    . "	?899#N!!.1!#n"5"787	 2,!*W!48A		
 r   c                 (    |xs t        d      }||fS )NSNOWFLAKE_JWTr   )r!   r4   r9   dynamic_api_keys       r   $_get_openai_compatible_provider_infoz8SnowflakeBaseConfig._get_openai_compatible_provider_infor   s     "D^O%D((r   )NN)r   r   r   strr   r"   dictboolr+   r5   r
   r   rD   r   rH   r   r   r   r   r      s    
 
c 
   	
  
0, "&"&)) ) '(	)
 ) ) #) 3-) 
)V) )08)	x}hsm+	,)r   r   N)typingr   r   r   r   r   litellm.secret_managers.mainr	   litellm.types.llms.openair
   )litellm.llms.base_llm.chat.transformationr   *litellm.litellm_core_utils.litellm_loggingr   _LiteLLMLoggingObjLiteLLMLoggingObjr   r   r   r   r   <module>rS      s?    < < 7 6 FX*	) 	a) a)r   