Ë
    uPêj^  ã                   óÄ   — d dl 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mZ d dlmZmZ d dlmZ dd	lmZ dd
lmZ dedeedz  edz  edz  f   fd„Z G d„ de«      Zy)é    )ÚFinalÚcastN)Ú/convert_generic_image_chunk_to_openai_image_objÚconvert_to_anthropic_image_obj)Úconvert_url_to_base64)ÚAllMessageValuesÚChatCompletionFileObjectÚChatCompletionImageObject)ÚContentTypeÚPartType)Úsupports_reasoningé   )Ú%_gemini_convert_messages_with_history)ÚVertexGeminiConfigÚimg_elementÚreturnc                 ó²   — | j                  d«      }t        |t        «      r2|j                  d«      |j                  d«      |j                  d«      fS |d d fS )NÚ	image_urlÚurlÚformatÚdetail)ÚgetÚ
isinstanceÚdict)r   Úimage_values     úl/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/gemini/chat/transformation.pyÚ_image_url_fieldsr      sP   € Ø$Ÿ™¨Ó5€KÜ�+œtÔ$Ø�‰˜uÓ% {§¡°xÓ'@À+Ç/Á/ÐRZÓB[Ð[Ð[Ø˜˜dÐ"Ð"ó    c                   ó˜  ‡ — e Zd ZU dZdZedz  ed<   dZedz  ed<   dZ	edz  ed<   dZ
edz  ed<   dZedz  ed<   dZedz  ed<   dZedz  ed	<   dZedz  ed
<   	 	 	 	 	 	 	 	 ddedz  dedz  dedz  dedz  dedz  dedz  d	edz  d
edz  ddfd„Zeˆ fd„«       Zdedefd„Zdedee   fd„Z	 	 ddee   dedz  dedz  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_sequencesr   c	                 ó¤   — 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(   Úlocals_ÚkeyÚvalues               r   Ú__init__z#GoogleAIStudioGeminiConfig.__init__<   sF   € ô  ›Ÿ™›ˆØ!Ÿ-™-›/ò 	4‰JˆC�Ø�f‹} Ñ!2Ü˜Ÿ™¨¨UÕ3ñ	4r   c                 ó    •— t         ‰| �  «       S )N)ÚsuperÚ
get_config)Úclsr/   s    €r   r6   z%GoogleAIStudioGeminiConfig.get_configL   s   ø€ ä‰wÑ!Ó#Ð#r   Úmodelc                 ó
   — d|v S )NÚtts© )r*   r8   s     r   Úis_model_gemini_audio_modelz6GoogleAIStudioGeminiConfig.is_model_gemini_audio_modelP   s   € Ø˜ˆ~Ðr   c                 ó°   — g d¢}t        |d¬«      r"|j                  d«       |j                  d«       | j                  |«      r|j                  d«       |S )N)r!   r#   Ú
max_tokensÚmax_completion_tokensÚstreamÚtoolsÚtool_choiceÚ	functionsÚresponse_formatÚnÚstopÚlogprobsÚfrequency_penaltyÚpresence_penaltyÚ
modalitiesÚparallel_tool_callsÚweb_search_optionsÚ$include_server_side_tool_invocationsÚservice_tierÚgemini)Úcustom_llm_providerÚreasoning_effortÚthinkingÚaudio)r   Úappendr<   )r*   r8   Úsupported_paramss      r   Úget_supported_openai_paramsz6GoogleAIStudioGeminiConfig.get_supported_openai_paramsS   sU   € ò#
Ðô* ˜e¸ÕBØ×#Ñ#Ð$6Ô7Ø×#Ñ# JÔ/Ø×+Ñ+¨EÔ2Ø×#Ñ# GÔ,ØÐr   ÚmessagesÚlitellm_paramsc                 ó–  — |D �]%  }|j                  d«      }|€Œt        |t        «      sŒ)g }|D ]ö  }|j                  d«      dk(  rPt        t        |«      }t        |«      \  }	}
}|	sŒ9d|	v sŒ>t        |	|
¬«      }t        |«      }|�	||dœ|d<   Œa||d<   Œg|j                  d«      dk(  sŒ|t        t        |«      }|j                  d«      }|€t        j                  d	|d
¬«      ‚|j                  d«      }|sŒËd|v sd|v sŒÔ	 t        |«      }||d<   |j                  dd«       Œø �Œ( t        |||d
¬«      S # t        $ r Y �Œw xY w)z‚
        Google AI Studio Gemini does not support HTTP/HTTPS URLs for files.
        Convert them to base64 data instead.
        ÚcontentNÚtyper   zhttps://)r   )r   r   ÚfilezFContent block has type='file' but is missing the required 'file' fieldrO   )Úmessager8   Úllm_providerÚfile_idzhttp://Ú	file_data)rW   r8   rX   rP   )r   r   Úlistr   r
   r   r   r   r	   ÚlitellmÚBadRequestErrorr   ÚpopÚ	Exceptionr   )r*   rW   r8   rX   r]   Ú_message_contentÚ_partsÚelementr   Ú
