
    ^hO&                         S SK r S SKJrJrJrJrJrJrJr  S SK	r	S SK
r
S SKJr  S SKJrJr  S SKJr  S SKJrJrJrJr  SSKJr  SS	KJr  SS
KJr  \(       a	  S SKJr  \r O\r  " S S\5      r!g)    N)TYPE_CHECKINGAnyAsyncIteratorIteratorListOptionalUnionconvert_content_list_to_str)
BaseConfigBaseLLMException)AllMessageValues)ChoicesMessageModelResponseUsage   CohereError)ModelResponseIterator)validate_environment)Loggingc                   n  ^  \ rS rSr% SrSr\\   \S'   Sr	\\   \S'   Sr
\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S	'   Sr\\   \S
'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'   Sr\\   \S'                S0S\\   S\\   S\\   S\\   S\\   S	\\   S
\\   S\\   S\\   S\\   S\\   S\\   S\\   SS4S jjr\U 4S j5       r S1S\S\S\\   S\S\\   S\4S jjrS\S\S\\\R@                  4   S\!4S jr"S\S\4S jr#S\S\S\S\$S\4
S  jr%S\S\\   S\S!\S\S\4S" jr&  S2S\S#\RN                  S$\(S%\)S&\S\\   S\S!\S'\*S\\   S(\\$   S\(4S) jjr+ S1S*\\   S\4S+ jjr, S3S,\\-\   \.\   \(4   S-\$S(\\$   4S. jjr/S/r0U =r1$ )4CohereTextConfig   a  
Reference: https://docs.cohere.com/reference/generate

The class `CohereConfig` provides configuration for the Cohere's API interface. Below are the parameters:

- `num_generations` (integer): Maximum number of generations returned. Default is 1, with a minimum value of 1 and a maximum value of 5.

- `max_tokens` (integer): Maximum number of tokens the model will generate as part of the response. Default value is 20.

- `truncate` (string): Specifies how the API handles inputs longer than maximum token length. Options include NONE, START, END. Default is END.

- `temperature` (number): A non-negative float controlling the randomness in generation. Lower temperatures result in less random generations. Default is 0.75.

- `preset` (string): Identifier of a custom preset, a combination of parameters such as prompt, temperature etc.

- `end_sequences` (array of strings): The generated text gets cut at the beginning of the earliest occurrence of an end sequence, which will be excluded from the text.

- `stop_sequences` (array of strings): The generated text gets cut at the end of the earliest occurrence of a stop sequence, which will be included in the text.

- `k` (integer): Limits generation at each step to top `k` most likely tokens. Default is 0.

- `p` (number): Limits generation at each step to most likely tokens with total probability mass of `p`. Default is 0.

- `frequency_penalty` (number): Reduces repetitiveness of generated tokens. Higher values apply stronger penalties to previously occurred tokens.

- `presence_penalty` (number): Reduces repetitiveness of generated tokens. Similar to frequency_penalty, but this penalty applies equally to all tokens that have already appeared.

- `return_likelihoods` (string): Specifies how and if token likelihoods are returned with the response. Options include GENERATION, ALL and NONE.

- `logit_bias` (object): Used to prevent the model from generating unwanted tokens or to incentivize it to include desired tokens. e.g. {"hello_world": 1233}
Nnum_generations
max_tokenstruncatetemperaturepresetend_sequencesstop_sequenceskpfrequency_penaltypresence_penaltyreturn_likelihoods
logit_biasreturnc                     [        5       nUR                  5        H*  u  nnUS:w  d  M  Uc  M  [        U R                  UU5        M,     g )Nself)localsitemssetattr	__class__)r+   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   locals_keyvalues                    g/home/james-whalen/.local/lib/python3.13/site-packages/litellm/llms/cohere/completion/transformation.py__init__CohereTextConfig.__init__I   s;      (!--/JCf}!2U3 *    c                     > [         TU ]  5       $ N)super
get_config)clsr/   s    r3   r:   CohereTextConfig.get_config^   s    w!##r6   headersmodelmessagesoptional_paramsapi_keyc                     [        UUUUUS9$ )N)r=   r>   r?   r@   rA   )cohere_validate_environment)r+   r=   r>   r?   r@   rA   s         r3   r   %CohereTextConfig.validate_environmentb   s      ++
 	
r6   error_messagestatus_codec                     [        X!S9$ )N)rF   messager   )r+   rE   rF   r=   s       r3   get_error_class CohereTextConfig.get_error_classr   s     {JJr6   c                 
    / SQ$ )N)
streamr   r   r(   top_pr%   r&   stopnextra_headers )r+   r>   s     r3   get_supported_openai_params,CohereTextConfig.get_supported_openai_paramsw   s    
 	
