o
    %g                 	   @   s>  d dl Z d dlmZmZmZmZmZmZ d dlm	Z	 ddl
mZ ddl
mZ ddl
mZ ddl
mZ dd	l
mZ dd
lmZ ddlmZ ddlmZ ddlmZmZ e dZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ 	ddedeeef dee defddZ!	ddedeeef dee defddZ"	ddedeeef dee defddZ#	ddedeeef dee defdd Z$	ddedeeef dee defd!d"Z%	ddedeeef dee defd#d$Z&	ddedeeef dee defd%d&Z'	ddedeeef dee defd'd(Z(	ddedeeef dee defd)d*Z)	ddedeeef dee defd+d,Z*	ddedeeef dee defd-d.Z+	ddedeeef dee defd/d0Z,	ddedeeef dee defd1d2Z-	ddedeeef dee defd3d4Z.	ddedeeef dee defd5d6Z/	ddedeeef dee defd7d8Z0	ddedeeef dee defd9d:Z1	ddedeeef dee defd;d<Z2	ddedeeef dee defd=d>Z3	ddedeeef dee defd?d@Z4	ddedeeef dee defdAdBZ5	ddedeeef dee defdCdDZ6	ddedeeef dee defdEdFZ7	ddedeeef dee defdGdHZ8	ddedeeef dee defdIdJZ9	ddedeeef dee defdKdLZ:	ddedeeef dee defdMdNZ;	ddedeeef dee defdOdPZ<	ddedeeef dee defdQdRZ=	ddedeeef dee defdSdTZ>	ddedeeef dee defdUdVZ?	ddedeeef dee defdWdXZ@	ddedeeef dee defdYdZZA	ddedeeef dee defd[d\ZB	ddedeeef dee defd]d^ZC	ddedeeef dee defd_d`ZD	ddedeeef dee defdadbZE	ddedeeef dee defdcddZF	ddedeeef dee defdedfZG	ddedeeef dee defdgdhZH	ddedeeef dee defdidjZI	ddedeeef dee defdkdlZJ	ddedeeef dee defdmdnZK	ddedeeef dee defdodpZL	ddedeeef dee defdqdrZM	ddedeeef dee defdsdtZN	ddedeeef dee defdudvZO	ddedeeef dee defdwdxZP	ddedeeef dee defdydzZQ	ddedeeef dee defd{d|ZR	ddedeeef dee defd}d~ZS	ddedeeef dee defddZT	ddedeeef dee defddZU	ddedeeef dee defddZV	ddedeeef dee defddZW	ddedeeef dee defddZX	ddedeeef dee defddZY	ddedeeef dee defddZZ	ddedeeef dee defddZ[	ddedeeef dee defddZ\	ddedeeef dee defddZ]	ddedeeef dee defddZ^	ddedeeef dee defddZ_	ddedeeef dee defddZ`	ddedeeef dee defddZa	ddedeeef dee defddZb	ddedeeef dee defddZc	ddedeeef dee defddZd	ddedeeef dee defddZe	ddedeeef dee defddZf	ddedeeef dee defddZgdefddZhdefddZi	ddedeeef dee defddZj	ddedeeef dee defddZk	ddedeeef dee defddZl	ddedeeef dee defddZm	ddedeeef dee defddZn	ddedeeef dee defddZo	ddedeeef dee defddZp	ddedeeef dee defddZq	ddedeeef dee defddZr	ddedeeef dee defddZs	ddedeeef dee defddZt	ddedeeef dee defddÄZu	ddedeeef dee defddńZv	ddedeeef dee defddǄZw	ddedeeef dee defddɄZx	ddedeeef dee defdd˄Zy	ddedeeef dee defdd̈́Zz	ddedeeef dee defddτZ{	ddedeeef dee defddфZ|	ddedeeef dee defddӄZ}	ddedeeef dee defddՄZ~	ddedeeef dee defddׄZ	ddedeeef dee defddلZ	ddedeeef dee defddۄZ	ddedeeef dee defdd݄Z	ddedeeef dee defdd߄Z	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defd dZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defddZ	ddedeeef dee defdd	Z	ddedeeef dee defd
dZ	ddedeeef dee defddZG dd dejZG dd dejZdS (      N)AnyAsyncIterator	AwaitableIteratorOptionalUnion)	urlencode   )_api_module)_common)_extra_utils)_transformers)types)BaseApiClient)get_value_by_path)set_value_by_path)
AsyncPagerPagerzgoogle_genai.models
api_clientfrom_objectparent_objectreturnc                 C   sP  i }t |dgd urtdt |dgd ur!t|dgt |dg t |dgd ur4t|dgt |dg t |dgd urGt|dgt |dg t |dgd urZt|d	gt |dg t |d
gd urmt|dgt |d
g t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg |S )Nvideo_metadataz8video_metadata parameter is not supported in Gemini API.thoughtcode_execution_resultcodeExecutionResultexecutable_codeexecutableCode	file_datafileDatafunction_callfunctionCallfunction_responsefunctionResponseinline_data
inlineDatatextgetv
ValueErrorsetvr   r   r   	to_object r-   U/mnt/skqttb/ctump_chatbot/chatbot/lib/python3.10/site-packages/google/genai/models.py_Part_to_mldev"   s8   

r/   c                    d   i t |dgd urtdg fddt |dgD  t |dgd ur0tdgt |dg S )Npartsc                       g | ]}t  |qS r-   )r/   .0itemr   r,   r-   r.   
<listcomp>X       
z%_Content_to_mldev.<locals>.<listcomp>roler(   r*   r   r   r   r-   r6   r.   _Content_to_mldevN      
	r<   c                 C   s  i }t |dgd urtdt |dgd urtdt |dgd ur&tdt |dgd ur2tdt |d	gd ur>td
