o
    pkj                    @   sP  d dl Z d dlZd dlZd dl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mZ edZ		dwdeeeef ef deeeef  deeeeef ef  deeef fddZ		dwdeeeef ef deeeef  deeeeef ef  deeef fddZ		dwdeeeef ef deeeef  deeeeef ef  deeef fddZ		dwdeeeef ef deeeef  deeeeef ef  deeef fddZ		dwdeeeef ef deeeef  deeeeef ef  deeef fddZ		dwdeeeef ef deeeef  deeeeef ef  deeef fddZ 		dwdeeeef ef deeeef  deeeeef ef  deeef fddZ!		dwdeeeef ef deeeef  deeeeef ef  deeef fdd Z"		dwdeeeef ef deeeef  deeeeef ef  deeef fd!d"Z#		dwdeeeef ef deeeef  deeeeef ef  deeef fd#d$Z$		dwdeeeef ef deeeef  deeeeef ef  deeef fd%d&Z%		dwdeeeef ef deeeef  deeeeef ef  deeef fd'd(Z&		dwdeeeef ef deeeef  deeeeef ef  deeef fd)d*Z'		dwdeeeef ef deeeef  deeeeef ef  deeef fd+d,Z(		dwdeeeef ef deeeef  deeeeef ef  deeef fd-d.Z)		dwdeeeef ef deeeef  deeeeef ef  deeef fd/d0Z*		dwdeeeef ef deeeef  deeeeef ef  deeef fd1d2Z+		dwdeeeef ef deeeef  deeeeef ef  deeef fd3d4Z,		dwdeeeef ef deeeef  deeeeef ef  deeef fd5d6Z-		dwdeeeef ef deeeef  deeeeef ef  deeef fd7d8Z.		dwdeeeef ef deeeef  deeeeef ef  deeef fd9d:Z/		dwdeeeef ef deeeef  deeeeef ef  deeef fd;d<Z0		dwdeeeef ef deeeef  deeeeef ef  deeef fd=d>Z1		dwdeeeef ef deeeef  deeeeef ef  deeef fd?d@Z2		dwdeeeef ef deeeef  deeeeef ef  deeef fdAdBZ3		dwdeeeef ef deeeef  deeeeef ef  deeef fdCdDZ4		dwdeeeef ef deeeef  deeeeef ef  deeef fdEdFZ5		dwdeeeef ef deeeef  deeeeef ef  deeef fdGdHZ6		dwdeeeef ef deeeef  deeeeef ef  deeef fdIdJZ7		dwdeeeef ef deeeef  deeeeef ef  deeef fdKdLZ8		dwdeeeef ef deeeef  deeeeef ef  deeef fdMdNZ9		dwdeeeef ef deeeef  deeeeef ef  deeef fdOdPZ:		dwdeeeef ef deeeef  deeeeef ef  deeef fdQdRZ;		dwdeeeef ef deeeef  deeeeef ef  deeef fdSdTZ<		dwdeeeef ef deeeef  deeeeef ef  deeef fdUdVZ=		dwdeeeef ef deeeef  deeeeef ef  deeef fdWdXZ>		dwdeeeef ef deeeef  deeeeef ef  deeef fdYdZZ?		dwdeeeef ef deeeef  deeeeef ef  deeef fd[d\Z@		dwdeeeef ef deeeef  deeeeef ef  deeef fd]d^ZA		dwdeeeef ef deeeef  deeeeef ef  deeef fd_d`ZB		dwdeeeef ef deeeef  deeeeef ef  deeef fdadbZC		dwdeeeef ef deeeef  deeeeef ef  deeef fdcddZD		dwdeeeef ef deeeef  deeeeef ef  deeef fdedfZE		dwdeeeef ef deeeef  deeeeef ef  deeef fdgdhZF		dwdeeeef ef deeeef  deeeeef ef  deeef fdidjZG		dwdeeeef ef deeeef  deeeeef ef  deeef fdkdlZH		dwdeeeef ef deeeef  deeeeef ef  deeef fdmdnZI		dwdeeeef ef deeeef  deeeeef ef  deeef fdodpZJG dqdr dre
jKZLG dsdt dte
jKZMG dudv dvZNdS )x    N)AnyOptionalUnion)	urlencode   )_api_module)_common)_transformers)types)get_value_by_path)set_value_by_path)
AsyncPagerPagerzgoogle_genai.tuningsfrom_objectparent_objectroot_objectreturnc                 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rRt|dgtt | dg|| |S )	NsamplingCountsampling_countflipEnabledflip_enabledautoraterModelautorater_modelgenerationConfiggeneration_configgetvsetv_GenerationConfig_from_vertexr   r   r   	to_object r"   R/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/google/genai/tunings.py_AutoraterConfig_from_vertex#       r$   c                 C   r   )	Nr   r   r   r   r   r   r   r   )r   r   _GenerationConfig_to_vertexr    r"   r"   r#   _AutoraterConfig_to_vertex>   r%   r'   c                 C   0   i }t | dgd urt|ddgt | dg |S Nname_urlr   r   r    r"   r"   r#   #_CancelTuningJobParameters_to_mldevY      r-   c                 C   r(   r)   r,   r    r"   r"   r#   $_CancelTuningJobParameters_to_vertexe   r.   r/   c                 C   .   i }t | dgd urt|dgt | dg |S NsdkHttpResponsesdk_http_responser,   r    r"   r"   r#   #_CancelTuningJobResponse_from_mldevq      r4   c                 C   r0   r1   r,   r    r"   r"   r#   $_CancelTuningJobResponse_from_vertex   r5   r6   c                 C   \   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 )NrewardConfigreward_configweight)r   r   2_SingleReinforcementTuningRewardConfig_from_vertexr    r"   r"   r#   I_CompositeReinforcementTuningRewardConfigWeightedRewardConfig_from_vertex      r<   c                 C   r7   )Nr9   r8   r:   )r   r   0_SingleReinforcementTuningRewardConfig_to_vertexr    r"   r"   r#   G_CompositeReinforcementTuningRewardConfigWeightedRewardConfig_to_vertex   r=   r?   c                    >   i t | dgd urtdg fddt | dgD  S )NweightedRewardConfigsweighted_reward_configsc                       g | ]}t | qS r"   )r<   .0itemr   r!   r"   r#   
<listcomp>       zI_CompositeReinforcementTuningRewardConfig_from_vertex.<locals>.<listcomp>r,   r   r   r   r"   rG   r#   5_CompositeReinforcementTuningRewardConfig_from_vertex      
rK   c                    r@   )NrB   rA   c                    rC   r"   )r?   rD   rG   r"   r#   rH      rI   zG_CompositeReinforcementTuningRewardConfig_to_vertex.<locals>.<listcomp>r,   rJ   r"   rG   r#   3_CompositeReinforcementTuningRewardConfig_to_vertex   rL   rM   c                    sd   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                    rC   r"   )_Part_to_vertexrD   rG   r"   r#   rH          
z&_Content_to_vertex.<locals>.<listcomp>roler,   rJ   r"   rG   r#   _Content_to_vertex   s   
	rR   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r-tdt | dgd urAt|g dt | dg t | d	gd urUt|g d
