
    ir                         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dee   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               x/Users/manta/Documents/Projects/TheRoad-I1/.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        |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gemini)custom_llm_providerreasoning_effortthinkingaudio)r   appendr2   )r   r.   supported_paramss      r&   get_supported_openai_paramsz6GoogleAIStudioGeminiConfig.get_supported_openai_paramsK   sU    
& eB##$67##J/++E2##G,r(   messagesc                     |D ]\  }|j                  d      }|t        |t              s)g }|D ],  }|j                  d      dk(  r|}d}d}	d}
t        |j                  d      t              r=|d   j                  d      }|d   j                  d      }	|d   j                  d      }
n|j                  d      }|sd|v st	        ||		      }t        |      }|
	||
d
|d<   ||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 Lw 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formatdetailzhttps://)rQ   )rP   rR   filefile_idzhttp://	file_data)rK   r.   )get
isinstancelistdictr   r   r   r
   r   pop	Exceptionr   )r   rK   r.   message_message_content_partselementimg_element
_image_urlrQ   rR   	image_objconverted_image_urlfile_elementrT   base64_datas                   r&   _transform_messagesz.GoogleAIStudioGeminiConfig._transform_messagesf   s     G&{{95+
;KT0R)+/G{{6*k9&-48
0404%kook&BDI)4[)A)E)Ee)LJ%0%=%A%A(%KF%0%=%A%A(%KF)4)EJ%*
*B(F *6)I !P$-!" 0
  &1+>.4<"K 8
 <OK 8 V,6'+,Dg'N".v"6":":9"E"	W(<
g@U%.CG.LDOV 4[ A ,V 4 8 8D II  0	  X 5heTT $- % $%s   5(E00	E=<E=)NNNNNNNNr*   )__name__
__module____qualname____doc__r   r   float__annotations__r   intr   r   r   strr   rY   r   r   rX   r'   classmethodr,   boolr2   r   rJ   r	   r   rf   __classcell__)r"   s   @r&   r   r      s   0 $(K%''+x}+!E8E?!E8C=(,,&*OXd^*%)OXc])%)NHTN) (,+/!%#,0*.)-)-4e_4 $C=4 	4
 }4 %SM4 "$4 "#4 !4 
4  $ $     c  8 HL3U-.3U7?}3U	k	3U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   r1   r(   r&   <module>rz      s8    ' ' Q > , T UGU!3 GUr(   