t |dgd urJtdt |dgd urVtdt |dgd urit|dgt |dg t |dgd ur|t|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd ur*t|dgt |dg t |dgd ur>t|dgt |dg t |dgd urRt|dgt |dg t |d gd urft|d gt |d g t |d!gd urzt|d!gt |d!g |S )"Nexamplez1example parameter is not supported in Gemini API.patternz1pattern parameter is not supported in Gemini API.defaultz1default parameter is not supported in Gemini API.
max_lengthz4max_length parameter is not supported in Gemini API.
min_lengthz4min_length parameter is not supported in Gemini API.min_propertiesz8min_properties parameter is not supported in Gemini API.max_propertiesz8max_properties parameter is not supported in Gemini API.any_ofanyOfdescriptionenumformatitems	max_itemsmaxItemsmaximum	min_itemsminItemsminimumnullable
propertiesproperty_orderingpropertyOrderingrequiredtitletyper'   r+   r-   r-   r.   _Schema_to_mldevd   sd   
rX   c                 C   sl   i }t |dgd urtdt |dgd ur!t|dgt |dg t |dgd ur4t|dgt |dg |S )Nmethodz0method parameter is not supported in Gemini API.category	thresholdr'   r+   r-   r-   r.   _SafetySetting_to_mldev   s   r\   c                 C   s   i }t |dgd urtdt |dgd ur!t|dgt |dg t |dgd ur4t|dgt |dg t |dgd urGt|dgt |dg |S )Nresponsez2response parameter is not supported in Gemini API.rG   name
parametersr'   r+   r-   r-   r.   _FunctionDeclaration_to_mldev   s   r`   c                 C      i }|S Nr-   r+   r-   r-   r.   _GoogleSearch_to_mldev      rc   c                 C   T   i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg |S Nmodedynamic_thresholddynamicThresholdr:   r+   r-   r-   r.    _DynamicRetrievalConfig_to_mldev      
rj   c                 C   6   i }t |dgd urt|dgt| t |dg| |S Ndynamic_retrieval_configdynamicRetrievalConfig)r(   r*   rj   r+   r-   r-   r.   _GoogleSearchRetrieval_to_mldev      

rp   c                    s   i t |dgd urtdg fddt |dgD  t |dgd ur)tdt |dgd ur@tdgt t |dg t |d	gd urWtd
gt t |d	g t |dgd urjtdgt |dg S )Nfunction_declarationsfunctionDeclarationsc                    r2   r-   )r`   r3   r6   r-   r.   r7     r8   z"_Tool_to_mldev.<locals>.<listcomp>	retrievalz3retrieval parameter is not supported in Gemini API.google_searchgoogleSearchgoogle_search_retrievalgoogleSearchRetrievalcode_executioncodeExecution)r(   r*   r)   rc   rp   r;   r-   r6   r.   _Tool_to_mldev  s@   
	

r{   c                 C   re   Nrg   allowed_function_namesallowedFunctionNamesr:   r+   r-   r-   r.   _FunctionCallingConfig_to_mldev8  rk   r   c                 C   rl   Nfunction_calling_configfunctionCallingConfig)r(   r*   r   r+   r-   r-   r.   _ToolConfig_to_mldevK  rq   r   c                 C   .   i }t |dgd urt|dgt |dg |S N
voice_name	voiceNamer:   r+   r-   r-   r.   _PrebuiltVoiceConfig_to_mldev_     r   c                 C   rl   Nprebuilt_voice_configprebuiltVoiceConfig)r(   r*   r   r+   r-   r-   r.   _VoiceConfig_to_mldevk     r   c                 C   rl   Nvoice_configvoiceConfig)r(   r*   r   r+   r-   r-   r.   _SpeechConfig_to_mldev}  r   r   c                 C   r   Ninclude_thoughtsincludeThoughtsr:   r+   r-   r-   r.   _ThinkingConfig_to_mldev     r   c                    s  i t |dgd urt|dgt t t |dg t |dgd ur0tdgt |dg t |dgd urCtdgt |dg t |dgd urVtdgt |dg t |dgd uritd	gt |dg t |d
gd ur|tdgt |d
g t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt t t |dg t |dgd ur+tdt |dgd urGt|dg fddt |dgD  t |d gd urgt|d g fd!dt t |d gD  t |d"gd urt|d#gt	 t |d"g t |d$gd urtd%t |d&gd urt|d'gt
 t |d&g t |d(gd urtd)gt |d(g t |d*gd urtd+gt |d*g t |d,gd urtd-gt t t |d,g t |d.gd urtd/t |d0gd urtd1gt t |d0g S )2Nsystem_instructionsystemInstructiontemperaturetop_ptopPtop_ktopKcandidate_countcandidateCountmax_output_tokensmaxOutputTokensstop_sequencesstopSequencesresponse_logprobsresponseLogprobslogprobspresence_penaltypresencePenaltyfrequency_penaltyfrequencyPenaltyseedresponse_mime_typeresponseMimeTyperesponse_schemaresponseSchemarouting_configz8routing_config parameter is not supported in Gemini API.safety_settingssafetySettingsc                    r2   r-   )r\   r3   r6   r-   r.   r7     r8   z3_GenerateContentConfig_to_mldev.<locals>.<listcomp>toolsc                        g | ]}t  t |qS r-   )r{   tt_toolr3   r6   r-   r.   r7         tool_config
toolConfiglabelsz0labels parameter is not supported in Gemini API.cached_contentcachedContentresponse_modalitiesresponseModalitiesmedia_resolutionmediaResolutionspeech_configspeechConfigaudio_timestampz9audio_timestamp parameter is not supported in Gemini API.thinking_configthinkingConfig)r(   r*   r<   r   	t_contentrX   t_schemar)   t_toolsr   t_cached_content_namer   t_speech_configr   r;   r-   r6   r.   _GenerateContentConfig_to_mldev  s  





		

r   c              
         i t |dgd urtddgt t |dg t |dgd ur9tdg fddt t |dgD  t |dgd urPtdgt t |dg S )Nmodel_urlcontentsc                    r2   r-   r<   r3   r6   r-   r.   r7   S  r8   z7_GenerateContentParameters_to_mldev.<locals>.<listcomp>configgenerationConfig)r(   r*   r   t_model
t_contentsr   r;   r-   r6   r.   #_GenerateContentParameters_to_mldevB  4   r   c                 C   s   i }t |dgd urt|ddgt |dg t |dgd ur*t|ddgt |dg t |dgd ur>t|ddgt |dg t |dgd urJtdt |d	gd urVtd
|S )N	task_type
requests[]taskTyperV   output_dimensionalityoutputDimensionality	mime_typez3mime_type parameter is not supported in Gemini API.auto_truncatez7auto_truncate parameter is not supported in Gemini API.r(   r*   r)   r+   r-   r-   r.   _EmbedContentConfig_to_mldevg  s(   

r   c              	   C   s   i }t |dgd urt|ddgt| t |dg t |dgd ur2t|ddgt| t |dg t |dgd urIt|dgt| t |dg| t|ddgt| t |dg |S )Nr   r   r   r   contentr   )r(   r*   r   r   t_contents_for_embedr   r+   r-   r-   r.    _EmbedContentParameters_to_mldev  s6   r   c                 C   s4  i }t |dgd urtdt |dgd urtdt |dgd ur.t|ddgt |dg t |dgd urBt|dd	gt |dg t |d
gd urVt|ddgt |d
g t |dgd urbtdt |dgd ur~tt |dg t|ddgt |dg t |dgd urtt |dg t|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|g dt |dg t |dgd urt|g dt |dg t |dgd urtdt |dgd urtd|S )Noutput_gcs_uri8output_gcs_uri parameter is not supported in Gemini API.negative_promptz9negative_prompt parameter is not supported in Gemini API.number_of_imagesr_   sampleCountaspect_ratioaspectRatioguidance_scaleguidanceScaler   .seed parameter is not supported in Gemini API.safety_filter_levelsafetySettingperson_generationpersonGenerationinclude_safety_attributesincludeSafetyAttributesinclude_rai_reasonincludeRaiReasonlanguageoutput_mime_typer_   outputOptionsmimeTypeoutput_compression_qualityr_   r   compressionQualityadd_watermarkz7add_watermark parameter is not supported in Gemini API.enhance_prompt8enhance_prompt parameter is not supported in Gemini API.)r(   r)   r*   )_SafetyFilterLevel_to_mldev_enum_validate(_PersonGeneration_to_mldev_enum_validater+   r-   r-   r.   _GenerateImagesConfig_to_mldev  s   











r  c              	   C      i }t |dgd urt|ddgt| t |dg t |dgd ur.t|ddgt |dg t |dgd urEt|dgt| t |dg| |S Nr   r   promptinstances[0]r   )r(   r*   r   r   r  r+   r-   r-   r.   "_GenerateImagesParameters_to_mldev  $   r  c              	   C   ^   i }t |dgd urt|ddgt| t |dg t |dgd ur-t|dgt |dg |S Nr   r   r^   r   r(   r*   r   r   r+   r-   r-   r.   _GetModelParameters_to_mldev0     r  c              	   C      i }t |dgd urt|ddgt |dg t |dgd ur*t|ddgt |dg t |dgd ur>t|ddgt |dg t |dgd urVt|dd	gt| t |dg |S 
N	page_size_querypageSize
page_token	pageTokenfilter
query_baser   
models_urlr(   r*   r   t_models_urlr+   r-   r-   r.   _ListModelsConfig_to_mldevC  (   
r  c                 C   6   i }t |dgd urt|dgt| t |dg| |S Nr   )r(   r*   r  r+   r-   r-   r.   _ListModelsParameters_to_mldevc  r   r  c                 C   T   i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg |S Ndisplay_namedisplayNamerG   r:   r+   r-   r-   r.   _UpdateModelConfig_to_mldevu     r$  c              	   C   sf   i }t |dgd urt|ddgt| t |dg t |dgd ur1t|dgt| t |dg| |S r  )r(   r*   r   r   r$  r+   r-   r-   r.   _UpdateModelParameters_to_mldev      r&  c              	   C   r
  r  r  r+   r-   r-   r.   _DeleteModelParameters_to_mldev  r  r(  c                 C   sP   i }t |dgd urtdt |dgd urtdt |dgd ur&td|S )Nr   z<system_instruction parameter is not supported in Gemini API.r   z/tools parameter is not supported in Gemini API.generation_configz;generation_config parameter is not supported in Gemini API.)r(   r)   r+   r-   r-   r.   _CountTokensConfig_to_mldev  s   r*  c              
         i t |dgd urtddgt t |dg t |dgd ur9tdg fddt t |dgD  t |dgd urPtdgt t |dg S )Nr   r   r   c                    r2   r-   r   r3   r6   r-   r.   r7     r8   z3_CountTokensParameters_to_mldev.<locals>.<listcomp>r   )r(   r*   r   r   r   r*  r;   r-   r6   r.   _CountTokensParameters_to_mldev  r   r,  c              	   C   st   i }t |dgd urtdt |dgd ur%t|dgt| t |dg t |dgd ur8t|dgt |dg |S )Ngcs_uriz1gcs_uri parameter is not supported in Gemini API.image_bytesbytesBase64Encodedr   r   )r(   r)   r*   r   t_bytesr+   r-   r-   r.   _Image_to_mldev  s   r1  c                 C   s`  i }t |dgd urt|ddgt |dg t |dgd ur"tdt |dgd ur.tdt |dgd urBt|dd	gt |dg t |d
gd urNtdt |dgd urbt|ddgt |dg t |dgd urntdt |dgd urt|ddgt |dg t |dgd urtdt |dgd urt|ddgt |dg t |dgd urtd|S )Nnumber_of_videosr_   r   r   r   fpsz-fps parameter is not supported in Gemini API.duration_secondsdurationSecondsr   r   r   r   
resolutionz4resolution parameter is not supported in Gemini API.r   r   pubsub_topicz6pubsub_topic parameter is not supported in Gemini API.r   negativePromptr   r   r   r+   r-   r-   r.   _GenerateVideosConfig_to_mldev  sX   




r9  c              	   C      i }t |dgd urt|ddgt| t |dg t |dgd ur.t|ddgt |dg t |dgd urFt|ddgt| t |dg| t |dgd ur]t|dgt| t |dg| |S Nr   r   r  r  imager   )r(   r*   r   r   r1  r9  r+   r-   r-   r.   "_GenerateVideosParameters_to_mldevB  0   r=  c                 C   ^  i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg t |dgd ur;t|dgt |dg t |dgd urNt|dgt |dg t |dgd urat|d	gt |dg t |d
gd urtt|dgt |d
g t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg |S )Nr   videoMetadatar   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r:   r+   r-   r-   r.   _Part_to_vertexe  8   

rA  c                    r0   )Nr1   c                    r2   r-   )rA  r3   r6   r-   r.   r7     r8   z&_Content_to_vertex.<locals>.<listcomp>r9   r:   r;   r-   r6   r.   _Content_to_vertex  r=   rC  c                 C   s^  i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg t |dgd ur;t|dgt |dg t |dgd urNt|dgt |dg t |dgd urat|dgt |dg t |dgd urtt|d	gt |dg t |d
gd urt|dgt |d
g t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd ur!t|dgt |dg t |dgd ur5t|dgt |dg t |dgd urIt|dgt |dg t |dgd ur]t|dgt |dg t |dgd urqt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg |S )Nr>   r?   r@   rA   	maxLengthrB   	minLengthrC   minPropertiesrD   maxPropertiesrE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   r:   r+   r-   r-   r.   _Schema_to_vertex  sd   
rH  c                 C   sz   i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg t |dgd ur;t|dgt |dg |S )NrY   rZ   r[   r:   r+   r-   r-   r.   _SafetySetting_to_vertex     rI  c                 C   s   i }t |dgd urt|dgt| t |dg| t |dgd ur,t|dgt |dg t |dgd ur?t|dgt |dg t |dgd urRt|dgt |dg |S )Nr]   rG   r^   r_   )r(   r*   rH  r+   r-   r-   r.   _FunctionDeclaration_to_vertex  s    rK  c                 C   ra   rb   r-   r+   r-   r-   r.   _GoogleSearch_to_vertex#  rd   rL  c                 C   re   rf   r:   r+   r-   r-   r.   !_DynamicRetrievalConfig_to_vertex-  rk   rM  c                 C   rl   rm   )r(   r*   rM  r+   r-   r-   r.    _GoogleSearchRetrieval_to_vertex@  rq   rN  c                    s   i t |dgd urtdg fddt |dgD  t |dgd ur0tdgt |dg t |dgd urGtdgt t |dg t |dgd ur^td	gt t |dg t |d
gd urqtdgt |d
g S )Nrr   rs   c                    r2   r-   )rK  r3   r6   r-   r.   r7   ^  r8   z#_Tool_to_vertex.<locals>.<listcomp>rt   ru   rv   rw   rx   ry   rz   )r(   r*   rL  rN  r;   r-   r6   r.   _Tool_to_vertexT  s@   
	

rO  c                 C   re   r|   r:   r+   r-   r-   r.    _FunctionCallingConfig_to_vertex  rk   rP  c                 C   rl   r   )r(   r*   rP  r+   r-   r-   r.   _ToolConfig_to_vertex  rq   rQ  c                 C   r   r   r:   r+   r-   r-   r.   _PrebuiltVoiceConfig_to_vertex  r   rR  c                 C   rl   r   )r(   r*   rR  r+   r-   r-   r.   _VoiceConfig_to_vertex  r   rS  c                 C   rl   r   )r(   r*   rS  r+   r-   r-   r.   _SpeechConfig_to_vertex  r   rT  c                 C   r   r   r:   r+   r-   r-   r.   _ThinkingConfig_to_vertex  r   rU  c                    sH  i t |dgd urt|dgt t t |dg t |dgd ur0tdgt |dg t |dgd urCtdgt |dg t |dgd urVtdgt |dg t |dgd uritd	gt |dg t |d
gd ur|tdgt |d
g t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt |dg t |dgd urtdgt t t |dg t |dgd ur2tdgt |dg t |dgd urNt|dg fddt |dgD  t |d gd urnt|d g fd!dt t |d gD  t |d"gd urt|d#gt t |d"g t |d$gd urt|d$gt |d$g t |d%gd urt|d&gt	 t |d%g t |d'gd urtd(gt |d'g t |d)gd urtd*gt |d)g t |d+gd urtd,gt
 t t |d+g t |d-gd ur