t | d	g t | dgd uratdt | dgd urmtdt | dgd urytdt | dgd urtdt | dgd urtd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rtdt | dgd urtdt | dgd urtdt | dgd urtd t | d!gd urtd"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r)td*t | d+gd ur6td,t | d-gd urCtd.t | d/gd urPtd0t | d1gd ur]td2t | d3gd urjtd4t | d5gd urwtd6t | d7gd urtd8|S )9Nvalidation_datasetzzvalidation_dataset parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.tuned_model_display_namedisplayNamedescriptionzsdescription parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.epoch_count)
tuningTaskhyperparameters
epochCountlearning_rate_multiplier)rX   rY   learningRateMultiplierexport_last_checkpoint_onlyzexport_last_checkpoint_only parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.pre_tuned_model_checkpoint_idzpre_tuned_model_checkpoint_id parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.adapter_sizeztadapter_size parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.tuning_modezstuning_mode parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.custom_base_modelzycustom_base_model parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.
batch_size)rX   rY   	batchSizelearning_rate)rX   rY   learningRateevaluation_configzyevaluation_config parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.labelsznlabels parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.betazlbeta parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.base_teacher_modelzzbase_teacher_model parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.tuned_teacher_model_sourceztuned_teacher_model_source parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.sft_loss_weight_multiplierzsft_loss_weight_multiplier parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.
output_urizroutput_uri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.encryption_speczwencryption_spec parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.r9   zureward_config parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.composite_reward_configzcomposite_reward_config parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.samples_per_promptzzsamples_per_prompt parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.evaluate_intervalzyevaluate_interval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.checkpoint_intervalz{checkpoint_interval parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.max_output_tokenszymax_output_tokens parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.thinking_levelzvthinking_level parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.validation_dataset_uriz~validation_dataset_uri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.r   
ValueErrorr   r    r"   r"   r#   _CreateTuningJobConfig_to_mldev   s   




rw   c                 C   s
  i }t |ddg}|d u rd}|dkr+t | dgd ur*t|dgtt | dg|| nS|dkrGt | dgd urFt|dgtt | dg|| n7|dkrct | dgd urbt|d	gtt | dg|| n|d
