Source code for chariot.training_v2.blueprint

from chariot import _apis
from chariot.config import getLogger
from chariot.training_v2.exceptions import BlueprintDoesNotExistError

__all__ = ["lookup_blueprint_id"]

log = getLogger(__name__)


[docs] def lookup_blueprint_id( name: str, version_ilike: str | None = None, ) -> str: """Returns the id of the blueprint specified by the arguments Parameters ---------- name : str name of the blueprint. if `version_ilike` is not provided, then the latest version of the blueprint with this name will be used. version_ilike : str this parameter accepts a SQL ILIKE pattern for matching a blueprint version. If multiple blueprints match the given version, the most recent one will be used. Returns ------- str : id of the blueprint Raises ------ BlueprintDoesNotExistError If the blueprint does not exist or has been deleted, this will be raised. ValueError If `name` is not provided. APIException If api communication fails, request is unauthorized or is unauthenticated. """ if not name: raise ValueError("Missing name argument.") if not version_ilike: blueprints = _apis.training_v2.v2_blueprints_api.v2_blueprints_get( name=[name], sort=["created_at:desc"], select=["id"], ).data else: blueprints = _apis.training_v2.v2_blueprints_api.v2_blueprints_get( name=[name], version_ilike=[version_ilike], select=["id"], sort=["created_at:desc"], ).data if len(blueprints) == 0: raise BlueprintDoesNotExistError( name=name, version_ilike=version_ilike, ) log.debug( f"Found {len(blueprints)} blueprints named='{name}' " f"version_ilike='{version_ilike}' returning blueprint={{{blueprints[0]}}}" ) return blueprints[0].id