
    h+                         d dl Z d dlZd dlmZmZmZmZmZ d dlZd dl	m
Z
 d dlmZmZ d dlmZ d dlmZmZ ddlmZ er	d d	lmZ eZneZ G d
 de      Zy)    N)TYPE_CHECKINGAnyListOptionalUnionconvert_content_list_to_str)
BaseConfigBaseLLMException)AllMessageValues)ModelResponseUsage   NLPCloudError)Loggingc                       e Zd ZU dZdZee   ed<   dZee	   ed<   dZ
ee   ed<   dZee	   ed<   dZee	   ed<   dZee   ed<   dZee   ed	<   dZee   ed
<   dZee   ed<   dZee   ed<   dZee   ed<   dZee   ed<   	 	 	 	 	 	 	 	 	 	 	 	 d)dee   dee	   dee   dee	   dee	   dee   d	ee   d
ee   dee   dee   dee   dee   ddfdZe f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defdZdededede	def
dZdedede ee!jD                  f   de#fd Z$dedee   dedededefd!Z%	 	 d*ded"e!jL                  d#e'd$e(d%edee   deded&e)dee   d'ee	   de'fd(Z* xZ+S )+NLPCloudConfigal  
    Reference: https://docs.nlpcloud.com/#generation

    - `max_length` (int): Optional. The maximum number of tokens that the generated text should contain.

    - `length_no_input` (boolean): Optional. Whether `min_length` and `max_length` should not include the length of the input text.

    - `end_sequence` (string): Optional. A specific token that should be the end of the generated sequence.

    - `remove_end_sequence` (boolean): Optional. Whether to remove the `end_sequence` string from the result.

    - `remove_input` (boolean): Optional. Whether to remove the input text from the result.

    - `bad_words` (list of strings): Optional. List of tokens that are not allowed to be generated.

    - `temperature` (float): Optional. Temperature sampling. It modulates the next token probabilities.

    - `top_p` (float): Optional. Top P sampling. Below 1, only the most probable tokens with probabilities that add up to top_p or higher are kept for generation.

    - `top_k` (int): Optional. Top K sampling. The number of highest probability vocabulary tokens to keep for top k filtering.

    - `repetition_penalty` (float): Optional. Prevents the same word from being repeated too many times.

    - `num_beams` (int): Optional. Number of beams for beam search.

    - `num_return_sequences` (int): Optional. The number of independently computed returned sequences.
    N
max_lengthlength_no_inputend_sequenceremove_end_sequenceremove_input	bad_wordstemperaturetop_ptop_krepetition_penalty	num_beamsnum_return_sequencesreturnc                     t               j                         }|j                         D ]%  \  }}|dk7  s|t        | j                  ||       ' y )Nself)localscopyitemssetattr	__class__)r#   r   r   r   r   r   r   r   r   r   r   r   r    locals_keyvalues                   f/var/www/Befach/backend/env/lib/python3.12/site-packages/litellm/llms/nlp_cloud/chat/transformation.py__init__zNLPCloudConfig.__init__B   sA     (--/!--/JCf}!2U3 *    c                      t         |          S N)super
get_config)clsr(   s    r,   r2   zNLPCloudConfig.get_configV   s    w!##r.   headersmodelmessagesoptional_paramslitellm_paramsapi_keyapi_basec                 $    ddd}|rd| |d<   |S )Nzapplication/json)acceptzcontent-typezToken Authorization )r#   r4   r5   r6   r7   r8   r9   r:   s           r,   validate_environmentz#NLPCloudConfig.validate_environmentZ   s,     ).
 )/y'9GO$r.   c                 
    g dS )N)
max_tokensstreamr   r   presence_penaltyfrequency_penaltynstopr>   )r#   r5   s     r,   get_supported_openai_paramsz*NLPCloudConfig.get_supported_openai_paramsl   s    	
 		
r.   non_default_paramsdrop_paramsc                     |j                         D ]V  \  }}|dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d<   |dk(  r||d	<   |d
k(  sR||d<   X |S )NrA   r   rB   r   r   rC   rD   rE   r    rF   stop_sequences)r&   )r#   rH   r7   r5   rI   paramr+   s          r,   map_openai_paramsz NLPCloudConfig.map_openai_paramsx   s     /446LE5$05- ,1)%16.+0(**6; 23++7< 34|:? 6749 01! 7" r.   error_messagestatus_codec                     t        |||      S )N)rO   messager4   r   )r#   rN   rO   r4   s       r,   get_error_classzNLPCloudConfig.get_error_class   s     #]G
 	
r.   c                 B    dj                  d |D              }d|i|}|S )N c              3   2   K   | ]  }t        |        y wr0   r   ).0rQ   s     r,   	<genexpr>z3NLPCloudConfig.transform_request.<locals>.<genexpr>   s     U3G<Us   text)join)r#   r5   r6   r7   r8   r4   rX   datas           r,   transform_requestz NLPCloudConfig.transform_request   s5     xxUHUU D


 r.   raw_responsemodel_responselogging_objrequest_dataencoding	json_modec                 x   |j                  d |
|j                  d|i       	 |j                         }d|v rt	        |d   |j
                        	 t        |d         dkD  r!|d   |j                  d   j                  _	        |d   }|d   }t        t        j                               |_        ||_        t        ||||z   	      }t!        |d
|       |S # t        $ r" t	        |j                  |j
                        w xY w# t        $ r+ t	        t        j                  |      |j
                        w xY w)Ncomplete_input_dict)inputr9   original_responseadditional_args)rQ   rO   errorgenerated_textr   nb_input_tokensnb_generated_tokens)prompt_tokenscompletion_tokenstotal_tokensusage)	post_callrX   json	Exceptionr   rO   lenchoicesrQ   contentdumpsinttimecreatedr5   r   r'   )r#   r5   r\   r]   r^   r_   r6   r7   r8   r`   r9   ra   completion_responserk   rl   rn   s                   r,   transform_responsez!NLPCloudConfig.transform_response   sj    	*//2LA	 	 	
	"."3"3"5
 ))+G4(44 
	*+;<=A+,<= #**1-55= ,,=>/0EF!$TYY[!1$'/&)::

 	/C  	$))|7O7O 	  # JJ':; , 8 8 s   C 2D +D4D9)NNNNNNNNNNNN)NN),__name__
__module____qualname____doc__r   r   rv   __annotations__r   boolr   strr   r   r   listr   floatr   r   r   r   r    r-   classmethodr2   dictr   r   r?   rG   rM   r   httpxHeadersr   rR   r[   Responser   LoggingClassr   rz   __classcell__)r(   s   @r,   r   r      sb   8 !%J$&*OXd^*"&L(3-&*.$.#'L(4.' $Ix~$#'K%'!E8E?!E8C=*..#Ix}#*.(3-. %)*.&*.2'+$('+!%#.2#'.24SM4 "$4 sm	4
 &d^4 tn4 D>4 e_4 4 }4 %UO4 C=4 'sm4 
4( $ $ "&"&  '(	
   # 3- 
$

 

 

   	
  
4
 
/2
=B4CV=W
	
 '( 	
   
8 "&$(:: nn: &	:
 ": : '(: : : : #: D>: 
:r.   r   )rp   rw   typingr   r   r   r   r   r   8litellm.litellm_core_utils.prompt_templates.common_utilsr	   )litellm.llms.base_llm.chat.transformationr
   r   litellm.types.llms.openair   litellm.utilsr   r   common_utilsr   *litellm.litellm_core_utils.litellm_loggingr   LiteLLMLoggingObjr   r   r>   r.   r,   <module>r      sF      < <  S 6 . (W$LLLZ Lr.   