kr~t | dgd ur~t|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dg}|d u rd}|dkrt | dgd urt|g dt | dg nL|dkrt | dgd urt|g dt | dg n3|dkrt | dgd urt|g dt | dg n|d
krt | dgd urt|g dt | dg t |ddg}|d u r$d}|dkr?t | dgd ur>t|g dt | dg nP|dkrZt | dgd urYt|g dt | dg n5|dkrut | dgd urtt|g dt | dg n|d
krt | dgd urt|g dt | dg t |ddg}|d u rd}|dkrt | dgd urt|ddgt | dg n5|dkrt | dgd urt|ddgt | dg n|dkrt | dgd urt|d	dgt | dg t |ddg}|d u rd}|dkrt | dgd urt|g dt | dg nP|dkr1t | dgd ur0t|g dt | dg n5|dkrLt | dgd urKt|g dt | dg n|d
krft | dgd urft|g dt | dg t |ddg}|d u rtd}|dkrt | d gd urt|dd!gt | d g n|dkrt | d gd urt|d	d!gt | d g t | d"gd urt|d#gt | d"g t |ddg}|d u rd}|dkrt | d$gd urt|g d%t | d$g n5|dkrt | d$gd ur t|g d&t | d$g n|d
krt | d$gd urt|g d't | d$g t |ddg}|d u r)d}|dkrDt | d(gd urCt|g d)t | d(g n|dkr^t | d(gd ur^t|g d*t | d(g t |ddg}|d u rld}|dkrt | d+gd urt|dd,gtt | d+g|| n=|dkrt | d+gd urt|dd,gtt | d+g|| n|dkrt | d+gd urt|d	d,gtt | d+g|| t | d-gd urt|d-gt | d-g t | d.gd urt|g d/t | d.g t | d0gd urt|d	d1gt | d0g t | d2gd urt|d	d3gt | d2g t | d4gd ur0t|g d5t | d4g t | d6gd urDt|d7gt | d6g t | d8gd urXt|d9gt | d8g t | d:gd urqt|dd;gtt | d:g|| t | d<gd urt|dd=gtt | d<g|| t | d>gd urt|g d?t | d>g t | d@gd urt|g dAt | d@g t | dBgd urt|g dCt | dBg t | dDgd urt|g dEt | dDg t | dFgd urt|g dGt | dFg t | dHgd urt|ddIgt | dHg |S )JNconfigmethodSUPERVISED_FINE_TUNINGrS   supervisedTuningSpecPREFERENCE_TUNINGpreferenceOptimizationSpecDISTILLATIONdistillationSpecREINFORCEMENT_TUNINGreinforcementTuningSpecrT   tunedModelDisplayNamerV   rW   )r{   hyperParametersrZ   )r}   r   rZ   )r   r   rZ   )r   r   rZ   r[   )r{   r   r\   )r}   r   r\   )r   r   r\   )r   r   r\   r]   exportLastCheckpointOnlyr_   )r{   r   adapterSize)r}   r   r   )r   r   r   )r   r   r   r`   
tuningModera   customBaseModelrb   )r{   r   rc   )r   r   rc   )r   r   rc   rd   )r{   r   re   )r   r   re   rf   evaluationConfigrg   rh   )r}   r   rh   ri   baseTeacherModelrj   tunedTeacherModelSourcerk   )r   r   sftLossWeightMultiplierrl   	outputUrirm   encryptionSpecr9   singleRewardConfigrn   compositeRewardConfigro   )r   r   samplesPerPromptrp   )r   r   evaluateIntervalrq   )r   r   checkpointIntervalrr   )r   r   maxOutputTokensrs   )r   r   thinkingLevelrt   validationDatasetUri)r   r   "_TuningValidationDataset_to_vertex_EvaluationConfig_to_vertexr>   rM   r   r   r   r!   discriminatorr"   r"   r#    _CreateTuningJobConfig_to_vertex  s  











	






















































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t | dg|| t | dgd urLtt | dg|| |S N
base_model	baseModelpre_tuned_modelpreTunedModeltraining_datasetrx   )r   r   _TuningDataset_to_mldevrw   r    r"   r"   r#   *_CreateTuningJobParametersPrivate_to_mldev5     r   c                 C   r   r   )r   r   _TuningDataset_to_vertexr   r    r"   r"   r#   +_CreateTuningJobParametersPrivate_to_vertexN  r   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rRt|dgtt | dg|| t | d	gd uret|d
gt | d	g t | dgd urxt|dgt | dg |S )Nr   r_   rZ   rW   r\   r[   r   r   re   rd   rc   rb   r   r    r"   r"   r#   (_DistillationHyperParameters_from_vertexg  s0   
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|| |S )
Nr   ri   r   rj   r   rt   promptDatasetUriprompt_dataset_urirY   r   r   r   r    r"   r"   r#   %_DistillationSamplingSpec_from_vertex  sD   



r   c                 C   sf  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t | dg|| t | dgd urRt|dgt | dg t | d	gd uret|d
g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 t | dgd urt|dgt | dg |S )Nr   r   r   ri   r   hyper_parameterspipelineRootDirectorypipeline_root_directorystudentModelstudent_modeltrainingDatasetUritraining_dataset_urir   rj   r   rt   r   r`   r   r    r"   r"   r#   _DistillationSpec_from_vertex  sd   





r   c                 C      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rBt|dgtt | dg|| t | dgd urYt|dgtt | dg|| |S )NmetricsoutputConfigoutput_configautoraterConfigautorater_configinferenceGenerationConfiginference_generation_config)r   r   t	t_metricsr$   r   r    r"   r"   r#   _EvaluationConfig_from_vertex  0   

r   c                 C   r   )Nr   r   r   r   r   r   r   )r   r   r   r   r'   r&   r    r"   r"   r#   r     r   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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rdt|d
gt | d	g t | dgd urwt|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r8t|dgt | dg t | dgd urLt|d gt | dg t | d!gd ur`t|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d,d- t | d*gD  t | d.gd urt|d/gt | d.g |S )0NmodelConfigmodel_selection_configresponseJsonSchemaresponse_json_schemaaudioTimestampaudio_timestampcandidateCountcandidate_countenableAffectiveDialogenable_affective_dialogfrequencyPenaltyfrequency_penaltylogprobsr   rr   mediaResolutionmedia_resolutionpresencePenaltypresence_penaltyresponseLogprobsresponse_logprobsresponseMimeTyperesponse_mime_typeresponseModalitiesresponse_modalitiesresponseSchemaresponse_schemaroutingConfigrouting_configseedspeechConfigspeech_configstopSequencesstop_sequencestemperaturethinkingConfigthinking_configtopKtop_ktopPtop_presponseFormatresponse_formatc                 S      g | ]}|qS r"   r"   rD   r"   r"   r#   rH         z1_GenerationConfig_from_vertex.<locals>.<listcomp>audioTranscriptionConfigaudio_transcription_config)r   r   r   t_json_schemar    r"   r"   r#   r   B  s   






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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rdt|d
gt | d	g t | dgd urwt|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r8t|dgt | dg t | dgd urPt|d gtt | dg|| t | d!gd urdt|d"g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 t | d(gd urt|d)gt | d(g t | d*gd urtd+t | d,gd urt|d-gd.d/ t | d,gD  t | d0gd urtd1t | d2gd urt|d3gt | d2g |S )4Nr   r   r   r   r   r   r   r   r   r   r   r   r   rr   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   enable_enhanced_civic_answerszenable_enhanced_civic_answers parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.r   r   c                 S   r   r"   r"   rD   r"   r"   r#   rH   7  r   z/_GenerationConfig_to_vertex.<locals>.<listcomp>translation_configzztranslation_config parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.r   r   )r   r   r   r   _SpeechConfig_to_vertexrv   r    r"   r"   r#   r&     s   






