
    g                         d dl Z d dlZd dlZd dlZd dlmZmZ d dlZd dlZd dl	m
Z
mZmZmZ  G d de      Z G d d      Z	 	 dded	ed
ededef
dZd Zy)    N)CallableOptional)ChoicesMessageModelResponseUsagec                        e Zd Z fdZ xZS )	PalmErrorc                     || _         || _        t        j                  dd      | _        t        j
                  || j                        | _        t        | !  | j                         y )NPOSTzJhttps://developers.generativeai.google/api/python/google/generativeai/chat)methodurl)status_coderequest)	r   messagehttpxRequestr   Responseresponsesuper__init__)selfr   r   	__class__s      [/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/deprecated_providers/palm.pyr   zPalmError.__init__   sT    &}}\
 ;ULL	
    )__name__
__module____qualname__r   __classcell__)r   s   @r   r
   r
      s    

 

r   r
   c                      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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d        Zy)
PalmConfigan  
    Reference: https://developers.generativeai.google/api/python/google/generativeai/chat

    The class `PalmConfig` provides configuration for the Palm's API interface. Here are the parameters:

    - `context` (string): Text that should be provided to the model first, to ground the response. This could be a prompt to guide the model's responses.

    - `examples` (list): Examples of what the model should generate. They are treated identically to conversation messages except that they take precedence over the history in messages if the total input size exceeds the model's input_token_limit.

    - `temperature` (float): Controls the randomness of the output. Must be positive. Higher values produce a more random and varied response. A temperature of zero will be deterministic.

    - `candidate_count` (int): Maximum number of generated response messages to return. This value must be between [1, 8], inclusive. Only unique candidates are returned.

    - `top_k` (int): The API uses combined nucleus and top-k sampling. `top_k` sets the maximum number of tokens to sample from on each step.

    - `top_p` (float): The API uses combined nucleus and top-k sampling. `top_p` configures the nucleus sampling. It sets the maximum cumulative probability of tokens to sample from.

    - `max_output_tokens` (int): Sets the maximum number of tokens to be returned in the output
    Ncontextexamplestemperaturecandidate_counttop_ktop_pmax_output_tokensreturnc                     t               }|j                         D ]%  \  }	}
|	dk7  s|
t        | j                  |	|
       ' y )Nr   )localsitemssetattrr   )r   r"   r#   r$   r%   r&   r'   r(   locals_keyvalues              r   r   zPalmConfig.__init__8   s;     (!--/JCf}!2U3 *r   c                     | j                   j                         D ci c]O  \  }}|j                  d      s9t        |t        j
                  t        j                  t        t        f      s|||Q c}}S c c}}w )N__)	__dict__r,   
startswith
isinstancetypesFunctionTypeBuiltinFunctionTypeclassmethodstaticmethod)clskvs      r   
get_configzPalmConfig.get_configG   sy     **,
,1<<%&&-- 	  qD,
 	
 
s   AA6)NNNNNNN)r   r   r   __doc__r"   r   str__annotations__r#   listr$   floatr%   intr&   r'   r(   r   r9   r>    r   r   r!   r!      s   ( "GXc]!#Hhtn##'K%'%)OXc])E8C=!E8E?!'+x}+ "&#''+)-#!%+/4#4 4.4 e_	4
 "#4 }4 4 $C=4 
4 
 
r   r!   modelmessagesmodel_responseprint_verboseoptional_paramsc
                    	 dd l m}
 |
j                  |       | } t	        j
                  |      }|j                  dd        t        j                  j                         }|j                         D ]  \  }}||vs|||<    d}|D ]+  }d|v r|d   dk(  r
||d    z  }||d    z  }#||d    z  }- |j                  |dd	d
|ii       	  |
j                  dd|i|}|j                  |d|d	i i        |d|        |}	 g }t!        |j"                        D ]S  \  }}t%        |d         dkD  rt'        |d         }nt'        d       }t)        |dz   |      }|j+                  |       U ||_        	 |d   d   d   j5                  d      }t%        |j7                  |            }t%        |j7                  |d   d   d   j5                  dd                  }t9        t;        j:                               |_        d| z   |_        tA        ||||z         }tC        |d|       |S # t        $ r t        d      w xY w# t        $ r}t        t        |      d      d }~ww xY w# t        $ r* t        t/        j0                         |j2                        w xY w# t        $ r t        dd|       w xY w)Nr   zTImporting google.generativeai failed, please run 'pip install -q google-generativeai)api_keystream roleusercontentcomplete_input_dictinference_params)inputrL   additional_argsprompti  )r   r   )rT   rL   original_responserU   zraw model_response: output)rQ      )indexr   choicesr   i  z*No response received. Original response - )r   r   zpalm/)prompt_tokenscompletion_tokenstotal_tokensusagerE   )"google.generativeaigenerativeai	Exception	configurecopydeepcopypoplitellmr!   r>   r,   pre_callgenerate_textr
   r@   	post_call	enumerate
candidateslenr   r   appendr[   	traceback
format_excr   getencoderD   timecreatedrF   r   r-   )rF   rG   rH   rI   rL   encodinglogging_objrJ   litellm_params	logger_fnpalmrS   configr<   r=   rV   r   r   ecompletion_responsechoices_listidxitemmessage_obj
choice_objr\   r]   r_   s                               r   
completionr   Z   s;   
*
 	NN7N#E }}_5$ **,F1%%"#Q	  FWv&(WY/01WY/01+,-F  .1CEU0VW  
%4%%HVH7GH ".3	   (
34"
"#6#A#ABIC4>"Q&%d8n=%d3 sQwDJ
+ C ".
,Y7:9EII)T /0My1!4Y?CCIrRS !-N"U?N#+"%66E
 NGU+y  
b
 	

N  
F
 	

4  
((*8L8L
 	

  
@
K
 	

s<   H/ I A4I. <J$ /I	I+I&&I+.3J!$J>c                       y )NrE   rE   r   r   	embeddingr      s    r   )NN)rd   rs   ro   r6   typingr   r   r   rg   litellm.utilsr   r   r   r   rb   r
   r!   r@   rB   dictr   r   rE   r   r   <module>r      s~        %   @ @
	 
<
 <
P jjj "j 	j jZ	r   