r6   non_default_paramsdrop_paramsc                    UR                  5        Hq  u  pVUS:X  a  XbS'   M  US:X  a  XbS'   M  US:X  a  XbS'   M)  US:X  a  XbS'   M5  US:X  a  XbS'   MA  US:X  a  XbS'   MM  US	:X  a  XbS	'   MY  US
:X  a  XbS
'   Me  US:X  d  Mm  XbS'   Ms     U$ )NrL   r   r   rO   r   r(   rM   r$   r%   r&   rN   r"   )r-   )r+   rT   r@   r>   rU   paramr2   s          r3   map_openai_params"CohereTextConfig.map_openai_params   s     /446LE ,1)-'16.,&05-#5: 12,&05-'!',$--7< 34,,6; 23&49 01% 7& r6   litellm_paramsc                    SR                  S U 5       5      n[        R                  R                  5       nUR	                  5        H  u  pX;  d  M  XU'   M     SU;   a  Sn
U R                  US   S9nXS'   UUS.UEnU$ )N c              3   4   #    U  H  n[        US 9v   M     g7f)rH   Nr
   .0rH   s     r3   	<genexpr>5CohereTextConfig.transform_request.<locals>.<genexpr>         
HPW'8   toolsT)re   )r>   prompt)joinlitellmCohereConfigr:   r-   )_construct_cohere_tool_for_completion_api)r+   r>   r?   r@   rZ   r=   rf   configr#   v_is_function_calltool_calling_system_promptdatas                r3   transform_request"CohereTextConfig.transform_request   s      
HP
 

 %%002LLNDA(%&"	 # o% $)-)W)W%g. *X *& (BG$ 
 
 r6   raw_responsemodel_responselogging_objrequest_dataencoding	json_modec                 L   SR                  S U 5       5      nUR                  5       n/ n[        US   5       HP  u  nn[        US   5      S:  a  [	        US   S9nO	[	        S S9n[        US   US-   US	9nUR                  U5        MR     Xl        [        U	R                  U5      5      n[        U	R                  US
   S   S   R                  SS5      5      5      n[        [        R                  " 5       5      Ul        Xl        [        UUUU-   S9n[        USU5        U$ )Nr\   c              3   4   #    U  H  n[        US 9v   M     g7fr^   r
   r_   s     r3   ra   6CohereTextConfig.transform_response.<locals>.<genexpr>   rc   rd   generationstextr   )contentfinish_reason   )r~   indexrH   choicesrH   r}    )prompt_tokenscompletion_tokenstotal_tokensusage)rg   json	enumeratelenr   r   appendr   encodegetinttimecreatedr>   r   r.   )r+   r>   rr   rs   rt   ru   r?   r@   rZ   rv   rA   rw   rf   completion_responsechoices_listidxitemmessage_obj
choice_objr   r   r   s                         r3   transform_response#CohereTextConfig.transform_response   s=     
HP
 
 +//1"#6}#EFIC4< 1$%d6l;%d3 "?3Ag#J
 
+ G ". HOOF34OON95a8CGG	SUVW
 "%TYY[!1$'/&)::

 	/r6   re   c                     Uc  / nSU0$ )Nre   rQ   )r+   re   s     r3   rj   :CohereTextConfig._construct_cohere_tool_for_completion_api   s     =Er6   streaming_responsesync_streamc                     [        UUUS9$ )N)r   r   rw   )CohereModelResponseIterator)r+   r   r   rw   s       r3   get_model_response_iterator,CohereTextConfig.get_model_response_iterator   s     +1#
 	
r6   rQ   )NNNNNNNNNNNNNr8   )NN)F)2__name__
__module____qualname____firstlineno____doc__r   r   r   __annotations__r   r   strr   r    r!   listr"   r#   r$   r%   r&   r'   r(   dictr4   classmethodr:   r   r   r   r	   httpxHeadersr   rI   rR   boolrX   rp   Responser   LiteLLMLoggingObjr   r   rj   r   r   r   __static_attributes____classcell__)r/   s   @r3   r   r      s   @ &*OXc]) $J$"Hhsm"!%K#% FHSM $(M8D>(%)NHTN)Ax}Ax}'+x}+&*hsm*(,,!%J% *.$("&%) $(,)-+/*.,0%)4!#4 SM4 3-	4
 c]4 4  ~4 !4 C=4 C=4 $C=4 #3-4 %SM4 TN4 
4* $ $ "&

 
 '(	

 
 #
 

 K K/2K=B4CV=WK	K

 
 
   	
  
8"" '(" 	"
 " " 
"^ "&$(.. nn. &	.
 '. . '(. . . . #. D>. 
.d !% ~  
  %*	

!(3-s1C]"RS

 

 D>	

 

r6   r   )"r   typingr   r   r   r   r   r   r	   r   rh   8litellm.litellm_core_utils.prompt_templates.common_utilsr   )litellm.llms.base_llm.chat.transformationr   r   litellm.types.llms.openair   litellm.types.utilsr   r   r   r   common_utilsr   r   r   r   rC   *litellm.litellm_core_utils.litellm_loggingr   _LiteLLMLoggingObjr   r   rQ   r6   r3   <module>r      sT     U U U   S 6 F F & O NX*m
z m
r6   