r&   c                 C   r(   r)   r,   r    r"   r"   r#    _GetTuningJobParameters_to_mldevJ  r.   r   c                 C   r(   r)   r,   r    r"   r"   r#   !_GetTuningJobParameters_to_vertexV  r.   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 |S )N	page_size_querypageSize
page_token	pageTokenfilterr,   r    r"   r"   r#   _ListTuningJobsConfig_to_vertexb  s   
r   c                 C   s,   i }t | dgd urtt | dg|| |S )Nrx   )r   r   r    r"   r"   r#   #_ListTuningJobsParameters_to_vertex{  s   r   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rCtdg fddt | dgD  S )	Nr2   r3   nextPageTokennext_page_token
tuningJobstuning_jobsc                    rC   r"   )_TuningJob_from_vertexrD   rG   r"   r#   rH     rP   z7_ListTuningJobsResponse_from_vertex.<locals>.<listcomp>r,   rJ   r"   rG   r#   #_ListTuningJobsResponse_from_vertex  s    
	r   c                    r@   )Nspeaker_voice_configsspeakerVoiceConfigsc                    rC   r"   )_SpeakerVoiceConfig_to_vertexrD   rG   r"   r#   rH     rP   z6_MultiSpeakerVoiceConfig_to_vertex.<locals>.<listcomp>r,   rJ   r"   rG   r#   "_MultiSpeakerVoiceConfig_to_vertex  s   
	r  c                 C   sB  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t | dgd urtdt | dgd urtd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   r   code_execution_resultcodeExecutionResultexecutable_codeexecutableCode	file_datafileDatafunction_callfunctionCallfunction_responsefunctionResponseinline_data
inlineDatatextthoughtthought_signaturethoughtSignaturevideo_metadatavideoMetadata	tool_callzqtool_call parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.tool_responsezutool_response parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.part_metadatazupart_metadata parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.audio_transcriptionaudioTranscriptionmedia_processingmediaProcessingr   r   rv   r    r"   r"   r#   rO     sx   



rO   c                 C      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 t | d	gd uret|d
gt | d	g |S )Nr   r   autoraterPromptautorater_promptautoraterResponseParseConfigautorater_response_parse_configparsedResponseConversionScorer!parsed_response_conversion_scorerexactMatchScorerexact_match_scorer)r   r   r$   r    r"   r"   r#   /_ReinforcementTuningAutoraterScorer_from_vertex  @   


r(  c                 C   r  )Nr   r   r!  r   r#  r"  r%  r$  r'  r&  )r   r   r'   r    r"   r"   r#   -_ReinforcementTuningAutoraterScorer_to_vertex9  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rGtdgtt | dg  S )Ncontentsc                    rC   r"   )rR   rD   rG   r"   r#   rH   o  rP   z9_ReinforcementTuningExample_to_vertex.<locals>.<listcomp>
referencessystem_instructionsystemInstruction)r   r   rR   rJ   r"   rG   r#   %_ReinforcementTuningExample_to_vertexe  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 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rit|d
gtt | d	g|| |S )Nr   rn   r   r   r   rt   r   r   r   single_reward_config)r   r   rK   r;   r    r"   r"   r#   $_ReinforcementTuningSpec_from_vertex  sD   

