Ë
    Ýªgw  ã                   óz   — d dl mZmZmZ d dl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 ddlmZ  G d	„ d
e«      Zy)é    )ÚDictÚListÚOptionalN)Ú/convert_generic_image_chunk_to_openai_image_objÚconvert_to_anthropic_image_obj)ÚAllMessageValues)ÚContentTypeÚPartTypeé   )Ú%_gemini_convert_messages_with_history)ÚVertexGeminiConfigc                   óŽ  ‡ — 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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edee   fd„Zdededededef
ˆ fd„Zdee   dee   fd„Zˆ xZS )ÚGoogleAIStudioGeminiConfigaî  
    Reference: https://ai.google.dev/api/rest/v1beta/GenerationConfig

    The class `GoogleAIStudioGeminiConfig` provides configuration for the Google AI Studio's Gemini API interface. Below are the parameters:

    - `temperature` (float): This controls the degree of randomness in token selection.

    - `max_output_tokens` (integer): This sets the limitation for the maximum amount of token in the text output. In this case, the default value is 256.

    - `top_p` (float): The tokens are selected from the most probable to the least probable until the sum of their probabilities equals the `top_p` value. Default is 0.95.

    - `top_k` (integer): The value of `top_k` determines how many of the most probable tokens are considered in the selection. For example, a `top_k` of 1 means the selected token is the most probable among all tokens. The default value is 40.

    - `response_mime_type` (str): The MIME type of the response. The default value is 'text/plain'. Other values - `application/json`.

    - `response_schema` (dict): Optional. Output response schema of the generated candidate text when response mime type can have schema. Schema can be objects, primitives or arrays and is a subset of OpenAPI schema. If set, a compatible response_mime_type must also be set. Compatible mimetypes: application/json: Schema for JSON response.

    - `candidate_count` (int): Number of generated responses to return.

    - `stop_sequences` (List[str]): The set of character sequences (up to 5) that will stop output generation. If specified, the API will stop at the first appearance of a stop sequence. The stop sequence will not be included as part of the response.

    Note: Please make sure to modify the default parameters as required for your use case.
    NÚtemperatureÚmax_output_tokensÚtop_pÚtop_kÚresponse_mime_typeÚresponse_schemaÚcandidate_countÚstop_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   Úlocals_ÚkeyÚvalues               ú\/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/gemini/chat/transformation.pyÚ__init__z#GoogleAIStudioGeminiConfig.__init__3   s;   € ô “(ˆØ!Ÿ-™-ž/‰JˆCØf‹} Ñ!2Ü˜Ÿ™¨¨UÕ3ñ *ó    c                 ó    •— t         ‰|   «       S )N)ÚsuperÚ
get_config)Úclsr   s    €r"   r'   z%GoogleAIStudioGeminiConfig.get_configC   s   ø€ ä‰wÑ!Ó#Ð#r$   Úmodelc                 ó
   — g d¢S )N)r   r   Ú
max_tokensÚmax_completion_tokensÚstreamÚtoolsÚtool_choiceÚ	functionsÚresponse_formatÚnÚstopÚlogprobs© )r   r)   s     r"   Úget_supported_openai_paramsz6GoogleAIStudioGeminiConfig.get_supported_openai_paramsG   s   € ò
ð 	
r$   Únon_default_paramsÚoptional_paramsÚdrop_paramsc                 óŒ   •— d|v r|d= d|v r|d= t         j                  t         j                  |d<   t        ‰|   ||||¬«      S )NÚfrequency_penaltyÚpresence_penaltyÚsafety_settings)r)   r7   r8   r9   )ÚlitellmÚvertex_ai_safety_settingsr&   Úmap_openai_params)r   r7   r8   r)   r9   r   s        €r"   r@   z,GoogleAIStudioGeminiConfig.map_openai_paramsW   si   ø€ ð Ð"4Ñ4Ø"Ð#6Ð7ØÐ!3Ñ3Ø"Ð#5Ð6Ü×,Ñ,Ð8Ü18×1RÑ1RˆOÐ-Ñ.Ü‰wÑ(ØØ1Ø+Ø#ð	 )ó 
ð 	
r$   Úmessagesc                 ó‚  — |D ]¯  }|j                  d«      }|€Œt        |t        «      sŒ(g }|D ]  }|j                  d«      dk(  sŒ|}d}t        |j                  d«      t        «      r|d   j                  d«      }n|j                  d«      }|sŒdd|v sŒit	        |«      }t        |«      |d<   Œƒ Œ± t        |¬«      S )zR
        Google AI Studio Gemini does not support image urls in messages.
        ÚcontentNÚtypeÚ	image_urlÚurlzhttps://)rA   )ÚgetÚ
isinstanceÚlistÚdictr   r   r   )	r   rA   ÚmessageÚ_message_contentÚ_partsÚelementÚimg_elementÚ
_image_urlÚ	image_objs	            r"   Ú_transform_messagesz.GoogleAIStudioGeminiConfig._transform_messagesm   sÃ   € ó  ˆGØ&Ÿ{™{¨9Ó5ÐØÑ+´
Ð;KÌTÕ0RØ)+Û/GØ—{‘{ 6Ó*¨kÓ9Ø&-˜Ø48˜
Ü% k§o¡o°kÓ&BÄDÔIØ)4°[Ñ)A×)EÑ)EÀeÓ)L™Jà)4¯©¸Ó)E˜JÚ%¨*¸
Ò*BÜ(FÀzÓ(R˜Iä OØ$-ó!"ð (¨Ò4ñ  0ð	  ô& 5¸hÔGÐGr$   )NNNNNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚfloatÚ__annotations__r   Úintr   r   r   Ústrr   rJ   r   r   rI   r#   Úclassmethodr'   r   r6   r   Úboolr@   r   r	   rR   Ú__classcell__)r   s   @r"   r   r      s–  ø… ñð0 $(€K˜%‘Ó'Ø'+Ðx ‘}Ó+Ø!€Eˆ8E‰?Ó!Ø€Eˆ8C‰=ÓØ(,Ð˜ ™Ó,Ø&*€OX˜d‘^Ó*Ø%)€OX˜c‘]Ó)Ø%)€NH˜T‘NÓ)ð (,Ø+/Ø!%Ø#Ø,0Ø*.Ø)-Ø)-ñ4à˜e‘_ð4ð $ C™=ð4ð ˜‰ð	4ð
 ˜‰}ð4ð % S™Mð4ð " $™ð4ð " #™ð4ð ! ™ð4ð 
ó4ð  ó$ó ð$ð
°ð 
¸¸c¹ó 
ð 
à ð
ð ð
ð ð	
ð
 ð
ð 
õ
ð,HØÐ-Ñ.ðHà	ˆkÑ	÷Hr$   r   )Útypingr   r   r   r>   Ú3litellm.litellm_core_utils.prompt_templates.factoryr   r   Úlitellm.types.llms.openair   Úlitellm.types.llms.vertex_air	   r
   Úvertex_ai.gemini.transformationr   Ú3vertex_ai.gemini.vertex_and_google_ai_studio_geminir   r   r5   r$   r"   Ú<module>rd      s2   ðß 'Ñ 'ã ÷õ 7ß >å TÝ UôwHØõwHr$   