_image_urlr   r   Ú	image_objÚconverted_image_urlÚfile_elementÚ_file_fieldr_   Úbase64_datas                     r   Ú_transform_messagesz.GoogleAIStudioGeminiConfig._transform_messagesp   s…  € ð  ó $	%ˆGØ&Ÿ{™{¨9Ó5ÐØÑ+´
Ð;KÌTÕ0RØ)+�Ø/ò  %�GØ—{‘{ 6Ó*¨kÒ9Ü&*Ô+DÀgÓ&N˜Ü5FÀ{Ó5SÑ2˜
 F¨FÚ%¨*¸
Ò*BÜ(FÀzÐZ`Ô(a˜IÜ2aÐbkÓ2lÐ/Ø%Ð1à+>Ø.4ñ<" ¨KÒ 8ð
 <O ¨KÒ 8Ø Ÿ™ VÓ,°Ó6Ü'+Ô,DÀgÓ'N˜Ø&2×&6Ñ&6°vÓ&>˜Ø&Ð.Ü")×"9Ñ"9Ø(pØ&+Ø-5ô#ð ð
 #.§/¡/°)Ó"<˜Ú"¨	°WÑ(<À
ÈgÒ@Uð%Ü.CÀGÓ.L Ø;F ¨KÑ 8Ø +§¡°	¸4Õ @ò; %ð	$	%ôJ 5ØØØ)Ø (ô	
ð 	
øô $-ò %â $ð%ús   Ä"D;Ä;	EÅE)NNNNNNNN)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   ÚfloatÚ__annotations__r"   Úintr#   r$   r%   Ústrr&   r   r'   r(   ra   r3   Úclassmethodr6   Úboolr<   rV   r   r   ro   Ú__classcell__)r/   s   @r   r    r       s˜  ø… ñð0 !%€K�˜‘Ó$Ø$(Ð�s˜T‘zÓ(Ø€Eˆ5�4‰<ÓØ€Eˆ3�‰:ÓØ%)Ð˜˜d™
Ó)Ø#'€O�T˜D‘[Ó'Ø"&€O�S˜4‘ZÓ&Ø"&€N�D˜4‘KÓ&ð %)Ø(,Ø"Ø Ø)-Ø'+Ø&*Ø&*ñ4à˜T‘\ð4ð  ™:ð4ð �t‰|ð	4ð
 �T‰zð4ð   $™Jð4ð  ™ð4ð ˜t™ð4ð ˜t™ð4ð 
ó4ð  ó$ó ð$ð°ð ¸ó ð °ð  ¸¸c¹ó  ð@ !Ø&*ñ	4
àÐ'Ñ(ð4
ð �T‰zð4
ð ˜t™ð	4
ð
 
ˆkÑ	÷4
r   r    )Útypingr   r   rb   Ú3litellm.litellm_core_utils.prompt_templates.factoryr   r   Ú:litellm.litellm_core_utils.prompt_templates.image_handlingr   Úlitellm.types.llms.openair   r	   r
   Úlitellm.types.llms.vertex_air   r   Úlitellm.utilsr   Úvertex_ai.gemini.transformationr   Ú3vertex_ai.gemini.vertex_and_google_ai_studio_geminir   Útuplerw   r   r    r;   r   r   ú<module>r„      sk   ðß ã ÷õ÷ lÑ kß >Ý ,å TÝ Uð#Ð#<ð #ÀÀsÈTÁzÐSVÐY]ÑS]Ð_bÐeiÑ_iÐGiÑAjó #ôJ
Ð!3õ J
r   