r1  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r4tdt | dgd ur@td|S )	N	mime_typemimeTypevoice_sample_audiovoiceSampleAudioconsent_audiozuconsent_audio parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.voice_consent_signaturezvoice_consent_signature parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.r  r    r"   r"   r#    _ReplicatedVoiceConfig_to_vertex  s$   
r8  c                 C      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 t | d	gd uret|d
gt | d	g t | dgd urxt|dgt | dg |S )NautoraterScorerautorater_scorer
rewardNamereward_nameparseResponseConfigparse_response_configcodeExecutionRewardScorercode_execution_reward_scorerstringMatchRewardScorerstring_match_reward_scorercloudRunRewardScorercloud_run_reward_scorer)r   r   r(  r    r"   r"   r#   r;     H   



r;   c                 C   r9  )Nr;  r:  r=  r<  r?  r>  rA  r@  rC  rB  rE  rD  )r   r   r*  r    r"   r"   r#   r>     rF  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t | dg|| |S )Nspeakervoice_configvoiceConfig)r   r   _VoiceConfig_to_vertexr    r"   r"   r#   r  3  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 t | dgd urCt|dgtt | dg|| |S )NrH  rI  language_codelanguageCodemulti_speaker_voice_configmultiSpeakerVoiceConfig)r   r   rJ  r  r    r"   r"   r#   r   H  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 )Nr*   modelendpointr,   r    r"   r"   r#   _TunedModel_from_mldevh  s   rQ  c                 C   sj   i }t | dgd urtdt | dgd urtdt | dgd ur3t|ddgdd t | dgD  |S )Ngcs_urizogcs_uri parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.vertex_dataset_resourcezvertex_dataset_resource parameter is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.examplesc                 S   r   r"   r"   rD   r"   r"   r#   rH     r   z+_TuningDataset_to_mldev.<locals>.<listcomp>ru   r    r"   r"   r#   r   w  s    r   c                 C   s  i }t |ddg}|d u rd}|dkr(t | dgd ur't|ddgt | dg nJ|dkrAt | dgd ur@t|ddgt | dg n1|d	krZt | dgd urYt|d
dgt | dg n|dkrrt | dgd urrt|ddgt | dg t |ddg}|d u rd}|dkrt | dgd urt|ddgt | dg nJ|dkrt | dgd urt|ddgt | dg n1|d	krt | dgd urt|d
dgt | dg n|dkrt | dgd urt|ddgt | dg t | dgd urtd|S )Nrx   ry   rz   rR  r{   r   r|   r}   r~   r   r   r   r   rS  rT  zpexamples parameter is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.r  r   r"   r"   r#   r     s   







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t | dg t | dgd urQt|dgt | dg t | ddgd urft|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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t | dg|| |S )Nr2   r3   r*   state
createTimecreate_timerX   	startTime
start_timecompleteTimeend_time
updateTimeupdate_timerV   r   r   _selftuned_model)r   r   r   t_tuning_job_statusrQ  r    r"   r"   r#   _TuningJob_from_mldev  sT   ra  c                 C   sn  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t | dg t | dgd urQt|dgt | dg t | dgd urdt|dgt | dg t | d	gd urwt|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t | dg|| t | dgd ur@t|dgtt | dg|| t | dgd urTt|dgt | dg t | dgd urht|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t | d#g|| t | d%gd urt|d&gt | d%g t | d'gd urt|d(gd)d* t | d'gD  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|d0gt | d/g t | d1gd ur%t|d2gt | d1g t | d3gd ur9t|d4gt | d3g t | d5gd urMt|d6gt | d5g t | d7gd urat|d8gt | d7g t | d9gd urut|d:gt | d9g 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 | d?g|| |S )ANr2   r3   r*   rU  rV  rW  rX  rY  endTimer[  r\  r]  errorrV   r   r   
tunedModelr_  r   r   r{   supervised_tuning_specr}   preference_optimization_specr   distillation_specr   reinforcement_tuning_spectuningDataStatstuning_data_statsr   rm   partnerModelTuningSpecpartner_model_tuning_specr   rf   r   ra   evaluateDatasetRunsevaluate_dataset_runsc                 S   r   r"   r"   rD   r"   r"   r#   rH     r   z*_TuningJob_from_vertex.<locals>.<listcomp>
experimentfullFineTuningSpecfull_fine_tuning_specrg   r   rl   pipelineJobpipeline_jobserviceAccountservice_accountr   rT   tuningJobStatetuning_job_stateveoTuningSpecveo_tuning_spectuningJobMetadatatuning_job_metadataveoLoraTuningSpecveo_lora_tuning_specdistillationSamplingSpecdistillation_sampling_spec)r   r   r   r`  r   r1  r   r   r    r"   r"   r#   r     s  










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 |S )Nr2   r3   r*   metadatadonerc  r,   r    r"   r"   r#   _TuningOperation_from_mldev  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 )NrR  r   rS  r,   r    r"   r"   r#   r     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gtt | dg|| t | dgd urDt|dgtt | dg|| t | dgd ur[t|dgtt | dg|| t | dgd urrt|d	gtt | dg|| |S )
Nparentr+   sample_responsesampleResponseexampler0  r   rn   r   )r   r   rR   r/  r>   rM   r    r"   r"   r#   #_ValidateRewardParameters_to_vertex 	  sL   

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rUt|dgdd	 t | dg D  |S )
Nr2   r3   overallRewardoverall_rewardrc  rewardInfoDetailsreward_info_detailsc                 S   s   i | ]\}}||qS r"   r"   )rE   kvr"   r"   r#   
<dictcomp>G	  s    z7_ValidateRewardResponse_from_vertex.<locals>.<dictcomp>)r   r   itemsr    r"   r"   r#   #_ValidateRewardResponse_from_vertex2	  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 )Nreplicated_voice_configreplicatedVoiceConfigprebuilt_voice_configprebuiltVoiceConfig)r   r   r8  r    r"   r"   r#   rJ  M	  s$   


rJ  c                   @     e Z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ddee deej dejdeej dejf
ddZdddddee deej dejdeej dejf
ddZdddddedejdejdeej deej 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eddddedejdeej dejfdd Zdddeej	 de ej fd!d"Z!dS )#TuningsNrx   r*   rx   r   c             	   C     t j||d}| jjr!t|d|}|d}|rd|}nd}nt|d|}|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sui nt|	j}
| jjrt|
d|}
| jjst|
d|}
t jj|
t|ddrdt|j
d	dt|j
d
dt|j
dddini d}t j|	jd|_| j| |S zzGets a TuningJob.

    Args:
      name: The resource name of the tuning job.

    Returns:
      A TuningJob object.
    r*   rx   Nr+   z{name}r   ?rx   getr   r   include_all_fieldsr   r   r  responsekwargsheaders)r
   _GetTuningJobParameters_api_clientvertexair   r  
format_mapr   r   poprx   http_optionsr   convert_to_dictencode_unserializable_typesrequestbodyjsonloadsr   ra  	TuningJob_from_responsegetattrHttpResponser  r3   _verify_responseselfr*   rx   parameter_modelrequest_dictrequest_url_dictpathquery_paramsr  r  response_dictreturn_valuer"   r"   r#   _getj	  s|   






zTunings._getc             	   C   sN  t j|d}| jjstdt|d |}|d}|r!d|}nd}|d}|r3| dt| }|	dd  d }|j
d urJ|j
jd urJ|j
j}t|}t|}| jd|||}|jsbi nt|j}	| jjrrt|	d |}	t jj|	t|dd rdt|j
d	d t|j
d
d t|j
dd dini d}
t j|jd|
_| j|
 |
S Nr  iThis method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode.r+   r   r   r  rx   r  r   r   r  r  r  r  )r
   _ListTuningJobsParametersr  r  rv   r   r  r  r   r  rx   r  r   r  r  r  r  r  r  r   ListTuningJobsResponser  r  r  r  r3   r  r  rx   r  r  r  r  r  r  r  r  r  r"   r"   r#   _list	  sj   





zTunings._listc             	   C   r  )zPCancels a tuning job.

    Args:
      name (str): TuningJob resource name.
    r  Nr+   {name}:cancelr   r  rx   postr   r   r  r  r  r  )r
   _CancelTuningJobParametersr  r  r/   r  r  r-   r   r  rx   r  r   r  r  r  r  r  r  r6   r4   CancelTuningJobResponser  r  r  r  r3   r  r  r"   r"   r#   cancel
  s   






zTunings.cancelr   r   rx   r   r   r   c             	   C   sT  t j||||d}| jjstdt|d|}|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sei nt|j}| jjrut|d|}t jj|t|ddrdt|j
d
dt|j
ddt|j
dddini d}t j|jd|_| j| |S a  Creates a tuning job and returns the TuningJob object.

    Args:
      base_model: The name of the model to tune.
      training_dataset: The training dataset to use.
      config: The configuration to use for the tuning job.

    Returns:
      A TuningJob object.
    r   r   r   rx   r  Nr+   r   r   r  rx   r  r   r   r  r  r  r  )r
   !_CreateTuningJobParametersPrivater  r  rv   r   r  r  r   r  rx   r  r   r  r  r  r  r  r  r   r  r  r  r  r  r3   r  r  r   r   r   rx   r  r  r  r  r  r  r  r  r  r"   r"   r#   _tunem
  t   





zTunings._tunec             	   C   sT  t j||||d}| jjrtdt|d|}|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sei nt|j}| jjsut|d|}t jj|t|ddrdt|j
d
dt|j
ddt|j
dddini d}t j|jd|_| j| |S a  Creates a tuning job and returns the TuningJob object.

    Args:
      base_model: The name of the model to tune.
      training_dataset: The training dataset to use.
      config: The configuration to use for the tuning job.

    Returns:
      A TuningJob operation.
    r  ziThis method is only supported in Gemini Developer API mode, not in Gemini Enterprise Agent Platform mode.Nr+   tunedModelsr   r  rx   r  r   r   r  r  r  r  )r
   r  r  r  rv   r   r  r  r   r  rx   r  r   r  r  r  r  r  r  r  TuningOperationr  r  r  r  r3   r  r  r"   r"   r#   _tune_mldev
  r  zTunings._tune_mldevr0  rn   rx   r  r  r  r0  rn   c             	   C   sX  t j||||||d}| jjstdt|d|}|d}	|	r&d|	}
nd}
|d}|r8|
 dt| }
|	dd d}|j
durO|j
jdurO|j
j}t|}t|}| jd	|
||}|jsgi nt|j}| jjrwt|d|}t jj|t|ddrdt|j
d
dt|j
ddt|j
dddini d}t j|jd|_| j| |S a  Validates a reinforcement tuning reward configuration.

    Allows users to validate a reinforcement tuning reward configuration
    against a sample response and example before creating a reinforcement
    tuning job, so that they can iterate on the reward configuration without
    having to create a tuning job each time.

    Args:
      parent: The resource name of the Location to validate the reward in, e.g.
        `projects/{project}/locations/{location}`.
      sample_response: The sample response for validating the reward
        configuration.
      example: The example to validate the reward configuration.
      single_reward_config: Single reward function configuration for
        reinforcement tuning. Mutually exclusive with composite_reward_config.
      composite_reward_config: Composite reward function configuration for
        reinforcement tuning. Mutually exclusive with single_reward_config.
      config: Optional parameters for the request.

    Returns:
      A ValidateRewardResponse with the computed reward(s).
    )r  r  r  r0  rn   rx   r  Nr+   z5{parent}/tuningJobs:validateReinforcementTuningRewardr   r  rx   r  r   r   r  r  r  r  )r
   _ValidateRewardParametersr  r  rv   r  r  r  r   r  rx   r  r   r  r  r  r  r  r  r  ValidateRewardResponser  r  r  r  r3   r  r  r  r  r  r0  rn   rx   r  r  r  r  r  r  r  r  r  r"   r"   r#   validate_reward'  s~   %






zTunings.validate_rewardc                C   s@   | j ||d}|jr| jjr| jjd urtj|j| jjd |S Nr  )ro  projectr  ro  r  r  r  _IpythonUtilsdisplay_experiment_buttonr  r*   rx   jobr"   r"   r#   r    s   zTunings.getSThe SDK's tuning implementation is experimental, and may change in future versions.c                C   s  | j jr|dr#d }|rt|dd }tj||d}| j|||d}nd }|d urzt|dd d urzt|d}t|trCtj	di |}|j
rI|jsMtdtt|j
D ]}	t|j
|	 trjtj|j
|	 |j
|	< qTt|tru||d< n||_|}| j|||d}|d urt|dd d ur||_n2| j|||d}
|
jd urd|
jv r|
jd }n|
jd u rtd	|
jd
d }tj|tjjd}|jr| j jrtj|jd |S Nz	projects/r^   )tuned_model_namecheckpoint_id)r   r   rx   rf   zEEvaluation config must have at least one metric and an output config.)r   r   rx   rd  zOperation name is required.z/operations/r   )r*   rU  )tuning_job_resourcer"   r  r  
startswithr  r
   PreTunedModelr  
isinstancedictEvaluationConfigr   r   rv   rangelenMetricmodel_validaterf   r  r  r*   	partitionr  JobStateJOB_STATE_QUEUEDr  display_model_tuning_button)r  r   r   rx   r  r   
tuning_jobvalidated_evaluation_configrf   i	operationr  r"   r"   r#   tune  s   






zTunings.tunec                C   s   | j }td|| j |d|S )a  Lists `TuningJob` objects.

    Args:
      config: The configuration for the list request.

    Returns:
      A Pager object that contains one page of tuning jobs. When iterating over
      the pager, it automatically fetches the next page if there are more.

    Usage:

    .. code-block:: python
        for tuning_job in client.tunings.list():
            print(tuning_job.name)
    r   r  )r  r   r  rx   list_requestr"   r"   r#   list  s   
zTunings.list)"__name__
__module____qualname__strr   r
   GetTuningJobConfigOrDictr  r  ListTuningJobsConfigOrDictr  r  CancelTuningJobConfigOrDictr  r  PreTunedModelOrDictTuningDatasetOrDictCreateTuningJobConfigOrDictr  r  r  ContentOrDict ReinforcementTuningExampleOrDict+SingleReinforcementTuningRewardConfigOrDict.CompositeReinforcementTuningRewardConfigOrDictValidateRewardConfigOrDictr  r  r  r   experimental_warningr  r   r  r"   r"   r"   r#   r  h	  s    
_
L
`
`
e	
y
	Pr  c                   @   r  )#AsyncTuningsNr  r*   rx   r   c             	        t j||d}| jjr"t|d|}|d}|rd|}nd}nt|d|}|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syi nt|	j}
| jjrt|
d|}
| jjst|
d|}
t jj|
t|ddrdt|j
d	dt|j
d
dt|j
dddini d}t j|	jd|_| j| |S r  )r
   r  r  r  r   r  r  r   r   r  rx   r  r   r  r  async_requestr  r  r  r   ra  r  r  r  r  r  r3   r  r  r"   r"   r#   r    s   







zAsyncTunings._getc             	      sV  t j|d}| jjstdt|d |}|d}|r"d|}nd}|d}|r4| dt| }|	dd  d }|j
d urK|j
jd urK|j
j}t|}t|}| jd|||I d H }|jsfi nt|j}	| jjrvt|	d |}	t jj|	t|dd rdt|j
d	d t|j
d
d t|j
dd dini d}
t j|jd|
_| j|
 |
S r  )r
   r  r  r  rv   r   r  r  r   r  rx   r  r   r  r  r  r  r  r  r   r  r  r  r  r  r3   r  r  r"   r"   r#   r    sp   






zAsyncTunings._listc             	      r  )zaCancels a tuning job asynchronously.

    Args:
      name (str): A TuningJob resource name.
    r  Nr+   r  r   r  rx   r  r   r   r  r  r  r  )r
   r  r  r  r/   r  r  r-   r   r  rx   r  r   r  r  r  r  r  r  r6   r4   r  r  r  r  r  r3   r  r  r"   r"   r#   r    s   







zAsyncTunings.cancelr  r   r   r   c             	      s\  t j||||d}| jjstdt|d|}|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sii nt|j}| jjryt|d|}t jj|t|ddrdt|j
d
dt|j
ddt|j
dddini d}t j|jd|_| j| |S r  )r
   r  r  r  rv   r   r  r  r   r  rx   r  r   r  r  r  r  r  r  r   r  r  r  r  r  r3   r  r  r"   r"   r#   r  &  v   






zAsyncTunings._tunec             	      s\  t j||||d}| jjrtdt|d|}|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sii nt|j}| jjsyt|d|}t jj|t|ddrdt|j
d
dt|j
ddt|j
dddini d}t j|jd|_| j| |S r  )r
   r  r  r  rv   r   r  r  r   r  rx   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r3   r  r  r"   r"   r#   r    r  zAsyncTunings._tune_mldevr  r  r  r  r0  rn   c             	      s`  t j||||||d}| jjstdt|d|}|d}	|	r'd|	}
