o
    i*P                     @   s  U d Z ddlmZ ddlmZ ddlZddd	Zejejd
ddgej	ej
ddddZejdejdejdddddejdejdejdddddejdejdejddejdddddejd ejdejddejd!d"d#d$dd%dejd&ejdejddejd!d"ejjd'd(dd%dejd)ejdejddejdddd*dejd+ejdejddejd!d"d,d-ejd.dd/dddejd0ejdejd1d2dd3dejd4ejdejd1d2ejd!d"d,d-ejd5d2d6d7id8dd3dejd9ejd:ejd;dejd<d=d>ejd?dd@edAdd%dejdBejd:ejd;dejd>ejd?ddCdDedEddFdejdGejd:ejd;dejd>ejd?ddHdIdCdDedJddFdejdKejd:ejd;dejd<d=d>ejd?ddCdDedLddFdejdMejdejddejejdNdOdPddFdgZeej edQ< ejee dRedSZdTZejjdUdVdWdXdY ZejjdUdVdWdZd[ ZejjdUdVdWd\d] Z ejjdUdVdWd^d_ Z!ejjdUdVdWejj"d`da Z#dS )bzTests for tunings.tune().   )types   )pytest_helper    Nv1beta1z?https://us-central1-autopush-aiplatform.sandbox.googleapis.com/)api_versionbase_urlbleuztest prompt template)nameprompt_templategs://sararob_test/output_uri_prefixgcs_destination)metricsoutput_configtest_dataset_gcs_urigemini-2.5-flashzVgs://cloud-samples-data/ai-platform/generative_ai/gemini-1_5/text/sft_train_data.jsonlgcs_uri)
base_modeltraining_datasetz1gcs_uri parameter is not supported in Gemini API.)r
   