td.gt |d-g t |d/gd ur"td0gt t |d/g S )1Nr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   routingConfigr   r   c                    r2   r-   )rI  r3   r6   r-   r.   r7   >  r8   z4_GenerateContentConfig_to_vertex.<locals>.<listcomp>r   c                    r   r-   )rO  r   r   r3   r6   r-   r.   r7   H  r   r   r   r   r   r   r   r   r   r   r   r   r   audioTimestampr   r   )r(   r*   rC  r   r   rH  r   r   rQ  r   rT  r   rU  r;   r-   r6   r.    _GenerateContentConfig_to_vertex  s   





		

rX  c              
      r   )Nr   r   r   c                    r2   r-   rC  r3   r6   r-   r.   r7     r8   z8_GenerateContentParameters_to_vertex.<locals>.<listcomp>r   r   )r(   r*   r   r   r   rX  r;   r-   r6   r.   $_GenerateContentParameters_to_vertex  r   rZ  c                 C   s   i }t |dgd urt|ddgt |dg t |dgd ur*t|ddgt |dg t |dgd ur>t|ddgt |dg t |dgd urRt|ddgt |dg t |d	gd urft|dd
gt |d	g |S )Nr   instances[]rV   r   r_   r   r   r   r   autoTruncater:   r+   r-   r-   r.   _EmbedContentConfig_to_vertex  s8   



r]  c              	   C   s   i }t |dgd urt|ddgt| t |dg t |dgd ur2t|ddgt| t |dg t |dgd urIt|dgt| t |dg| |S )Nr   r   r   r[  r   r   )r(   r*   r   r   r   r]  r+   r-   r-   r.   !_EmbedContentParameters_to_vertex  s,   r^  c                 C   sf  i }t |dgd urt|ddgt |dg t |dgd ur*t|ddgt |dg t |dgd ur>t|ddgt |dg t |dgd urRt|dd	gt |dg t |d
gd urft|ddgt |d
g t |dgd urzt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|g dt |dg t |dgd urt|g dt |dg t |dgd urt|ddgt |dg t |dgd ur1t|ddgt |dg |S )Nr   r_   
storageUrir   r8  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   addWatermarkr   enhancePromptr:   r+   r-   r-   r.   _GenerateImagesConfig_to_vertex     













rb  c              	   C   r  r  )r(   r*   r   r   rb  r+   r-   r-   r.   #_GenerateImagesParameters_to_vertexf  r	  rd  c              	   C      i }t |dgd urt|dgt |dg t |dgd ur,t|dgt| t |dg t |dgd ur?t|dgt |dg |S )Nr-  gcsUrir.  r/  r   r   r(   r*   r   r0  r+   r-   r-   r.   _Image_to_vertex     rh  c                 C   z   i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg t |dgd ur;t|dgt |dg |S )N	mask_modemaskModesegmentation_classesmaskClassesmask_dilationdilationr:   r+   r-   r-   r.   _MaskReferenceConfig_to_vertex  s   rq  c                 C   T   i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg |S )Ncontrol_typecontrolType enable_control_image_computationcomputeControlr:   r+   r-   r-   r.   !_ControlReferenceConfig_to_vertex  rk   rw  c                 C   r   )Nstyle_descriptionstyleDescriptionr:   r+   r-   r-   r.   _StyleReferenceConfig_to_vertex     
rz  c                 C   rr  )Nsubject_typesubjectTypesubject_descriptionsubjectDescriptionr:   r+   r-   r-   r.   !_SubjectReferenceConfig_to_vertex  rk   r  c                 C   s:  i }t |dgd urt|dgt| t |dg| t |dgd ur,t|dgt |dg t |dgd ur?t|dgt |dg t |dgd urVt|dgt| t |dg| t |d	gd urmt|d
gt| t |d	g| t |dgd urt|dgt| t |dg| t |dgd urt|dgt| t |dg| |S )Nreference_imagereferenceImagereference_idreferenceIdreference_typereferenceTypemask_image_configmaskImageConfigcontrol_image_configcontrolImageConfigstyle_image_configstyleImageConfigsubject_image_configsubjectImageConfig)r(   r*   rh  rq  rw  rz  r  r+   r-   r-   r.   _ReferenceImageAPI_to_vertex  s\   r  c                 C   sf  i }t |dgd urt|ddgt |dg t |dgd ur*t|ddgt |dg t |dgd ur>t|ddgt |dg t |dgd urRt|dd	gt |dg t |d
gd urft|ddgt |d
g t |dgd urzt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|g dt |dg t |dgd urt|g dt |dg t |dgd urt|ddgt |dg t |dgd ur1t|g dt |dg |S )Nr   r_   r_  r   r8  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	edit_modeeditMode
base_steps)r_   
editConfig	baseStepsr:   r+   r-   r-   r.   _EditImageConfig_to_vertex  rc  r  c              	      s   i t |dgd urtddgt t |dg t |dgd ur.tddgt |dg t |dgd urJtddg fddt |dgD  t |d	gd uratd	gt t |d	g S )
Nr   r   r  r  reference_imagesreferenceImagesc                    r2   r-   )r  r3   r6   r-   r.   r7     r8   z2_EditImageParameters_to_vertex.<locals>.<listcomp>r   )r(   r*   r   r   r  r;   r-   r6   r.   _EditImageParameters_to_vertex  s4   
	r  c                 C   s   i }t |dgd urt|ddgt |dg t |dgd ur*t|g dt |dg t |dgd ur>t|g dt |dg t |dgd urRt|dd	gt |dg t |d
gd urft|dd
gt |d
g |S )Nr   r_   r   r   r   r   r   r   r   rg   r:   r+   r-   r-   r.    _UpscaleImageAPIConfig_to_vertex  s8   



r  c              	   C   s   i }t |dgd urt|ddgt| t |dg t |dgd ur2t|ddgt| t |dg| t |dgd urFt|g dt |dg t |dgd ur]t|dgt| t |dg| |S )Nr   r   r<  r  upscale_factor)r_   upscaleConfigupscaleFactorr   )r(   r*   r   r   rh  r  r+   r-   r-   r.   $_UpscaleImageAPIParameters_to_vertex  s8   
r  c              	   C   r
  r  r  r+   r-   r-   r.   _GetModelParameters_to_vertex	  r  r  c              	   C   r  r  r  r+   r-   r-   r.   _ListModelsConfig_to_vertex	  r  r  c                 C   r  r  )r(   r*   r  r+   r-   r-   r.   _ListModelsParameters_to_vertex6	  r   r  c                 C   r   r!  r:   r+   r-   r-   r.   _UpdateModelConfig_to_vertexH	  r%  r  c              	   C   sf   i }t |dgd urt|ddgt| t |dg t |dgd ur1t|dgt| t |dg| |S )Nr   r   r   )r(   r*   r   r   r  r+   r-   r-   r.    _UpdateModelParameters_to_vertexX	  r'  r  c              	   C   r
  r  r  r+   r-   r-   r.    _DeleteModelParameters_to_vertexq	  r  r  c                    s   i t |dgd urt|dgt t t |dg t |dgd ur8t|dg fddt |dgD  t |dgd urKt|dgt |dg S )Nr   r   r   c                    r2   r-   )rO  r3   r6   r-   r.   r7   	  r8   z0_CountTokensConfig_to_vertex.<locals>.<listcomp>r)  r   )r(   r*   rC  r   r   r;   r-   r6   r.   _CountTokensConfig_to_vertex	  s4   

	
r  c              
      r+  )Nr   r   r   c                    r2   r-   rY  r3   r6   r-   r.   r7   	  r8   z4_CountTokensParameters_to_vertex.<locals>.<listcomp>r   )r(   r*   r   r   r   r  r;   r-   r6   r.    _CountTokensParameters_to_vertex	  r   r  c              
      s   i t |dgd urtddgt t |dg t |dgd ur9tdg fddt t |dgD  t |dgd urLtdgt |dg S )Nr   r   r   c                    r2   r-   rY  r3   r6   r-   r.   r7   	  r8   z6_ComputeTokensParameters_to_vertex.<locals>.<listcomp>r   )r(   r*   r   r   r   r;   r-   r6   r.   "_ComputeTokensParameters_to_vertex	  s(   r  c                 C   s  i }t |dgd urt|ddgt |dg t |dgd ur*t|ddgt |dg t |dgd ur>t|ddgt |dg t |dgd urRt|ddgt |dg t |d	gd urft|dd	gt |d	g t |d
gd urzt|ddgt |d
g t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg t |dgd urt|ddgt |dg |S )Nr2  r_   r   r   r_  r3  r4  r5  r   r   r   r6  r   r   r7  pubsubTopicr   r8  r   ra  r:   r+   r-   r-   r.   _GenerateVideosConfig_to_vertex	  sx   