nd}
|d}|r9|
 dt| }
|	dd d}|j
durP|j
jdurP|j
j}t|}t|}| jd	|
||I dH }|jski nt|j}| jjr{t|d|}t jj|t|ddrdt|j
d
dt|j
ddt|j
dddini d}t j|jd|_| j| |S r  )r
   r  r  r  rv   r  r  r  r   r  rx   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r3   r  r  r"   r"   r#   r    s   %







zAsyncTunings.validate_rewardc                   sH   | j ||dI d H }|jr"| jjr"| jjd ur"tj|j| jjd |S r  r  r  r"   r"   r#   r  U  s   zAsyncTunings.getr  c                   s  | j jr|dr'd }|rt|dd }tj||d}| j|||dI d H }n|d urzt|dd d urzt|d}t|trEtj	di |}|j
rK|jsOtdtt|j
D ]}t|j
| trltj|j
| |j
|< qVt|trw||d< n||_| j|||dI d H }n5| j|||dI d H }	|	jd urd|	jv r|	jd }
n|	jd u rtd	|	jd
d }
tj|
tjjd}|jr| j jrtj|jd |S r  r  )r  r   r   rx   r  r   r  rf   r  r  r  r"   r"   r#   r  g  sv   






zAsyncTunings.tunec                   s$   | j }td|| j |dI dH |S )a  Lists `TuningJob` objects asynchronously.

    Args:
      config: The configuration for the list request.

    Returns:
      A Pager object that contains one page of tuning jobs. When iterating over
      the pager, it automatically fetches the next page if there are more.

    Usage:

    .. code-block:: python
        async for tuning_job in await client.aio.tunings.list():
            print(tuning_job.name)
    r   r  N)r  r   r  r"   r"   r#   r    s   zAsyncTunings.list)"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    
