@@ -714,11 +714,12 @@ def convert_parser(subparsers):
714714 )
715715 parser .add_argument (
716716 "--type" ,
717- default = "raw" ,
718- choices = ["car" , "raw" ],
717+ default = CONFIG . convert_type ,
718+ choices = ["artifact" , " car" , "raw" ],
719719 help = """\
720720 type of OCI Model Image to push.
721721
722+ Model "artifact" stores the AI Model as an OCI Artifact.
722723Model "car" includes base image with the model stored in a /models subdir.
723724Model "raw" contains the model and a link file model.file to it stored at /.""" ,
724725 )
@@ -755,11 +756,12 @@ def push_parser(subparsers):
755756 add_network_argument (parser )
756757 parser .add_argument (
757758 "--type" ,
758- default = "raw" ,
759- choices = ["car" , "raw" ],
759+ default = CONFIG . convert_type ,
760+ choices = ["artifact" , " car" , "raw" ],
760761 help = """\
761762 type of OCI Model Image to push.
762763
764+ Model "artifact" stores the AI Model as an OCI Artifact.
763765Model "car" includes base image with the model stored in a /models subdir.
764766Model "raw" contains the model and a link file model.file to it stored at /.""" ,
765767 )
@@ -774,20 +776,28 @@ def push_parser(subparsers):
774776 parser .set_defaults (func = push_cli )
775777
776778
777- def _get_source_model (args ):
779+ def _get_source_model (args , transport = None ):
778780 src = shortnames .resolve (args .SOURCE )
779- smodel = New (src , args )
781+ smodel = New (src , args , transport = transport )
780782 if smodel .type == "OCI" :
783+ if not args .TARGET :
784+ return smodel
781785 raise ValueError (f"converting from an OCI based image { src } is not supported" )
782786 if not smodel .exists () and not args .dryrun :
783787 smodel .pull (args )
784788 return smodel
785789
786790
787791def push_cli (args ):
788- source_model = _get_source_model (args )
789792 target = args .SOURCE
793+ transport = None
794+ if not args .TARGET :
795+ transport = "oci"
796+ source_model = _get_source_model (args , transport = transport )
797+
790798 if args .TARGET :
799+ if source_model .type == "OCI" :
800+ raise ValueError (f"converting from an OCI based image { args .SOURCE } is not supported" )
791801 target = shortnames .resolve (args .TARGET )
792802 target_model = New (target , args )
793803
@@ -1169,9 +1179,14 @@ def serve_cli(args):
11691179 model .ensure_model_exists (args )
11701180 except KeyError as e :
11711181 try :
1182+ if "://" in args .MODEL :
1183+ raise e
11721184 args .quiet = True
11731185 model = TransportFactory (args .MODEL , args , ignore_stderr = True ).create_oci ()
11741186 model .ensure_model_exists (args )
1187+ # Since this is a OCI model, prepend oci://
1188+ args .MODEL = f"oci://{ args .MODEL } "
1189+
11751190 except Exception :
11761191 raise e
11771192
@@ -1412,27 +1427,42 @@ def rm_parser(subparsers):
14121427 parser .set_defaults (func = rm_cli )
14131428
14141429
1430+ def _rm_oci_model (model , args ) -> bool :
1431+ # attempt to remove as a container image
1432+ try :
1433+ m = TransportFactory (model , args , ignore_stderr = True ).create_oci ()
1434+ return m .remove (args )
1435+ except Exception :
1436+ return False
1437+
1438+
14151439def _rm_model (models , args ):
1440+ exceptions = []
14161441 for model in models :
14171442 model = shortnames .resolve (model )
14181443
14191444 try :
14201445 m = New (model , args )
1421- m .remove (args )
1422- except KeyError as e :
1446+ if m .remove (args ):
1447+ continue
1448+ # Failed to remove and might be OCI so attempt to remove OCI
1449+ if args .ignore :
1450+ _rm_oci_model (model , args )
1451+ continue
1452+ except (KeyError , subprocess .CalledProcessError ) as e :
14231453 for prefix in MODEL_TYPES :
14241454 if model .startswith (prefix + "://" ):
14251455 if not args .ignore :
14261456 raise e
1427- try :
1428- # attempt to remove as a container image
1429- m = TransportFactory ( model , args , ignore_stderr = True ). create_oci ()
1430- m . remove ( args )
1431- return
1432- except Exception :
1433- pass
1434- if not args . ignore :
1435- raise e
1457+ # attempt to remove as a container image
1458+ if _rm_oci_model ( model , args ) or args . ignore :
1459+ continue
1460+ exceptions . append ( e )
1461+
1462+ if len ( exceptions ) > 0 :
1463+ for exception in exceptions [: 1 ]:
1464+ perror ( exception )
1465+ raise exceptions [ 0 ]
14361466
14371467
14381468def rm_cli (args ):
@@ -1524,9 +1554,11 @@ def eprint(e, exit_code):
15241554 args .func (args )
15251555 except urllib .error .HTTPError as e :
15261556 eprint (f"pulling { e .geturl ()} failed: { e } " , errno .EINVAL )
1557+ except FileNotFoundError as e :
1558+ eprint (e , errno .ENOENT )
15271559 except HelpException :
15281560 parser .print_help ()
1529- except (ConnectionError , IndexError , KeyError , ValueError , NoRefFileFound ) as e :
1561+ except (IsADirectoryError , ConnectionError , IndexError , KeyError , ValueError , NoRefFileFound ) as e :
15301562 eprint (e , errno .EINVAL )
15311563 except NotImplementedError as e :
15321564 eprint (e , errno .ENOSYS )
0 commit comments