r  c              	   C   r:  r;  )r(   r*   r   r   rh  r  r+   r-   r-   r.   #_GenerateVideosParameters_to_vertex=
  r>  r  
enum_valuec                 C       | t dgv rt|  dd S )N
BLOCK_NONE+ enum value is not supported in Gemini API.setr)   r  r-   r-   r.   r  `
     r  c                 C   r  )N	ALLOW_ALLr  r  r  r-   r-   r.   r  e
  r  r  c                 C   s8  i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg t |dgd ur;t|dgt |dg t |dgd urNt|dgt |dg t |dgd urat|d	gt |dg t |d
gd urtt|dgt |d
g t |dgd urt|dgt |dg t |dgd urt|dgt |dg |S )Nr   r   r   r   r   r   r   r!   r    r#   r"   r%   r$   r&   r:   r+   r-   r-   r.   _Part_from_mldevj
  s4   

r  c                    r0   )Nr1   c                    r2   r-   )r  r3   r6   r-   r.   r7   
  r8   z'_Content_from_mldev.<locals>.<listcomp>r9   r:   r;   r-   r6   r.   _Content_from_mldev
  r=   r  c                 C   r   )NcitationSources	citationsr:   r+   r-   r-   r.   _CitationMetadata_from_mldev
  r   r  c                 C   n  i }t |dgd urt|dgt| t |dg| t |dgd ur0t|dgt| t |dg| t |dgd urCt|dgt |dg t |dgd urVt|dgt |dg t |dgd urit|d	gt |dg t |d
gd ur|t|dgt |d
g t |dgd urt|dgt |dg t |dgd urt|dgt |dg t |dgd urt|dgt |dg |S )Nr   citationMetadatacitation_metadata
tokenCounttoken_countfinishReasonfinish_reasonavgLogprobsavg_logprobsgroundingMetadatagrounding_metadataindexlogprobsResultlogprobs_resultsafetyRatingssafety_ratings)r(   r*   r  r  r+   r-   r-   r.   _Candidate_from_mldev
  H   
r  c                    s   i t |dgd urtdg fddt |dgD  t |dgd ur0tdgt |dg t |dgd urCtdgt |dg t |dgd urVtd	gt |dg S )
N
candidatesc                    r2   r-   )r  r3   r6   r-   r.   r7   
  r8   z7_GenerateContentResponse_from_mldev.<locals>.<listcomp>modelVersionmodel_versionpromptFeedbackprompt_feedbackusageMetadatausage_metadatar:   r;   r-   r6   r.   #_GenerateContentResponse_from_mldev
  s    
	r  c                 C   ra   rb   r-   r+   r-   r-   r.   &_ContentEmbeddingStatistics_from_mldev  rd   r  c                 C   .   i }t |dgd urt|dgt |dg |S )Nvaluesr:   r+   r-   r-   r.   _ContentEmbedding_from_mldev  r   r  c                 C   ra   rb   r-   r+   r-   r-   r.    _EmbedContentMetadata_from_mldev  rd   r  c                    sl   i t |dgd urtdg fddt |dgD  t |dgd ur4tdgt t |dg S )N
embeddingsc                    r2   r-   )r  r3   r6   r-   r.   r7   0  r8   z4_EmbedContentResponse_from_mldev.<locals>.<listcomp>metadata)r(   r*   r  r;   r-   r6   r.    _EmbedContentResponse_from_mldev&  s$   
	r  c              	   C   s\   i }t |dgd urt|dgt| t |dg t |dgd ur,t|dgt |dg |S )Nr/  r.  r   r   rg  r+   r-   r-   r.   _Image_from_mldevB  s   r  c                 C      i }t |ddgd urt|dgt |ddg t |ddgd ur,t|dgt |ddg t |dgd ur?t|dgt |dg |S NsafetyAttributes
categoriesscorescontentTypecontent_typer:   r+   r-   r-   r.   _SafetyAttributes_from_mldevV     r  c                 C   s   i }t |dgd urt|dgt| t |dg| t |dgd ur,t|dgt |dg t |dgd urCt|dgt| t |dg| |S )N_selfr<  raiFilteredReasonrai_filtered_reasonsafety_attributes)r(   r*   r  r  r+   r-   r-   r.   _GeneratedImage_from_mldevn  s,   
r  c                    l   i t |dgd urtdg fddt |dgD  t |dgd ur4tdgt t |dg S )Npredictionsgenerated_imagesc                    r2   r-   )r  r3   r6   r-   r.   r7     r8   z6_GenerateImagesResponse_from_mldev.<locals>.<listcomp>positivePromptSafetyAttributes!positive_prompt_safety_attributes)r(   r*   r  r;   r-   r6   r.   "_GenerateImagesResponse_from_mldev  (   
	

r  c                 C   ra   rb   r-   r+   r-   r-   r.   _Endpoint_from_mldev  rd   r  c                 C   rj  )N	baseModel
base_model
createTimecreate_time
updateTimeupdate_timer:   r+   r-   r-   r.   _TunedModelInfo_from_mldev  rJ  r  c                 C   s@  i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg t |dgd ur;t|dgt |dg t |dgd urNt|dgt |dg t |dgd uret|dgt| t |dg| t |dgd urxt|d	gt |dg t |d
gd urt|dgt |d
g t |dgd urt|dgt |dg |S )Nr^   r#  r"  rG   versionr  tuned_model_infoinputTokenLimitinput_token_limitoutputTokenLimitoutput_token_limitsupportedGenerationMethodssupported_actions)r(   r*   r  r+   r-   r-   r.   _Model_from_mldev  sD   

r   c              
      l   i t |dgd urtdgt |dg t |dgd ur4tdg fddt t |dgD  S )NnextPageTokennext_page_tokenr  modelsc                    r2   r-   )r   r3   r6   r-   r.   r7     r8   z2_ListModelsResponse_from_mldev.<locals>.<listcomp>r(   r*   r   t_extract_modelsr;   r-   r6   r.   _ListModelsResponse_from_mldev     r  c                 C   ra   rb   r-   r+   r-   r-   r.   _DeleteModelResponse_from_mldev  rd   r	  c                 C   rr  )NtotalTokenstotal_tokenscachedContentTokenCountcached_content_token_countr:   r+   r-   r-   r.   _CountTokensResponse_from_mldev  rk   r  c              
   C   s   i }t |ddgd urt|dgt |ddg t |ddgd ur0t|dgt| t |ddg t |dgd urCt|dgt |dg |S )NvideouriencodedVideovideo_bytesencodingr   rg  r+   r-   r-   r.   _Video_from_mldev.  s   r  c                 C   rl   Nr  r  )r(   r*   r  r+   r-   r-   r.   _GeneratedVideo_from_mldevD     r  c                       i t |dgd urtdg fddt |dgD  t |dgd ur0tdgt |dg t |dgd urCtdgt |dg S )	NgeneratedSamplesgenerated_videosc                    r2   r-   )r  r3   r6   r-   r.   r7   ^  r8   z6_GenerateVideosResponse_from_mldev.<locals>.<listcomp>raiMediaFilteredCountrai_media_filtered_countraiMediaFilteredReasonsrai_media_filtered_reasonsr:   r;   r-   r6   r.   "_GenerateVideosResponse_from_mldevT  ,   
	

r  c              	   C   s   i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg t |dgd ur;t|dgt |dg t |dgd urNt|dgt |dg t |dgd urat|dgt |dg t |ddgd urzt|dgt| t |ddg| |S )Nr^   r  doneerrorr]   generateVideoResponseresult)r(   r*   r  r+   r-   r-   r.   #_GenerateVideosOperation_from_mldevu  s,   
r%  c                 C   r?  )Nr@  r   r   r   r   r   r   r   r   r!   r    r#   r"   r%   r$   r&   r:   r+   r-   r-   r.   _Part_from_vertex  rB  r&  c                    r0   )Nr1   c                    r2   r-   )r&  r3   r6   r-   r.   r7     r8   z(_Content_from_vertex.<locals>.<listcomp>r9   r:   r;   r-   r6   r.   _Content_from_vertex  r=   r'  c                 C   r  )Nr  r:   r+   r-   r-   r.   _CitationMetadata_from_vertex  r   r(  c                 C   r  )Nr   r  r  finishMessagefinish_messager  r  r  r  r  r  r  r  r  r  r  )r(   r*   r'  r(  r+   r-   r-   r.   _Candidate_from_vertex  r  r+  c                    s   i t |dgd urtdg fddt |dgD  t |dgd ur0tdgt |dg t |dgd urCtdgt |dg t |dgd urVtd	gt |dg t |d
gd uritdgt |d
g t |dgd ur|tdgt |dg S )Nr  c                    r2   r-   )r+  r3   r6   r-   r.   r7   $  r8   z8_GenerateContentResponse_from_vertex.<locals>.<listcomp>r  r  
responseIdresponse_idr  r  r  r  r  r  r:   r;   r-   r6   r.   $_GenerateContentResponse_from_vertex  s(   
	r.  c                 C   sT   i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg |S )N	truncatedr  r:   r+   r-   r-   r.   '_ContentEmbeddingStatistics_from_vertex<  s   r0  c                 C   s\   i }t |dgd urt|dgt |dg t |dgd ur,t|dgt| t |dg| |S )Nr  
statistics)r(   r*   r0  r+   r-   r-   r.   _ContentEmbedding_from_vertexK  s   r2  c                 C   r   )NbillableCharacterCountbillable_character_countr:   r+   r-   r-   r.   !_EmbedContentMetadata_from_vertex`  r{  r5  c                    sp   i t |ddgd urtdg fddt |ddgD  t |dgd ur6tdgt t |dg S )Nzpredictions[]r  c                    r2   r-   )r2  r3   r6   r-   r.   r7   z  r8   z5_EmbedContentResponse_from_vertex.<locals>.<listcomp>r  )r(   r*   r5  r;   r-   r6   r.   !_EmbedContentResponse_from_vertexp  s$   	r6  c              	   C   re  )Nrf  r-  r/  r.  r   r   rg  r+   r-   r-   r.   _Image_from_vertex  ri  r7  c                 C   r  r  r:   r+   r-   r-   r.   _SafetyAttributes_from_vertex  r  r8  c                 C   s   i }t |dgd urt|dgt| t |dg| t |dgd ur,t|dgt |dg t |dgd urCt|dgt| t |dg| t |dgd urVt|dgt |dg |S )Nr  r<  r  r  r  r  enhanced_prompt)r(   r*   r7  r8  r+   r-   r-   r.   _GeneratedImage_from_vertex  s0   
r:  c                    r  )Nr  r  c                    r2   r-   r:  r3   r6   r-   r.   r7     r8   z7_GenerateImagesResponse_from_vertex.<locals>.<listcomp>r  r  )r(   r*   r8  r;   r-   r6   r.   #_GenerateImagesResponse_from_vertex  r  r<  c                    >   i t |dgd urtdg fddt |dgD  S )Nr  r  c                    r2   r-   r;  r3   r6   r-   r.   r7     r8   z2_EditImageResponse_from_vertex.<locals>.<listcomp>r:   r;   r-   r6   r.   _EditImageResponse_from_vertex     
	r>  c                    r=  )Nr  r  c                    r2   r-   r;  r3   r6   r-   r.   r7     r8   z5_UpscaleImageResponse_from_vertex.<locals>.<listcomp>r:   r;   r-   r6   r.   !_UpscaleImageResponse_from_vertex  r?  r@  c                 C   rr  )Nendpointr^   deployedModelIddeployed_model_idr:   r+   r-   r-   r.   _Endpoint_from_vertex!  s   rD  c                 C   s~   i }t |ddgd urt|dgt |ddg t |dgd ur*t|dgt |dg t |dgd ur=t|dgt |dg |S )Nr   z&google-vertex-llm-tuning-base-model-idr  r  r  r  r  r:   r+   r-   r-   r.   _TunedModelInfo_from_vertex2  s   rE  c                    s*  i t |dgd urtdgt |dg t |dgd ur(tdgt |dg t |dgd ur;tdgt |dg t |dgd urNtdgt |dg t |dgd uritdg fd	d
t |dgD  t |dgd ur|tdgt |dg t |dgd urtdgt t |dg S )Nr^   r#  r"  rG   	versionIdr  deployedModels	endpointsc                    r2   r-   )rD  r3   r6   r-   r.   r7   a  r8   z&_Model_from_vertex.<locals>.<listcomp>r   r  r  )r(   r*   rE  r;   r-   r6   r.   _Model_from_vertexK  s8   
	rI  c              
      r  )Nr  r  r  r  c                    r2   r-   )rI  r3   r6   r-   r.   r7     r8   z3_ListModelsResponse_from_vertex.<locals>.<listcomp>r  r;   r-   r6   r.   _ListModelsResponse_from_vertexv  r  rJ  c                 C   ra   rb   r-   r+   r-   r-   r.    _DeleteModelResponse_from_vertex  rd   rK  c                 C   r   )Nr
  r  r:   r+   r-   r-   r.    _CountTokensResponse_from_vertex  r   rL  c                 C   r   )N
