
    g                         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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                         D ]%  \  }}|dk7  s|t        | j                  ||       ' y )Nself)localsitemssetattr	__class__)r#   r   r   r   r   r   r   r   r   r   r   r   r    locals_keyvalues                   _/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/nlp_cloud/chat/transformation.py__init__zNLPCloudConfig.__init__B   s;     (!--/JCf}!2U3 *    c                      t         |          S N)super
get_config)clsr'   s    r+   r1   zNLPCloudConfig.get_configV   s    w!##r-   headersmodelmessagesoptional_paramsapi_keyapi_basec                 $    ddd}|rd| |d<   |S )Nzapplication/json)acceptzcontent-typezToken Authorization )r#   r3   r4   r5   r6   r7   r8   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#   r4   s     r+   get_supported_openai_paramsz*NLPCloudConfig.get_supported_openai_paramsk   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 )Nr?   r   r@   r   r   rA   rB   rC   r    rD   stop_sequences)r%   )r#   rF   r6   r4   rG   paramr*   s          r+   map_openai_paramsz NLPCloudConfig.map_openai_paramsw   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)rM   messager3   r   )r#   rL   rM   r3   s       r+   get_error_classzNLPCloudConfig.get_error_class   s     #]G
 	
r-   litellm_paramsc                 B    dj                  d |D              }d|i|}|S )N c              3   2   K   | ]  }t        |        y wr/   r   ).0rO   s     r+   	<genexpr>z3NLPCloudConfig.transform_request.<locals>.<genexpr>   s     UH3G<Hs   text)join)r#   r4   r5   r6   rQ   r3   rW   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)inputr7   original_responseadditional_args)rO   rM   errorgenerated_textr   nb_input_tokensnb_generated_tokens)prompt_tokenscompletion_tokenstotal_tokensusage)	post_callrW   json	Exceptionr   rM   lenchoicesrO   contentdumpsinttimecreatedr4   r   r&   )r#   r4   r[   r\   r]   r^   r5   r6   rQ   r_   r7   r`   completion_responserj   rk   rm   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   ru   __annotations__r   boolr   strr   r   r   listr   floatr   r   r   r   r    r,   classmethodr1   dictr   r   r=   rE   rK   r   httpxHeadersr   rP   rZ   Responser   LoggingClassr   ry   __classcell__)r'   s   @r+   r   r      sX   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   )ro   rv   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KZ Kr-   