a
N
`
`
e	
y
	Jr  c                
   @   s   e Zd ZU dZe Zee ed< ede	ee
f fddZedefddZedefdd	Zed
edeje defddZe	ddededee ddfddZedededdfddZededdfddZdS )r  z6Temporary class to hold the IPython related functions.displayed_experimentsr   c                  C   s,   dd l } d| jv rddlm} | jjS dS )Nr   IPython)get_ipython )sysmodulesr  r  	__class__r  )r  r  r"   r"   r#   _get_ipython_shell_name  s
   

z%_IpythonUtils._get_ipython_shell_namec                   C   s   t t S )N)boolr  r  r"   r"   r"   r#   is_ipython_available  s   z"_IpythonUtils.is_ipython_availablec                   C   s   dS )z8Returns the HTML style markup to support custom buttons.a  
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <style>
      .view-vertex-resource,
      .view-vertex-resource:hover,
      .view-vertex-resource:visited {
        position: relative;
        display: inline-flex;
        flex-direction: row;
        height: 32px;
        padding: 0 12px;
          margin: 4px 18px;
        gap: 4px;
        border-radius: 4px;

        align-items: center;
        justify-content: center;
        background-color: rgb(255, 255, 255);
        color: rgb(51, 103, 214);

        font-family: Roboto,"Helvetica Neue",sans-serif;
        font-size: 13px;
        font-weight: 500;
        text-transform: uppercase;
        text-decoration: none !important;

        transition: box-shadow 280ms cubic-bezier(0.4, 0, 0.2, 1) 0s;
        box-shadow: 0px 3px 1px -2px rgba(0,0,0,0.2), 0px 2px 2px 0px rgba(0,0,0,0.14), 0px 1px 5px 0px rgba(0,0,0,0.12);
      }
      .view-vertex-resource:active {
        box-shadow: 0px 5px 5px -3px rgba(0,0,0,0.2),0px 8px 10px 1px rgba(0,0,0,0.14),0px 3px 14px 2px rgba(0,0,0,0.12);
      }
      .view-vertex-resource:active .view-vertex-ripple::before {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        border-radius: 4px;
        pointer-events: none;

        content: '';
        background-color: rgb(51, 103, 214);
        opacity: 0.12;
      }
      .view-vertex-icon {
        font-size: 18px;
      }
    </style>
  r"   r"   r"   r"   r#   _get_styles  s   z_IpythonUtils._get_stylesmarkerresource_partsc                 C   sB   t t|D ]}|| | kr|d t|k r||d    S qdS )z,Returns the part after the marker text part.r   r  )r  r  )r  r  r  r"   r"   r#   _parse_resource_name  s
   z"_IpythonUtils._parse_resource_nameopen_in_newr  urliconNc           	      C   s   d}| |std| dddl}dt|  }dt  d| d	| d