tokensInfotokens_infor:   r+   r-   r-   r.   "_ComputeTokensResponse_from_vertex  r   rO  c              	   C   re  )Nrf  r  r/  r  r   r   rg  r+   r-   r-   r.   _Video_from_vertex  ri  rP  c                 C   rl   r  )r(   r*   rP  r+   r-   r-   r.   _GeneratedVideo_from_vertex  r  rQ  c                    r  )	Nvideosr  c                    r2   r-   )rQ  r3   r6   r-   r.   r7     r8   z7_GenerateVideosResponse_from_vertex.<locals>.<listcomp>r  r  r  r  r:   r;   r-   r6   r.   #_GenerateVideosResponse_from_vertex  r   rS  c                 C   s   i }t |dgd urt|dgt |dg t |dgd ur(t|dgt |dg t |dgd ur;t|dgt |dg t |dgd urNt|dgt |dg t |dgd urat|dgt |dg t |dgd urxt|dgt| t |dg| |S )Nr^   r  r!  r"  r]   r$  )r(   r*   rS  r+   r-   r-   r.   $_GenerateVideosOperation_from_vertex  s(   rT  c                   @   s  e Zd Zdddedeejejf deej	 dej
fddZdddedeejejf deej	 deej
 fd	d
Zdddedeejejf deej dejfddZdddededeej dejfddZdddededeej deej dejf
ddZdddedejdedeej dejf
ddZdddedeej dejfddZdddeej  dej!fddZ"dddedeej# dejfddZ$dddedeej% dej&fddZ'dddedeejejf deej( dej)fdd Z*dddedeejejf deej+ dej,fd!d"Z-e./d#dddd$dedee deej deej0 dej1f
d%d&Z2dddedeejejf deej	 dej
fd'd(Z3dddedeejejf deej	 deej
 fd)d*Z4dddededeej dejfd+d,Z5dddededeej deej dejf
d-d.Z6dddedejdedeej7 dejf
d/d0Z8dddeej  de9ej fd1d2ZdS )3ModelsNr   r   r   r   r   c                C   s(  t j|||d}| jjr"t| j|}|d}|rd|}nd}nt| j|}|d}|r5d|}nd}|d}|rG| dt| }|	dd  d }	|j
d ur^|j
jd ur^|j
j}	t|}t|}| jd|||	}
| jjr|t| j|
}
nt| j|
}
t jj|
| d}| j| |S 	Nr   r   r   r   z{model}:generateContentr  ?r   postr]   kwargs)r   _GenerateContentParameters_api_clientvertexairZ  get
format_mapr   r   popr   http_optionsr   convert_to_dictencode_unserializable_typesrequestr.  r  GenerateContentResponse_from_response
model_dump_verify_responseselfr   r   r   parameter_modelrequest_dictrequest_url_dictpathquery_paramsrc  response_dictreturn_valuer-   r-   r.   _generate_content  sZ   





zModels._generate_contentc                c   s6   t j|||d}| jjr#t| j|}|d}|r d|}nd}nt| j|}|d}|r6d|}nd}|d}|rH| dt| }|	dd  d }	|j
d ur_|j
jd ur_|j
j}	t|}t|}| jd|||	D ]&}
| jjrt| j|
}
nt| j|
}
t jj|
| d}| j| |V  qrd S )	NrX  r   %{model}:streamGenerateContent?alt=sser  rY  r   rZ  r[  )r   r]  r^  r_  rZ  r`  ra  r   r   rb  r   rc  r   rd  re  request_streamedr.  r  rg  rh  ri  rj  rk  r-   r-   r.   _generate_content_stream_  sf   





zModels._generate_content_streamc                C   s(  t j|||d}| jjr"t| j|}|d}|rd|}nd}nt| j|}|d}|r5d|}nd}|d}|rG| dt| }|	dd d}	|j
dur^|j
jdur^|j
j}	t|}t|}| jd	|||	}
| jjr|t| j|
}
nt| j|
}
t jj|
| d
}| j| |S )aA  Calculates embeddings for the given contents. Only text is supported.

    Args:
      model (str): The model to use.
      contents (list[Content]): The contents to embed.
      config (EmbedContentConfig): Optional configuration for embeddings.

    Usage:

    .. code-block:: python

      embeddings = client.models.embed_content(
          model= 'text-embedding-004',
          contents=[
              'What is your name?',
              'What is your favorite color?',
          ],
          config={
              'output_dimensionality': 64
          },
      )
    rX  r   {model}:predict{model}:batchEmbedContentsr  rY  r   NrZ  r[  )r   _EmbedContentParametersr^  r_  r^  r`  ra  r   r   rb  r   rc  r   rd  re  rf  r6  r  EmbedContentResponserh  ri  rj  rk  r-   r-   r.   embed_content  sZ   





zModels.embed_contentr  c                C   (  t j|||d}| jjr"t| j|}|d}|rd|}nd}nt| j|}|d}|r5d|}nd}|d}|rG| dt| }|	dd d}	|j
dur^|j
jdur^|j
j}	t|}t|}| jd|||	}
| jjr|t| j|
}
nt| j|
}
t jj|
| d	}| j| |S 
zGenerates images based on a text description and configuration.

    Args:
      model (str): The model to use.
      prompt (str): A text description of the images to generate.
      config (GenerateImagesConfig): Configuration for generation.
    r   r  r   r   rx  r  rY  r   NrZ  r[  )r   _GenerateImagesParametersr^  r_  rd  r`  ra  r  r   rb  r   rc  r   rd  re  rf  r<  r  GenerateImagesResponserh  ri  rj  rl  r   r  r   rm  rn  ro  rp  rq  rc  rr  rs  r-   r-   r.   _generate_images  sZ   





zModels._generate_imagesr  c                C      t j||||d}| jjstdt| j|}|d}|r$d|}nd}|d}	|	r6| dt|	 }|	dd d}
|j
durM|j
jdurM|j
j}
t|}t|}| jd	|||
}| jjrjt| j|}t jj|| d
}| j| |S )L  Edits an image based on a text description and configuration.

    Args:
      model (str): The model to use.
      prompt (str): A text description of the edit to apply to the image.
        reference_images (list[Union[RawReferenceImage, MaskReferenceImage,
        ControlReferenceImage, StyleReferenceImage, SubjectReferenceImage]): The
        reference images for editing.
      config (EditImageConfig): Configuration for editing.

    Usage:

    .. code-block:: python

      from google.genai.types import RawReferenceImage, MaskReferenceImage

      raw_ref_image = RawReferenceImage(
        reference_id=1,
        reference_image=types.Image.from_file(IMAGE_FILE_PATH),
      )

      mask_ref_image = MaskReferenceImage(
        reference_id=2,
        config=types.MaskReferenceConfig(
            mask_mode='MASK_MODE_FOREGROUND',
            mask_dilation=0.06,
        ),
      )
      response = client.models.edit_image(
        model='imagen-3.0-capability-001',
        prompt='man with dog',
        reference_images=[raw_ref_image, mask_ref_image],
        config=types.EditImageConfig(
            edit_mode= "EDIT_MODE_INPAINT_INSERTION",
            number_of_images= 1,
            include_rai_reason= True,
        )
      )
      response.generated_images[0].image.show()
      # Shows a man with a dog instead of a cat.
    r   r  r  r   6This method is only supported in the Vertex AI client.r   rx  r  rY  r   NrZ  r[  )r   _EditImageParametersr^  r_  r)   r  r`  ra  r   rb  r   rc  r   rd  re  rf  r>  EditImageResponserh  ri  rj  rl  r   r  r  r   rm  rn  ro  rp  rq  rc  rr  rs  r-   r-   r.   _edit_imageQ  sJ   2




zModels._edit_imager<  r  c                C   r  a  Upscales an image.

    Args:
      model (str): The model to use.
      image (Image): The input image for upscaling.
      upscale_factor (str): The factor to upscale the image (x2 or x4).
      config (_UpscaleImageAPIConfig): Configuration for upscaling.
    r   r<  r  r   r  r   rx  r  rY  r   NrZ  r[  )r   _UpscaleImageAPIParametersr^  r_  r)   r  r`  ra  r   rb  r   rc  r   rd  re  rf  r@  UpscaleImageResponserh  ri  rj  rl  r   r<  r  r   rm  rn  ro  rp  rq  rc  rr  rs  r-   r-   r.   _upscale_image  sJ   




zModels._upscale_imagec                C   &  t j||d}| jjr!t| j|}|d}|rd|}nd}nt| j|}|d}|r4d|}nd}|d}|rF| dt| }|	dd  d }|j
d ur]|j
jd ur]|j
j}t|}t|}| jd|||}	| jjr{t| j|	}	nt| j|	}	t jj|	| d}
| j|
 |
S 	Nr   r   r   {name}r  rY  r   r`  r[  )r   _GetModelParametersr^  r_  r  r`  ra  r  r   rb  r   rc  r   rd  re  rf  rI  r   Modelrh  ri  rj  rl  r   r   rm  rn  ro  rp  rq  rc  rr  rs  r-   r-   r.   r`    sP   





z
Models.getc          
      C   s$  t j|d}| jjr t| j|}|d}|rd|}nd}nt| j|}|d}|r3d|}nd}|d}|rE| dt| }|	dd  d }|j
d ur\|j
jd ur\|j
j}t|}t|}| jd|||}| jjrzt| j|}nt| j|}t jj|| d}	| j|	 |	S 	NrV  r   z{models_url}r  rY  r   r`  r[  )r   _ListModelsParametersr^  r_  r  r`  ra  r  r   rb  r   rc  r   rd  re  rf  rJ  r  ListModelsResponserh  ri  rj  
rl  r   rm  rn  ro  rp  rq  rc  rr  rs  r-   r-   r.   _list6  sV   





zModels._listc                C   s&  t j||d}| jjr!t| j|}|d}|rd|}nd}nt| j|}|d}|r4d|}nd}|d}|rF| dt| }|	dd  d }|j
d ur]|j
jd ur]|j
j}t|}t|}| jd|||}	| jjr{t| j|	}	nt| j|	}	t jj|	| d	}
| j|
 |