parametersexception_if_mldevtest_tune_pretuned_modelzFprojects/801452371447/locations/us-central1/models/9030969596621881344Vgs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/text/sft_train_data.jsonlzis not supported in Gemini API+test_tune_pretuned_model_with_checkpoint_id3)pre_tuned_model_checkpoint_idr   r   configtest_tune_simple_dpozModel display name   PREFERENCE_TUNING)tuned_model_display_nameepoch_countmethodz)parameter is not supported in Gemini API.test_tune_dpo_with_betag      ?)r%   r&   r'   beta*test_non_pretuned_model_with_checkpoint_idzis not supported in Gemini API.#test_dataset_gcs_uri_all_parameters      ?ADAPTER_SIZE_ONEz[gs://cloud-samples-data/ai-platform/generative_ai/gemini-1_5/text/sft_validation_data.jsonl)r%   r&   learning_rate_multiplieradapter_sizevalidation_dataset$test_dataset_vertex_dataset_resourcezHprojects/801452371447/locations/us-central1/datasets/5779918772206829568)vertex_dataset_resourcezAvertex_dataset_resource parameter is not supported in Gemini API.,test_dataset_dataset_resource_all_parameterszHprojects/801452371447/locations/us-central1/datasets/1168232753779441664testlabelkeytestlabelvalue)r%   r&   r.   r/   r0   labelstest_tune_distillationz#meta/llama3_1@llama-3.1-8b-instructzEgs://nathreya-oss-tuning-sdk-test/distillation-openai-opposites.jsonlDISTILLATIONzdeepseek-ai/deepseek-v3.1-maas   zIgs://nathreya-oss-tuning-sdk-test/distillation-val-openai-opposites.jsonlzDgs://nathreya-oss-tuning-sdk-test/ayushagra-distillation-test-folder)r'   base_teacher_modelr&   r0   
output_urihttp_optionstest_tune_oss_sftzigs://nathreya-oss-tuning-sdk-test/ayushagra-distillation-test-folder/postprocess/node-0/checkpoints/finalz=gs://nathreya-oss-tuning-sdk-test/ayushagra-distillation-test)r&   r0   custom_base_modelr;   r<   znot supported in Gemini APItest_tune_oss_sft_hyperparamsgMb0?TUNING_MODE_FULL)r&   r0   learning_ratetuning_moder>   r;   r<   test_tune_oss_distillation)r'   r:   r&   r0   r>   r;   r<   test_tune_encryption_speczZprojects/vertex-sdk-dev/locations/us-central1/keyRings/ayush-test-key/cryptoKeys/ayush-key)kms_key_name)encryption_spec
test_tableztunings.tune)fileglobals_for_filetest_methodrG   )pytest_asynciozconfig.getoption('--private')zSkipping in pre-public tests)reasonc                 C   sd   | j jr.| jjdtjddtjddddtjddtd	d
}|j	tj
jks'J |jtks0J dS dS zTests tuning with eval config.r   r   r   tuning job with eval configr#   r,   r-   [gs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/text/sft_validation_data.jsonlr%   r&   r.   r/   r0   evaluation_configr    N)_api_clientvertexaituningstunegenai_typesTuningDatasetCreateTuningJobConfigTuningValidationDatasetrQ   stateJobStateJOB_STATE_PENDINGclient
tuning_job r`   b/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/google/genai/tests/tunings/test_tune.pytest_eval_config  s&   
rb   c                 C   s   | j jrNtjtjdddddtjddtjddgtjtjd	d
dtjdddd}| jj	dtj
ddtjddddtjdd|dd}|jtjjksPJ dS dS )&Tests tuning with eval config metrics.prompt-relevanceXHow well does the response address the prompt?: PROMPT: {request}
 RESPONSE: {response}
T:You are a cat. Make all evaluations from this perspective.r
   r   return_raw_outputjudge_model_system_instructionr	   )r
   rouge_1r   r   r   r#   
test-modelsampling_countautorater_modelr   r   autorater_configr   r   r   rN   r,   r-   rO   rP   r    N)rR   rS   rV   EvaluationConfigMetricOutputConfigGcsDestinationAutoraterConfigrT   rU   rW   rX   rY   rZ   r[   r\   r^   rQ   r_   r`   r`   ra   test_eval_config_with_metrics.  sL   



$rw   c                 C   s   | j jr]tjtjtjddtjddddtjtjdddtjtjd	d
dgtj	tj
dddtjdddd}| jjdtjddtjddddtjdd|dd}|jtjjks_J dS dS )rc   re   rf   T)rh   )metric_prompt_templatesystem_instructioncustom_output_format_config)pointwise_metric_spec)use_effective_order)	bleu_specrouge1)
rouge_type)
rouge_specr   r   r   r#   rk   rl   ro   r   r   r   rN   r,   r-   rO   rP   r    N)rR   rS   rV   rq   UnifiedMetricPointwiseMetricSpecCustomOutputFormatConfigBleuSpec	RougeSpecrs   rt   ru   rT   rU   rW   rX   rY   rZ   r[   r\   rv   r`   r`   ra   %test_eval_config_with_unified_metrics[  sZ   

!
0r   c                 C   s   | j jrMtjdddddddiddid	d
diigtjtjdddtjdddd}| jjdtj	ddtj
ddddtjdd|dd}|jtjjksOJ dS dS )rc   rd   re   Trf   rg   r
   r	   rj   r}   r|   r   r   r   r#   rk   rl   ro   r   r   r   rN   r,   r-   rO   rP   r    N)rR   rS   rV   rq   rs   rt   ru   rT   rU   rW   rX   rY   rZ   r[   r\   rv   r`   r`   ra   "test_eval_config_with_metrics_dict  sR   
)r   c                    s`   | j jr,| jjjdtjddtjddddtjddt	d	d
I dH }|j
tjjks.J dS dS rM   )rR   rS   aiorT   rU   rV   rW   rX   rY   rQ   rZ   r[   r\   r]   r`   r`   ra   test_eval_config_async  s&   
r   )$__doc__ r   rV   r   pytestVERTEX_HTTP_OPTIONSrq   rr   rs   rt   rQ   TestTableItemCreateTuningJobParametersrW   rX   TuningMethodr$   rY   EncryptionSpecrG   list__annotations__setup__file__globals
pytestmarkpytest_pluginsmarkskipifrb   rw   r   r   asyncior   r`   r`   r`   ra   <module>   s$  

		
  b

)
5
/