@@ -209,7 +209,7 @@ def create(
209
209
# This involves packaging and uploading the artifacts for
210
210
# reasoning_engine, requirements and extra_packages to
211
211
# `staging_bucket/gcs_dir_name`.
212
- _prepare (
212
+ _prepare_create (
213
213
reasoning_engine = reasoning_engine ,
214
214
requirements = requirements ,
215
215
project = sdk_resource .project ,
@@ -304,11 +304,15 @@ def update(
304
304
305
305
Args:
306
306
reasoning_engine (ReasoningEngineInterface):
307
- Optional. The Reasoning Engine to be replaced.
307
+ Optional. The Reasoning Engine to be replaced. If it is not
308
+ specified, the existing Reasoning Engine will be used.
308
309
requirements (Union[str, Sequence[str]]):
309
310
Optional. The set of PyPI dependencies needed. It can either be
310
311
the path to a single file (requirements.txt), or an ordered list
311
312
of strings corresponding to each line of the requirements file.
313
+ If it is not specified, the existing requirements will be used.
314
+ If it is set to an empty string or list, the existing
315
+ requirements will be removed.
312
316
display_name (str):
313
317
Optional. The user-defined name of the Reasoning Engine.
314
318
The name can be up to 128 characters long and can comprise any
@@ -322,7 +326,10 @@ def update(
322
326
Optional. The Python system version used. Currently updating
323
327
sys version is not supported.
324
328
extra_packages (Sequence[str]):
325
- Optional. The set of extra user-provided packages (if any).
329
+ Optional. The set of extra user-provided packages (if any). If
330
+ it is not specified, the existing extra packages will be used.
331
+ If it is set to an empty list, the existing extra packages will
332
+ be removed.
326
333
327
334
Returns:
328
335
ReasoningEngine: The Reasoning Engine that was updated.
@@ -359,18 +366,18 @@ def update(
359
366
)
360
367
if sys_version :
361
368
_LOGGER .warning ("Updated sys_version is not supported." )
362
- if requirements :
369
+ if requirements is not None :
363
370
requirements = _validate_requirements_or_raise (requirements )
364
- if extra_packages :
371
+ if extra_packages is not None :
365
372
extra_packages = _validate_extra_packages_or_raise (extra_packages )
366
- if reasoning_engine :
373
+ if reasoning_engine is not None :
367
374
reasoning_engine = _validate_reasoning_engine_or_raise (reasoning_engine )
368
375
369
- # Prepares the Reasoning Engine for creation in Vertex AI.
376
+ # Prepares the Reasoning Engine for update in Vertex AI.
370
377
# This involves packaging and uploading the artifacts for
371
378
# reasoning_engine, requirements and extra_packages to
372
379
# `staging_bucket/gcs_dir_name`.
373
- _prepare (
380
+ _prepare_update (
374
381
reasoning_engine = reasoning_engine ,
375
382
requirements = requirements ,
376
383
project = self .project ,
@@ -392,14 +399,11 @@ def update(
392
399
operation_future = self .api_client .update_reasoning_engine (
393
400
request = update_request
394
401
)
395
- _LOGGER .log_create_with_lro (ReasoningEngine , operation_future )
396
- created_resource = operation_future .result ()
397
- _LOGGER .log_create_complete (
398
- ReasoningEngine ,
399
- created_resource ,
400
- self ._resource_noun ,
401
- module_name = "vertexai.preview.reasoning_engines" ,
402
+ _LOGGER .info (
403
+ f"Update ReasoningEngine backing LRO: { operation_future .operation .name } "
402
404
)
405
+ created_resource = operation_future .result ()
406
+ _LOGGER .info (f"ReasoningEngine updated. Resource name: { created_resource .name } " )
403
407
self ._operation_schemas = None
404
408
return self
405
409
@@ -560,7 +564,7 @@ def _upload_extra_packages(
560
564
_LOGGER .info (f"Writing to { dir_name } /{ _EXTRA_PACKAGES_FILE } " )
561
565
562
566
563
- def _prepare (
567
+ def _prepare_create (
564
568
reasoning_engine : Queryable ,
565
569
requirements : Sequence [str ],
566
570
extra_packages : Sequence [str ],
@@ -571,7 +575,10 @@ def _prepare(
571
575
) -> None :
572
576
"""Prepares the reasoning engine for creation in Vertex AI.
573
577
574
- This involves packaging and uploading the artifacts to Cloud Storage.
578
+ This involves packaging and uploading artifacts to Cloud Storage. Note that
579
+ 1. This does not actually create the Reasoning Engine in Vertex AI.
580
+ 2. This will always generate and upload a pickled object.
581
+ 3. This will always generate and upload the dependencies.tar.gz file.
575
582
576
583
Args:
577
584
reasoning_engine: The reasoning engine to be prepared.
@@ -584,11 +591,45 @@ def _prepare(
584
591
use for staging the artifacts needed.
585
592
"""
586
593
gcs_bucket = _get_gcs_bucket (project , location , staging_bucket )
587
- if reasoning_engine :
588
- _upload_reasoning_engine (reasoning_engine , gcs_bucket , gcs_dir_name )
594
+ _upload_reasoning_engine (reasoning_engine , gcs_bucket , gcs_dir_name )
589
595
if requirements :
590
596
_upload_requirements (requirements , gcs_bucket , gcs_dir_name )
591
- if extra_packages :
597
+ _upload_extra_packages (extra_packages , gcs_bucket , gcs_dir_name )
598
+
599
+
600
+ def _prepare_update (
601
+ reasoning_engine : Optional [Queryable ],
602
+ requirements : Optional [Sequence [str ]],
603
+ extra_packages : Optional [Sequence [str ]],
604
+ project : str ,
605
+ location : str ,
606
+ staging_bucket : str ,
607
+ gcs_dir_name : str ,
608
+ ) -> None :
609
+ """Prepares the reasoning engine for updates in Vertex AI.
610
+
611
+ This involves packaging and uploading artifacts to Cloud Storage. Note that
612
+ 1. This does not actually update the Reasoning Engine in Vertex AI.
613
+ 2. This will only generate and upload a pickled object if specified.
614
+ 3. This will only generate and upload the dependencies.tar.gz file if
615
+ extra_packages is non-empty.
616
+
617
+ Args:
618
+ reasoning_engine: The reasoning engine to be prepared.
619
+ requirements (Sequence[str]): The set of PyPI dependencies needed.
620
+ extra_packages (Sequence[str]): The set of extra user-provided packages.
621
+ project (str): The project for the staging bucket.
622
+ location (str): The location for the staging bucket.
623
+ staging_bucket (str): The staging bucket name in the form "gs://...".
624
+ gcs_dir_name (str): The GCS bucket directory under `staging_bucket` to
625
+ use for staging the artifacts needed.
626
+ """
627
+ gcs_bucket = _get_gcs_bucket (project , location , staging_bucket )
628
+ if reasoning_engine is not None :
629
+ _upload_reasoning_engine (reasoning_engine , gcs_bucket , gcs_dir_name )
630
+ if requirements is not None :
631
+ _upload_requirements (requirements , gcs_bucket , gcs_dir_name )
632
+ if extra_packages is not None :
592
633
_upload_extra_packages (extra_packages , gcs_bucket , gcs_dir_name )
593
634
594
635
@@ -607,23 +648,23 @@ def _generate_update_request_or_raise(
607
648
update_masks : List [str ] = []
608
649
reasoning_engine_spec = types .ReasoningEngineSpec ()
609
650
package_spec = types .ReasoningEngineSpec .PackageSpec ()
610
- if requirements :
651
+ if requirements is not None :
611
652
is_spec_update = True
612
653
update_masks .append ("spec.package_spec.requirements_gcs_uri" )
613
654
package_spec .requirements_gcs_uri = "{}/{}/{}" .format (
614
655
staging_bucket ,
615
656
gcs_dir_name ,
616
657
_REQUIREMENTS_FILE ,
617
658
)
618
- if extra_packages :
659
+ if extra_packages is not None :
619
660
is_spec_update = True
620
661
update_masks .append ("spec.package_spec.dependency_files_gcs_uri" )
621
662
package_spec .dependency_files_gcs_uri = "{}/{}/{}" .format (
622
663
staging_bucket ,
623
664
gcs_dir_name ,
624
665
_EXTRA_PACKAGES_FILE ,
625
666
)
626
- if reasoning_engine :
667
+ if reasoning_engine is not None :
627
668
is_spec_update = True
628
669
update_masks .append ("spec.package_spec.pickle_object_gcs_uri" )
629
670
package_spec .pickle_object_gcs_uri = "{}/{}/{}" .format (
0 commit comments