S 
Nr  r   z{model}r  r  rY  r   patchr[  )r   _UpdateModelParametersr^  r_  r  r`  ra  r&  r   rb  r   rc  r   rd  re  rf  rI  r   r  rh  ri  rj  r  r-   r-   r.   updateu  sP   





zModels.updatec                C   r  	Nr  r   r  r  rY  r   deleter[  )r   _DeleteModelParametersr^  r_  r  r`  ra  r(  r   rb  r   rc  r   rd  re  rf  rK  r	  DeleteModelResponserh  ri  rj  r  r-   r-   r.   r    sX   





zModels.deletec                C   r}  )
a8  Counts the number of tokens in the given content.

    Multimodal input is supported for Gemini models.

    Args:
      model (str): The model to use for counting tokens.
      contents (list[types.Content]): The content to count tokens for.
      config (CountTokensConfig): The configuration for counting tokens.

    Usage:

    .. code-block:: python

      response = client.models.count_tokens(
          model='gemini-2.0-flash',
          contents='What is your name?',
      )
      print(response)
      # total_tokens=5 cached_content_token_count=None
    rX  r   {model}:countTokensr  rY  r   NrZ  r[  )r   _CountTokensParametersr^  r_  r  r`  ra  r,  r   rb  r   rc  r   rd  re  rf  rL  r  CountTokensResponserh  ri  rj  rk  r-   r-   r.   count_tokens  sZ   





zModels.count_tokensc                C   s   t j|||d}| jjstdt| j|}|d}|r#d|}nd}|d}|r5| dt| }|	dd d}	|j
durL|j
jdurL|j
j}	t|}t|}| jd	|||	}
| jjrit| j|
}
t jj|
| d
}| j| |S )az  Given a list of contents, returns a corresponding TokensInfo containing the

    list of tokens and list of token ids.

    This method is not supported by the Gemini Developer API.

    Args:
      model (str): The model to use.
      contents (list[shared.Content]): The content to compute tokens for.

    Usage:

    .. code-block:: python

      response = client.models.compute_tokens(
          model='gemini-2.0-flash',
          contents='What is your name?',
      )
      print(response)
      # tokens_info=[TokensInfo(role='user', token_ids=['1841', ...],
      # tokens=[b'What', b' is', b' your', b' name', b'?'])]
    rX  r  r   {model}:computeTokensr  rY  r   NrZ  r[  )r   _ComputeTokensParametersr^  r_  r)   r  r`  ra  r   rb  r   rc  r   rd  re  rf  rO  ComputeTokensResponserh  ri  rj  rk  r-   r-   r.   compute_tokensQ  sH   




zModels.compute_tokens>This method is experimental and may change in future versions.r  r<  r   c                C   s*  t j||||d}| jjr#t| j|}|d}|r d|}nd}nt| j|}|d}|r6d|}nd}|d}	|	rH| dt|	 }|	dd d}
|j
dur_|j
jdur_|j
j}
t|}t|}| jd|||
}| jjr}t| j|}nt| j|}t jj|| d	}| j| |S 
aS  Generates videos based on a text description and configuration.

    Args:
      model: The model to use.
      instances: A list of prompts, images and videos to generate videos from.
      config: Configuration for generation.

    Usage:

      ```
      operation = client.models.generate_videos(
          model="veo-2.0-generate-001",
          prompt="A neon hologram of a cat driving at top speed",
      )
      while not operation.done:
          time.sleep(10)
          operation = client.operations.get(operation)

      operation.result.generated_videos[0].video.uri
      ```
    )r   r  r<  r   r   z{model}:predictLongRunningr  rY  r   NrZ  r[  )r   _GenerateVideosParametersr^  r_  r  r`  ra  r=  r   rb  r   rc  r   rd  re  rf  rT  r%  GenerateVideosOperationrh  ri  rj  rl  r   r  r<  r   rm  rn  ro  rp  rq  rc  rr  rs  r-   r-   r.   generate_videos  s\   !	





zModels.generate_videosc                C   sh  t |r| j|||dS t |}td| d g }t }d}|dkr|d7 }| j|||d}td| d |d8 }|dkrItd t |}|sQnU|sTnR|j	rd|j	d j
rd|j	d j
jsenAt ||}	|	snn8|j	d j
}
tjd	|	d
}t| j|}|s|| t|tr||
 || ||
 || |dks't |r|dur||_|S )a  Makes an API request to generate content using a model.

    For the `model` parameter, supported formats for Vertex AI API include:
    - The Gemini model ID, for example: 'gemini-2.0-flash'
    - The full resource name starts with 'projects/', for example:
      'projects/my-project-id/locations/us-central1/publishers/google/models/gemini-2.0-flash'
    - The partial resource name with 'publishers/', for example:
      'publishers/google/models/gemini-2.0-flash' or
      'publishers/meta/models/llama-3.1-405b-instruct-maas'
    - `/` separated publisher and model name, for example:
      'google/gemini-2.0-flash' or 'meta/llama-3.1-405b-instruct-maas'

    For the `model` parameter, supported formats for Gemini API include:
    - The Gemini model ID, for example: 'gemini-2.0-flash'
    - The model name starts with 'models/', for example:
      'models/gemini-2.0-flash'
    - For tuned models, the model name starts with 'tunedModels/',
      for example:
      'tunedModels/1234567890123456789'

    Some models support multimodal input and output.

    Usage:

    .. code-block:: python

      from google.genai import types
      from google import genai

      client = genai.Client(
          vertexai=True, project='my-project-id', location='us-central1'
      )

      response = client.models.generate_content(
        model='gemini-2.0-flash',
        contents='''What is a good name for a flower shop that specializes in
          selling bouquets of dried flowers?'''
      )
      print(response.text)
      # **Elegant & Classic:**
      # * The Dried Bloom
      # * Everlasting Florals
      # * Timeless Petals

      response = client.models.generate_content(
        model='gemini-2.0-flash',
        contents=[
          types.Part.from_text('What is shown in this image?'),
          types.Part.from_uri('gs://generativeai-downloads/images/scones.jpg',
          'image/jpeg')
        ]
      )
      print(response.text)
      # The image shows a flat lay arrangement of freshly baked blueberry
      # scones.
    rX  &AFC is enabled with max remote calls: .r   r	   AFC remote call 	 is done.8Reached max remote calls for automatic function calling.userr9   r1   Nr   should_disable_afcrt  get_max_remote_calls_afcloggerinfor   rg  get_function_mapr  r   r1   get_function_response_partsContentr   r   r^  extend
isinstancelistappendshould_append_afc_history"automatic_function_calling_history)rl  r   r   r   remaining_remote_calls_afcr  r]   ifunction_mapfunc_response_partsfunc_call_contentfunc_response_contentr-   r-   r.   generate_content  sn   
@










'zModels.generate_contentc                c   s   t |r| j|||dE dH  dS t |}td| d g }d}d}d}|dkr|d7 }| j|||d}	td| d |d8 }|dkrOtd	 t |}
|dkr|	D ]%}|
sb|V  qZ|jrr|jd jrr|jd jj	st nt 
||
}|s|V  qZn(|	D ]}t |r||_|V  q|jr|jd jr|jd jj	sdS t 
||
}|
sdS |sdS |jdur|jd j}tjd
|d}t| j|}|s|| t|tr|dur|| || |dur|| || |dks-dS dS )a?  Makes an API request to generate content using a model and yields the model's response in chunks.

    For the `model` parameter, supported formats for Vertex AI API include:
    - The Gemini model ID, for example: 'gemini-2.0-flash'
    - The full resource name starts with 'projects/', for example:
      'projects/my-project-id/locations/us-central1/publishers/google/models/gemini-2.0-flash'
    - The partial resource name with 'publishers/', for example:
      'publishers/google/models/gemini-2.0-flash' or
      'publishers/meta/models/llama-3.1-405b-instruct-maas'
    - `/` separated publisher and model name, for example:
      'google/gemini-2.0-flash' or 'meta/llama-3.1-405b-instruct-maas'

    For the `model` parameter, supported formats for Gemini API include:
    - The Gemini model ID, for example: 'gemini-2.0-flash'
    - The model name starts with 'models/', for example:
      'models/gemini-2.0-flash'
    - For tuned models, the model name starts with 'tunedModels/',
      for example:
      'tunedModels/1234567890123456789'

    Some models support multimodal input and output.

    Usage:

    .. code-block:: python

      from google.genai import types
      from google import genai

      client = genai.Client(
          vertexai=True, project='my-project-id', location='us-central1'
      )

      for chunk in client.models.generate_content_stream(
        model='gemini-2.0-flash',
        contents='''What is a good name for a flower shop that specializes in
          selling bouquets of dried flowers?'''
      ):
        print(chunk.text)
      # **Elegant & Classic:**
      # * The Dried Bloom
      # * Everlasting Florals
      # * Timeless Petals

      for chunk in client.models.generate_content_stream(
        model='gemini-2.0-flash',
        contents=[
          types.Part.from_text('What is shown in this image?'),
          types.Part.from_uri('gs://generativeai-downloads/images/scones.jpg',
          'image/jpeg')
        ]
      ):
        print(chunk.text)
      # The image shows a flat lay arrangement of freshly baked blueberry
      # scones.
    rX  Nr  r  r   r	   r  r  r  r  r  )r   r  rw  r  r  r  r  r  r   r1   r  r  r  r   r  r   r   r^  r  r  r  r  )rl  r   r   r   r  r  chunkr  r  r]   r  r  r  r-   r-   r.   generate_content_streamy  s   
@












zModels.generate_content_streamc          	      C   sh   | j |||d}d}g }|r|js|S |jD ]}|jr%|jjdkr%|j}q|| qtj||d}|S )ap  Generates images based on a text description and configuration.

    Args:
      model (str): The model to use.
      prompt (str): A text description of the images to generate.
      config (GenerateImagesConfig): Configuration for generation.

    Usage:

    .. code-block:: python

      response = client.models.generate_images(
        model='imagen-3.0-generate-002',
        prompt='Man with a dog',
        config=types.GenerateImagesConfig(
            number_of_images= 1,
            include_rai_reason= True,
        )
      )
      response.generated_images[0].image.show()
      # Shows a man with a dog.
    r  NPositive Promptr  r  r  r  r  r  r  r   r  	rl  r   r  r   api_responser  r  generated_imager]   r-   r-   r.   generate_images  s,   

zModels.generate_imagesc                C   s   | j ||||dS )r  r  r  rl  r   r  r  r   r-   r-   r.   
edit_imageF  s   1zModels.edit_imagec                C   s   t j||||d |pi }t|t jr| }nt|}t j|dd|dd|dd|ddd}d|d	< d
|d< | j||||dS )a  Makes an API request to upscale a provided image.

    Args:
      model (str): The model to use.
      image (Image): The input image for upscaling.
      upscale_factor (str): The factor to upscale the image (x2 or x4).
      config (UpscaleImageConfig): Configuration for upscaling.

    Usage:

    .. code-block:: python

      from google.genai.types import Image

      IMAGE_FILE_PATH="my-image.png"
      response=client.models.upscale_image(
          model='imagen-3.0-generate-001',
          image=types.Image.from_file(IMAGE_FILE_PATH),
          upscale_factor='x2',
      )
      response.generated_images[0].image.show()
      # Opens my-image.png which is upscaled by a factor of 2.
    r  rc  Nr   r   r   rc  r   r   r   upscalerg   r	   r   	r   UpscaleImageParametersr  UpscaleImageConfigri  dict_UpscaleImageAPIConfigDictr`  r  rl  r   r<  r  r   