| d|  d}|d| d| d| d7 }ddlm} ddlm	} ||| dS )a@  Creates and displays the link to open the Gemini Enterprise Agent Platform resource.

    Args:
      text: The text displayed on the clickable button.
      url: The url that the button will lead to. Only cloud console URIs are
        allowed.
      icon: The icon name on the button (from material-icons library)
    z https://console.cloud.google.comzOnly urls starting with z are allowed.r   Nzview-vertex-resource-z	
        z-
        <a class="view-vertex-resource" id="z" href="#view-z;">
          <span class="material-icons view-vertex-icon">z</span>
          <span>z</span>
        </a>
        z]
        <script>
          (function () {
            const link = document.getElementById('z');
            link.addEventListener('click', (e) => {
              if (window.google?.colab?.openUrl) {
                window.google.colab.openUrl('z8');
              } else {
                window.open('z', '_blank');
              }
              e.stopPropagation();
              e.preventDefault();
            });
          })();
        </script>
    )display)HTML)
r  rv   uuidr   uuid4r  r  IPython.displayr"  r#  )	r  r   r!  CLOUD_UI_URLr$  	button_idhtmlr"  r#  r"   r"   r#   _display_link#  s4   
	
z_IpythonUtils._display_linkro  r  c                 C   sl   t  r	| t jv rdS | d}|d }|d }d| d| d d|  }t d|d	 t j|  dS )
a\  Function to generate a link bound to the Gemini Enterprise Agent Platform experiment.

    Args:
      experiment: The Gemini Enterprise Agent Platform experiment name. Example
        format:
          projects/{project_id}/locations/{location}/metadataStores/default/contexts/{experiment_name}
      project: The project (alphanumeric) name.
    N/   zAhttps://console.cloud.google.com/vertex-ai/experiments/locations/z/experiments/zruns?project=zView Experimentscience)r  r  r  splitr*  add)ro  r  r  locationexperiment_nameurir"   r"   r#   r  W  s   

z'_IpythonUtils.display_experiment_buttonr  c                 C   s^   t  sdS | d}|d }|d }|d }dd| d|  d	|  }t d
|d dS )a"  Function to generate a link bound to the Gemini Enterprise Agent Platform model tuning job.

    Args:
      tuning_job_resource: The Gemini Enterprise Agent Platform tuning job name.
        Example format:
        projects/{project_id}/locations/{location}/tuningJobs/{tuning_job_id}
    Nr+  r   r,  r-  z?https://console.cloud.google.com/vertex-ai/generative/language/z
locations/z/tuning/tuningJob/z	?project=zView Tuning Jobr  )r  r  r/  r*  )r  r  r  r1  tuning_job_idr3  r"   r"   r#   r  v  s   	
z)_IpythonUtils.display_model_tuning_button)r  )r  r  r  __doc__setr  r   __annotations__staticmethodr   r   r  r  r  r  builtinsr  r  r   r*  r  r  r"   r"   r"   r#   r    s@   
 	5	3r  )NN)Or9  r  loggingtypingr   r   r   urllib.parser   r  r   r   r	   r   r
   r   r   r   r   pagersr   r   	getLoggerloggerr  r   objectr$   r'   r-   r/   r4   r6   r<   r?   rK   rM   rR   rw   r   r   r   r   r   r   r   r   r   r&   r   r   r   r   r   r  rO   r(  r*  r/  r1  r8  r;   r>   r  r   rQ  r   r   ra  r   r  r   r  r  rJ  
BaseModuler  r  r  r"   r"   r"   r#   <module>   s`  
























 :

   





'

0

D

%

%

}

 













X

.

.

!

0

!

3

3



"





R

=

 8





4



     :     8