@@ -407,37 +407,46 @@ def _wait_for_completion(self, job_name: str) -> types.CustomJob:
407407
408408 def optimize (
409409 self ,
410- method : str ,
411- config : types .PromptOptimizerVAPOConfigOrDict ,
410+ method : types . PromptOptimizerMethod ,
411+ config : types .PromptOptimizerConfigOrDict ,
412412 ) -> types .CustomJob :
413413 """Call PO-Data optimizer.
414414
415415 Args:
416- method: The method for optimizing multiple prompts.
417- config: PromptOptimizerVAPOConfig instance containing the
416+ method: The method for optimizing multiple prompts. Supported methods:
417+ VAPO, OPTIMIZATION_TARGET_GEMINI_NANO.
418+ config: PromptOptimizerConfig instance containing the
418419 configuration for prompt optimization.
419420 Returns:
420421 The custom job that was created.
421422 """
422423
423- if method != "vapo" :
424- raise ValueError ("Only vapo method is currently supported." )
425-
426424 if isinstance (config , dict ):
427- config = types .PromptOptimizerVAPOConfig (** config )
425+ config = types .PromptOptimizerConfig (** config )
426+
427+ if not config .config_path :
428+ raise ValueError ("Config path is required." )
429+
430+ _OPTIMIZER_METHOD_TO_CONTAINER_URI = {
431+ types .PromptOptimizerMethod .VAPO : "us-docker.pkg.dev/vertex-ai/cair/vaipo:preview_v1_0" ,
432+ types .PromptOptimizerMethod .OPTIMIZATION_TARGET_GEMINI_NANO : "us-docker.pkg.dev/vertex-ai/cair/android-apo:preview_v1_0" ,
433+ }
434+ container_uri = _OPTIMIZER_METHOD_TO_CONTAINER_URI .get (method )
435+ if not container_uri :
436+ raise ValueError (
437+ 'Only "VAPO" and "OPTIMIZATION_TARGET_GEMINI_NANO" '
438+ "methods are currently supported."
439+ )
428440
429441 if config .optimizer_job_display_name :
430442 display_name = config .optimizer_job_display_name
431443 else :
432444 timestamp = datetime .datetime .now ().strftime ("%Y%m%d-%H%M%S" )
433- display_name = f"vapo-optimizer-{ timestamp } "
445+ display_name = f"{ method .value .lower ()} -optimizer-{ timestamp } "
446+
434447 wait_for_completion = config .wait_for_completion
435- if not config .config_path :
436- raise ValueError ("Config path is required." )
437448 bucket = "/" .join (config .config_path .split ("/" )[:- 1 ])
438449
439- container_uri = "us-docker.pkg.dev/vertex-ai/cair/vaipo:preview_v1_0"
440-
441450 region = self ._api_client .location
442451 project = self ._api_client .project
443452 container_args = {
@@ -766,8 +775,8 @@ async def _get_custom_job(
766775 # Todo: b/428953357 - Add example in the README.
767776 async def optimize (
768777 self ,
769- method : str ,
770- config : types .PromptOptimizerVAPOConfigOrDict ,
778+ method : types . PromptOptimizerMethod ,
779+ config : types .PromptOptimizerConfigOrDict ,
771780 ) -> types .CustomJob :
772781 """Call async Vertex AI Prompt Optimizer (VAPO).
773782
@@ -777,26 +786,37 @@ async def optimize(
777786
778787 Example usage:
779788 client = vertexai.Client(project=PROJECT_NAME, location='us-central1')
780- vapo_config = vertexai.types.PromptOptimizerVAPOConfig (
789+ vapo_config = vertexai.types.PromptOptimizerConfig (
781790 config_path='gs://you-bucket-name/your-config.json',
782791 service_account=service_account,
783792 )
784793 job = await client.aio.prompt_optimizer.optimize(
785- method='vapo' , config=vapo_config)
794+ method=types.PromptOptimizerMethod.VAPO , config=vapo_config)
786795
787796 Args:
788- method: The method for optimizing multiple prompts (currently only
789- vapo is supported) .
790- config: PromptOptimizerVAPOConfig instance containing the
797+ method: The method for optimizing multiple prompts. Supported methods:
798+ VAPO, OPTIMIZATION_TARGET_GEMINI_NANO .
799+ config: PromptOptimizerConfig instance containing the
791800 configuration for prompt optimization.
792801 Returns:
793802 The custom job that was created.
794803 """
795- if method != "vapo" :
796- raise ValueError ("Only vapo methods is currently supported." )
797-
798804 if isinstance (config , dict ):
799- config = types .PromptOptimizerVAPOConfig (** config )
805+ config = types .PromptOptimizerConfig (** config )
806+
807+ if not config .config_path :
808+ raise ValueError ("Config path is required." )
809+
810+ _OPTIMIZER_METHOD_TO_CONTAINER_URI = {
811+ types .PromptOptimizerMethod .VAPO : "us-docker.pkg.dev/vertex-ai/cair/vaipo:preview_v1_0" ,
812+ types .PromptOptimizerMethod .OPTIMIZATION_TARGET_GEMINI_NANO : "us-docker.pkg.dev/vertex-ai/cair/android-apo:preview_v1_0" ,
813+ }
814+ container_uri = _OPTIMIZER_METHOD_TO_CONTAINER_URI .get (method )
815+ if not container_uri :
816+ raise ValueError (
817+ 'Only "VAPO" and "OPTIMIZATION_TARGET_GEMINI_NANO" '
818+ "methods are currently supported."
819+ )
800820
801821 if config .wait_for_completion :
802822 logger .info (
@@ -807,14 +827,12 @@ async def optimize(
807827 display_name = config .optimizer_job_display_name
808828 else :
809829 timestamp = datetime .datetime .now ().strftime ("%Y%m%d-%H%M%S" )
810- display_name = f"vapo -optimizer-{ timestamp } "
830+ display_name = f"{ method . value . lower () } -optimizer-{ timestamp } "
811831
812832 if not config .config_path :
813833 raise ValueError ("Config path is required." )
814834 bucket = "/" .join (config .config_path .split ("/" )[:- 1 ])
815835
816- container_uri = "us-docker.pkg.dev/vertex-ai/cair/vaipo:preview_v1_0"
817-
818836 region = self ._api_client .location
819837 project = self ._api_client .project
820838 container_args = {
0 commit comments