config_dct
api_configr-   r-   r.   upscale_image~  s4   !




zModels.upscale_imagec                C   sl   t j|djp
t  }|jdu rd|_| jjr*| }|js*|j}|r'|d nd|_t	d| j
| j
|d|S )a  Makes an API request to list the available models.

    If `query_base` is set to True in the config or not set (default), the
    API will return all available base models. If set to False, it will return
    all tuned models.

    Args:
      config (ListModelsConfigOrDict): Configuration for retrieving models.

    Usage:

    .. code-block:: python

      response=client.models.list(config={'page_size': 5})
      print(response.page)
      # [Model(name='projects/./locations/./models/123', display_name='my_model'

      response=client.models.list(config={'page_size': 5, 'query_base': True})
      print(response.page)
      # [Model(name='publishers/google/models/gemini-2.0-flash-exp' ...
    rV  NT&filter=labels.tune-type:*labels.tune-type:*r  )r   r  r   ListModelsConfigr  r^  r_  copyr  r   r  rl  r   filter_valuer-   r-   r.   r    s&   


zModels.list):__name__
__module____qualname__strr   r   ContentListUnionContentListUnionDictr   GenerateContentConfigOrDictrg  rt  r   rw  EmbedContentConfigOrDictr{  r|  GenerateImagesConfigOrDictr  r  r  _ReferenceImageAPIOrDictEditImageConfigOrDictr  r  ImageOrDict_UpscaleImageAPIConfigOrDictr  r  GetModelConfigOrDictr  r`  ListModelsConfigOrDictr  r  UpdateModelConfigOrDictr  DeleteModelConfigOrDictr  r  CountTokensConfigOrDictr  r  ComputeTokensConfigOrDictr  r  r   experimental_warningGenerateVideosConfigOrDictr  r  r  r  r  r  UpscaleImageConfigOrDictr  r   r-   r-   r-   r.   rU    s   
J
N
a
S
k
E
=
C
C
H
_
Pb
}
 
=
>
ErU  c                   @   s  e Zd Zdddedeejejf deej	 dej
fddZdddedeejejf deej	 deeej
  fd	d
Zdddedeejejf deej dejfddZdddededeej dejfddZdddededeej deej dejf
ddZdddedejdedeej dejf
ddZdddedeej dejfddZ dddeej! dej"fddZ#dddedeej$ dejfddZ%dddedeej& dej'fddZ(dddedeejejf deej) dej*fdd Z+dddedeejejf deej, dej-fd!d"Z.e/0d#dddd$dedee deej deej1 dej2f
d%d&Z3dddedeejejf deej	 dej
fd'd(Z4dddedeejejf deej	 deeej
  fd)d*Z5dddededeej deej dejf
d+d,Z6dddeej! de7ej fd-d.Zdddededeej dejfd/d0Z8dddedejdedeej9 dejf
d1d2Z:dS )3AsyncModelsNrV  r   r   r   r   c                   s0  t j|||d}| jjr#t| j|}|d}|r d|}nd}nt| j|}|d}|r6d|}nd}|d}|rH| dt| }|	dd  d }	|j
d ur_|j
jd ur_|j
j}	t|}t|}| jd|||	I d H }
| jjrt| j|
}
nt| j|
}
t jj|
| d}| j| |S rW  )r   r]  r^  r_  rZ  r`  ra  r   r   rb  r   rc  r   rd  re  async_requestr.  r  rg  rh  ri  rj  rk  r-   r-   r.   rt    s\   






zAsyncModels._generate_contentc          
         s   t j|||d jjr#tj }|d}|r d|}nd}ntj }|d}|r6d|}nd}|d}|rH| dt| }|	dd  d } j
d ur_ j
jd ur_ j
j}t|}t|}jd|||I d H  fdd	}	|	 S )
NrX  r   ru  r  rY  r   rZ  c                    sb   2 z*3 d H W } j jrtj | } ntj | } tjj|   d}j | |V  q6 d S )Nr[  )	r^  r_  r.  r  r   rg  rh  ri  rj  )rr  rs  rm  response_streamrl  r-   r.   async_generators  s   z=AsyncModels._generate_content_stream.<locals>.async_generator)r   r]  r^  r_  rZ  r`  ra  r   r   rb  r   rc  r   rd  re  async_request_streamed)
rl  r   r   r   rn  ro  rp  rq  rc  r  r-   r  r.   rw  :  sP   






z$AsyncModels._generate_content_streamc                   s0  t j|||d}| jjr#t| j|}|d}|r d|}nd}nt| j|}|d}|r6d|}nd}|d}|rH| dt| }|	dd d}	|j
dur_|j
jdur_|j
j}	t|}t|}| jd	|||	I dH }
| jjrt| j|
}
nt| j|
}
t jj|
| d
}| j| |S )aK  Calculates embeddings for the given contents. Only text is supported.

    Args:
      model (str): The model to use.
      contents (list[Content]): The contents to embed.
      config (EmbedContentConfig): Optional configuration for embeddings.

    Usage:

    .. code-block:: python

      embeddings = await client.aio.models.embed_content(
          model= 'text-embedding-004',
          contents=[
              'What is your name?',
              'What is your favorite color?',
          ],
          config={
              'output_dimensionality': 64
          },
      )
    rX  r   rx  ry  r  rY  r   NrZ  r[  )r   rz  r^  r_  r^  r`  ra  r   r   rb  r   rc  r   rd  re  r  r6  r  r{  rh  ri  rj  rk  r-   r-   r.   r|    s\   






zAsyncModels.embed_contentr  c                   0  t j|||d}| jjr#t| j|}|d}|r d|}nd}nt| j|}|d}|r6d|}nd}|d}|rH| dt| }|	dd d}	|j
dur_|j
jdur_|j
j}	t|}t|}| jd|||	I dH }
| jjrt| j|
}
nt| j|
}
t jj|
| d	}| j| |S r~  )r   r  r^  r_  rd  r`  ra  r  r   rb  r   rc  r   rd  re  r  r<  r  r  rh  ri  rj  r  r-   r-   r.   r    s\   






zAsyncModels._generate_imagesr  c                      t j||||d}| jjstdt| j|}|d}|r%d|}nd}|d}	|	r7| dt|	 }|	dd d}
|j
durN|j
jdurN|j
j}
t|}t|}| jd	|||
I dH }| jjrnt| j|}t jj|| d
}| j| |S )V  Edits an image based on a text description and configuration.

    Args:
      model (str): The model to use.
      prompt (str): A text description of the edit to apply to the image.
        reference_images (list[Union[RawReferenceImage, MaskReferenceImage,
        ControlReferenceImage, StyleReferenceImage, SubjectReferenceImage]): The
        reference images for editing.
      config (EditImageConfig): Configuration for editing.

    Usage:

    .. code-block:: python

      from google.genai.types import RawReferenceImage, MaskReferenceImage

      raw_ref_image = RawReferenceImage(
        reference_id=1,
        reference_image=types.Image.from_file(IMAGE_FILE_PATH),
      )

      mask_ref_image = MaskReferenceImage(
        reference_id=2,
        config=types.MaskReferenceConfig(
            mask_mode='MASK_MODE_FOREGROUND',
            mask_dilation=0.06,
        ),
      )
      response = await client.aio.models.edit_image(
        model='imagen-3.0-capability-001',
        prompt='man with dog',
        reference_images=[raw_ref_image, mask_ref_image],
        config=types.EditImageConfig(
            edit_mode= "EDIT_MODE_INPAINT_INSERTION",
            number_of_images= 1,
            include_rai_reason= True,
        )
      )
      response.generated_images[0].image.show()
      # Shows a man with a dog instead of a cat.
    r  r  r   rx  r  rY  r   NrZ  r[  )r   r  r^  r_  r)   r  r`  ra  r   rb  r   rc  r   rd  re  r  r>  r  rh  ri  rj  r  r-   r-   r.   r  1  sL   2





zAsyncModels._edit_imager<  r  c                   r  r  )r   r  r^  r_  r)   r  r`  ra  r   rb  r   rc  r   rd  re  r  r@  r  rh  ri  rj  r  r-   r-   r.   r    sL   





zAsyncModels._upscale_imagec                   .  t j||d}| jjr"t| j|}|d}|rd|}nd}nt| j|}|d}|r5d|}nd}|d}|rG| dt| }|	dd  d }|j
d ur^|j
jd ur^|j
j}t|}t|}| jd|||I d H }	| jjrt| j|	}	nt| j|	}	t jj|	| d}
| j|
 |
S r  )r   r  r^  r_  r  r`  ra  r  r   rb  r   rc  r   rd  re  r  rI  r   r  rh  ri  rj  r  r-   r-   r.   r`    sR   






zAsyncModels.getc          
         s,  t j|d}| jjr!t| j|}|d}|rd|}nd}nt| j|}|d}|r4d|}nd}|d}|rF| dt| }|	dd  d }|j
d ur]|j
jd ur]|j
j}t|}t|}| jd|||I d H }| jjr~t| j|}nt| j|}t jj|| d}	| j|	 |	S r  )r   r  r^  r_  r  r`  ra  r  r   rb  r   rc  r   rd  re  r  rJ  r  r  rh  ri  rj  r  r-   r-   r.   r    sX   






zAsyncModels._listc                   s.  t j||d}| jjr"t| j|}|d}|rd|}nd}nt| j|}|d}|r5d|}nd}|d}|rG| dt| }|	dd  d }|j
d ur^|j
jd ur^|j
j}t|}t|}| jd|||I d H }	| jjrt| j|	}	nt| j|	}	t jj|	| d	}
| j|
 |
S r  )r   r  r^  r_  r  r`  ra  r&  r   rb  r   rc  r   rd  re  r  rI  r   r  rh  ri  rj  r  r-   r-   r.   r  U  sR   






zAsyncModels.updatec                   r  r  )r   r  r^  r_  r  r`  ra  r(  r   rb  r   rc  r   rd  re  r  rK  r	  r  rh  ri  rj  r  r-   r-   r.   r    sZ   






zAsyncModels.deletec                   r
  )
