
    j                         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
mZ d dlmZmZ d dlmZ ddlmZ dd	lmZ  G d
 de      Zy)    )ListOptionalcast)/convert_generic_image_chunk_to_openai_image_objconvert_to_anthropic_image_obj)convert_url_to_base64)AllMessageValuesChatCompletionFileObject)ContentTypePartType)supports_reasoning   )%_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fdZdedee   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                         }	|	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               /Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/litellm/llms/gemini/chat/transformation.py__init__z#GoogleAIStudioGeminiConfig.__init__4   sA     (--/!--/JCf}!2U3 *    c                      t         |          S )N)super
get_config)clsr"   s    r&   r+   z%GoogleAIStudioGeminiConfig.get_configD   s    w!##r(   modelc                 
    d|v S )Ntts )r   r-   s     r&   is_model_gemini_audio_modelz6GoogleAIStudioGeminiConfig.is_model_gemini_audio_modelH   s    ~r(   c                     g d}t        |      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
modalitiesparallel_tool_callsweb_search_optionsreasoning_effortthinkingaudio)r   appendr1   )r   r-   supported_paramss      r&   get_supported_openai_paramsz6GoogleAIStudioGeminiConfig.get_supported_openai_paramsK   sS    
$ e$##$67##J/++E2##G,r(   messagesc                    |D ]8  }|j                  d      }|t        |t              s)g }|D ]  }|j                  d      dk(  r|}d}d}t        |j                  d      t              r)|d   j                  d      }|d   j                  d      }n|j                  d      }|szd|v st	        ||      }	t        |	      |d<   |j                  d      d	k(  st        t        |      }
|
d	   j                  d
      }|sd|v sd|v s	 t        |      }||
d	   d<   |
d	   j                  d
d        ; t        |      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type	image_urlurlformatzhttps://)rM   filefile_idzhttp://	file_data)rG   )get
isinstancelistdictr   r   r   r
   r   pop	Exceptionr   )r   rG   message_message_content_partselementimg_element
_image_urlrM   	image_objfile_elementrO   base64_datas                r&   _transform_messagesz.GoogleAIStudioGeminiConfig._transform_messagese   ss     G&{{95+
;KT0R)+/G{{6*k9&-48
04%kook&BDI)4[)A)E)Ee)LJ%0%=%A%A(%KF)4)EJ%*
*B(F *6)I !P$-!" (4
 !V,6'+,Dg'N".v"6":":9"E"	W(<
g@U%.CG.LDOV 4[ A ,V 4 8 8D I7  0	  F 5hGG $- % $%s   (E	EE)NNNNNNNN)__name__
__module____qualname____doc__r   r   float__annotations__r   intr   r   r   strr   rT   r   r   rS   r'   classmethodr+   boolr1   r   rF   r	   r   r`   __classcell__)r"   s   @r&   r   r      st   0 $(K%''+x}+!E8E?!E8C=(,,&*OXd^*%)OXc])%)NHTN) (,+/!%#,0*.)-)-4e_4 $C=4 	4
 }4 %SM4 "$4 "#4 !4 
4  $ $     c  4*H-.*H	k	*Hr(   r   N)typingr   r   r   3litellm.litellm_core_utils.prompt_templates.factoryr   r   :litellm.litellm_core_utils.prompt_templates.image_handlingr   litellm.types.llms.openair	   r
   litellm.types.llms.vertex_air   r   litellm.utilsr   vertex_ai.gemini.transformationr   3vertex_ai.gemini.vertex_and_google_ai_studio_geminir   r   r0   r(   r&   <module>rt      s8    ' ' Q > , T U}H!3 }Hr(   