Skip to content

Commit f228286

Browse files
add substring util
1 parent 2f3c48a commit f228286

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

ads/aqua/deployment.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
UNKNOWN_DICT,
2323
get_resource_name,
2424
get_model_by_reference_paths,
25+
get_ocid_substring,
2526
)
2627
from ads.aqua.finetune import FineTuneCustomMetadata
2728
from ads.aqua.data import AquaResourceIdentifier
@@ -393,9 +394,8 @@ def create(
393394

394395
model_type = "custom" if is_fine_tuned_model else "service"
395396
deployment_id = deployment.dsc_model_deployment.id
396-
telemetry_kwargs = (
397-
{"ocid": deployment_id[-8:]} if len(deployment_id) > 8 else {}
398-
)
397+
telemetry_kwargs = {"ocid": get_ocid_substring(deployment_id, key_len=8)}
398+
399399
# tracks unique deployments that were created in the user compartment
400400
self.telemetry.record_event_async(
401401
category=f"aqua/{model_type}/deployment",
@@ -464,7 +464,7 @@ def list(self, **kwargs) -> List["AquaDeployment"]:
464464
self.telemetry.record_event_async(
465465
category=f"aqua/deployment",
466466
action="list",
467-
detail=deployment_id[-8:] if len(deployment_id) > 8 else "",
467+
detail=get_ocid_substring(deployment_id, key_len=8),
468468
value=state,
469469
)
470470

ads/aqua/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,3 +741,9 @@ def known_realm():
741741
742742
"""
743743
return os.environ.get("CONDA_BUCKET_NS") in AQUA_GA_LIST
744+
745+
746+
def get_ocid_substring(ocid: str, key_len: int = 8) -> str:
747+
"""This helper function returns the last n characters of the ocid specified by key_len parameter, which defaults
748+
to 8. If ocid is None or length is less than key_len, it returns an empty string."""
749+
return ocid[-key_len:] if ocid and len(ocid) > key_len else ""

0 commit comments

Comments
 (0)