aB  Counts the number of tokens in the given content.

    Multimodal input is supported for Gemini models.

    Args:
      model (str): The model to use for counting tokens.
      contents (list[types.Content]): The content to count tokens for.
      config (CountTokensConfig): The configuration for counting tokens.

    Usage:

    .. code-block:: python

      response = await client.aio.models.count_tokens(
          model='gemini-2.0-flash',
          contents='What is your name?',
      )
      print(response)
      # total_tokens=5 cached_content_token_count=None
    rX  r   r  r  rY  r   NrZ  r[  )r   r  r^  r_  r  r`  ra  r,  r   rb  r   rc  r   rd  re  r  rL  r  r  rh  ri  rj  rk  r-   r-   r.   r    s\   






zAsyncModels.count_tokensc                   s   t j|||d}| jjstdt| j|}|d}|r$d|}nd}|d}|r6| dt| }|	dd d}	|j
durM|j
jdurM|j
j}	t|}t|}| jd	|||	I dH }
| jjrmt| j|
}
t jj|
| d
}| j| |S )aF  Given a list of contents, returns a corresponding TokensInfo containing the

    list of tokens and list of token ids.


    Args:
      model (str): The model to use.
      contents (list[shared.Content]): The content to compute tokens for.

    Usage:

    .. code-block:: python

      response = await client.aio.models.compute_tokens(
          model='gemini-2.0-flash',
          contents='What is your name?',
      )
      print(response)
      # tokens_info=[TokensInfo(role='user', token_ids=['1841', ...],
      # tokens=[b'What', b' is', b' your', b' name', b'?'])]
    rX  r  r   r  r  rY  r   NrZ  r[  )r   r  r^  r_  r)   r  r`  ra  r   rb  r   rc  r   rd  re  r  rO  r  rh  ri  rj  rk  r-   r-   r.   r  1  sJ   





zAsyncModels.compute_tokensr  r  c                   s2  t j||||d}| jjr$t| j|}|d}|r!d|}nd}nt| j|}|d}|r7d|}nd}|d}	|	rI| dt|	 }|	dd d}
|j
dur`|j
jdur`|j
j}
t|}t|}| jd|||
I dH }| jjrt| j|}nt| j|}t jj|| d	}| j| |S r  )r   r  r^  r_  r  r`  ra  r=  r   rb  r   rc  r   rd  re  r  rT  r%  r  rh  ri  rj  r  r-   r-   r.   r    s^   !	






zAsyncModels.generate_videosc                   sX  t |r| j|||dI dH S t |}td| d g }t }|dkr| j|||dI dH }|d8 }|dkrAtd t |}|sInU|sLnR|j	r\|j	d j
r\|j	d j
js]nAt ||}|sfn8|j	d j
}	tjd|d	}
t| j|}|s|| t|tr||	 ||
 ||	 ||
 |dks)t |r|dur||_|S )
a.  Makes an API request to generate content using a model.

    Some models support multimodal input and output.

    Usage:

    .. code-block:: python

      from google.genai import types
      from google import genai

      client = genai.Client(
          vertexai=True, project='my-project-id', location='us-central1'
      )

      response = await client.aio.models.generate_content(
          model='gemini-2.0-flash',
          contents='User input: I like bagels. Answer:',
          config=types.GenerateContentConfig(
              system_instruction=
                [
                  'You are a helpful language translator.',
                  'Your mission is to translate text in English to French.'
                ]
          ),
      )
      print(response.text)
      # J'aime les bagels.
    rX  Nr  r  r   r	   r  r  r  r  )rl  r   r   r   r  r  r]   r  r  r  r  r-   r-   r.   r    sj   
$










&zAsyncModels.generate_contentc                   sR   t |rj|||dI dH   fdd}||||S fdd}||||S )a_  Makes an API request to generate content using a model and yields the model's response in chunks.

    For the `model` parameter, supported formats for Vertex AI API include:
    - The Gemini model ID, for example: 'gemini-2.0-flash'
    - The full resource name starts with 'projects/', for example:
      'projects/my-project-id/locations/us-central1/publishers/google/models/gemini-2.0-flash'
    - The partial resource name with 'publishers/', for example:
      'publishers/google/models/gemini-2.0-flash' or
      'publishers/meta/models/llama-3.1-405b-instruct-maas'
    - `/` separated publisher and model name, for example:
      'google/gemini-2.0-flash' or 'meta/llama-3.1-405b-instruct-maas'

    For the `model` parameter, supported formats for Gemini API include:
    - The Gemini model ID, for example: 'gemini-2.0-flash'
    - The model name starts with 'models/', for example:
      'models/gemini-2.0-flash'
    - For tuned models, the model name starts with 'tunedModels/',
      for example:
      'tunedModels/1234567890123456789'

    Some models support multimodal input and output.

    Usage:

    .. code-block:: python

      from google.genai import types
      from google import genai

      client = genai.Client(
          vertexai=True, project='my-project-id', location='us-central1'
      )

      async for chunk in await client.aio.models.generate_content_stream(
        model='gemini-2.0-flash',
        contents='''What is a good name for a flower shop that specializes in
          selling bouquets of dried flowers?'''
      ):
        print(chunk.text)
      # **Elegant & Classic:**
      # * The Dried Bloom
      # * Everlasting Florals
      # * Timeless Petals

      async for chunk in awiat client.aio.models.generate_content_stream(
        model='gemini-2.0-flash',
        contents=[
          types.Part.from_text('What is shown in this image?'),
          types.Part.from_uri('gs://generativeai-downloads/images/scones.jpg',
          'image/jpeg')
        ]
      ):
        print(chunk.text)
      # The image shows a flat lay arrangement of freshly baked blueberry
      # scones.
    rX  Nc                   s     2 z	3 d H W }|V  q6 d S rb   r-   )r   r   r   r  )r]   r-   r.   base_async_generator  s   zAAsyncModels.generate_content_stream.<locals>.base_async_generatorc                   s  t |}td| d g }d }d }d}|dkr|d7 } j| ||dI d H }td| d |d8 }|dkr@td t |}	|dkrw|2 z)3 d H W }|	sW|V  qK|jrg|jd jrg|jd jjsi nt 	||	}|st|V  qK6 n-|2 z3 d H W }t 
|r||_|V  qy6 |jr|jd jr|jd jjsd S t 	||	}|	sd S |sd S |jd j}
tjd	|d
}t j|}|s|| t|tr|
d ur||
 || |
d ur||
 || |dksd S d S )Nr  r  r   r	   rX  r  r  r  r  r  )r   r  r  r  rw  r  r  r   r1   r  r  r  r   r  r   r   r^  r  r  r  r  )r   r   r   r  r  r  r  r  r]   r  r  r  )rl  r-   r.   r    s   










z<AsyncModels.generate_content_stream.<locals>.async_generator)r   r  rw  )rl  r   r   r   r  r  r-   )r]   rl  r.   r  :  s   
@Sz#AsyncModels.generate_content_streamc                   s   | j ||||dI dH S )r  r  Nr  r  r-   r-   r.   r    s   1zAsyncModels.edit_imagec                   st   t j|djpt  }|jdu rd|_| jjr+| }|js+|j}|r(|d nd|_t	d| j
| j
|dI dH |S )a  Makes an API request to list the available models.

    If `query_base` is set to True in the config or not set (default), the
    API will return all available base models. If set to False, it will return
    all tuned models.

    Args:
      config (ListModelsConfigOrDict): Configuration for retrieving models.

    Usage:

    .. code-block:: python

      response = await client.aio.models.list(config={'page_size': 5})
      print(response.page)
      # [Model(name='projects/./locations/./models/123', display_name='my_model'

      response = await client.aio.models.list(
          config={'page_size': 5, 'query_base': True}
        )
      print(response.page)
      # [Model(name='publishers/google/models/gemini-2.0-flash-exp' ...
    rV  NTr  r  r  )r   r  r   r  r  r^  r_  r  r  r   r  r  r-   r-   r.   r    s(   

zAsyncModels.listc          	         sp   | j |||dI dH }d}g }|r|js|S |jD ]}|jr)|jjdkr)|j}q|| qtj||d}|S )az  Generates images based on a text description and configuration.

    Args:
      model (str): The model to use.
      prompt (str): A text description of the images to generate.
      config (GenerateImagesConfig): Configuration for generation.

    Usage:

    .. code-block:: python

      response = await client.aio.models.generate_images(
        model='imagen-3.0-generate-002',
        prompt='Man with a dog',
        config=types.GenerateImagesConfig(
            number_of_images= 1,
            include_rai_reason= True,
        )
      )
      response.generated_images[0].image.show()
      # Shows a man with a dog.
    r  Nr  r  r  r  r-   r-   r.   r  F  s.   

zAsyncModels.generate_imagesc                   s   t j||||d |pi }t|t jr| }nt|}t j|dd|dd|dd|ddd}d|d	< d
|d< | j||||dI dH S )a  Makes an API request to upscale a provided image.

    Args:
      model (str): The model to use.
      image (Image): The input image for upscaling.
      upscale_factor (str): The factor to upscale the image (x2 or x4).
      config (UpscaleImageConfig): Configuration for upscaling.

    Usage:

    .. code-block:: python

      from google.genai.types import Image

      IMAGE_FILE_PATH="my-image.png"
      response = await client.aio.models.upscale_image(
          model='imagen-3.0-generate-001',
          image=types.Image.from_file(IMAGE_FILE_PATH),
          upscale_factor='x2',
      )
      response.generated_images[0].image.show()
      # Opens my-image.png which is upscaled by a factor of 2.
    r  rc  Nr   r   r   r  r  rg   r	   r   r  r  r-   r-   r.   r  }  s6   !




zAsyncModels.upscale_image);r  r  r  r  r   r   r  r  r   r  rg  rt  r   r   rw  r  r{  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r`  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r   r  r  r  r  r  r  r  r   r  r  r  r-   r-   r-   r.   r    s   
J
S
a
S
k
E
=
C
C
H
_
Ob
_
 '
;
9
=r  rb   )loggingtypingr   r   r   r   r   r   urllib.parser    r
   r   r   r   r   r   r^  r   r   r(   r   r*   pagersr   r   	getLoggerr  r  objectr/   r<   rX   r\   r`   rc   rj   rp   r{   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r$  r&  r(  r*  r,  r1  r9  r=  rA  rC  rH  rI  rK  rL  rM  rN  rO  rP  rQ  rR  rS  rT  rU  rX  rZ  r]  r^  rb  rd  rh  rq  rw  rz  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r	  r  r  r  r  r%  r&  r'  r(  r+  r.  r0  r2  r5  r6  r7  r8  r:  r<  r>  r@  rD  rE  rI  rJ  rK  rL  rO  rP  rQ  rS  rT  
BaseModulerU  r  r-   r-   r-   r.   <module>   s	   


/



R











0













 )

(

$

(

j





#











(



B

&

/



R











0













 '

(

,

#

r













?

r

)

,

*



#









)

(

"

R

#

-





7















#

!





4











$

&

/





7

%













&

!









.







$
!           f