@@ -24,7 +24,7 @@ func newPackagedCmd() *cobra.Command {
2424 var opts packageOptions
2525
2626 c := & cobra.Command {
27- Use : "package --gguf <path> [--license <path>...] [--context-size <tokens>] [--push] TARGET " ,
27+ Use : "package --gguf <path> [--license <path>...] [--context-size <tokens>] [--push] [<tag>] " ,
2828 Short : "Package a GGUF file into a Docker model OCI artifact, with optional licenses. The package is sent to the model-runner, unless --push is specified" ,
2929 Args : func (cmd * cobra.Command , args []string ) error {
3030 if len (args ) != 1 {
@@ -61,7 +61,7 @@ func newPackagedCmd() *cobra.Command {
6161 return nil
6262 },
6363 RunE : func (cmd * cobra.Command , args []string ) error {
64- if err := packageModel (cmd , args [ 0 ], opts ); err != nil {
64+ if err := packageModel (cmd , opts ); err != nil {
6565 cmd .PrintErrln ("Failed to package model" )
6666 return fmt .Errorf ("package model: %w" , err )
6767 }
@@ -72,7 +72,7 @@ func newPackagedCmd() *cobra.Command {
7272
7373 c .Flags ().StringVar (& opts .ggufPath , "gguf" , "" , "absolute path to gguf file (required)" )
7474 c .Flags ().StringArrayVarP (& opts .licensePaths , "license" , "l" , nil , "absolute path to a license file" )
75- c .Flags ().BoolVar (& opts .push , "push" , false , "push to registry. If not set, the package is loaded into the Model Runner content store." )
75+ c .Flags ().BoolVar (& opts .push , "push" , false , "push to registry (if not set, the model is loaded into the Model Runner content store." )
7676 c .Flags ().Uint64Var (& opts .contextSize , "context-size" , 0 , "context size in tokens" )
7777 return c
7878}
@@ -82,26 +82,20 @@ type packageOptions struct {
8282 licensePaths []string
8383 push bool
8484 contextSize uint64
85+ tag string
8586}
8687
87- func packageModel (cmd * cobra.Command , tag string , opts packageOptions ) error {
88+ func packageModel (cmd * cobra.Command , opts packageOptions ) error {
8889 var (
8990 target builder.Target
9091 err error
9192 )
9293 if opts .push {
93- cmd .PrintErrln ("Pushing model...%q\n " , tag )
94- var err error
9594 target , err = registry .NewClient (
9695 registry .WithUserAgent ("docker-model-cli/" + desktop .Version ),
97- ).NewTarget (tag )
98- if err != nil {
99- return err
100- }
101- cmd .PrintErrln ("Pushing to registry..." )
96+ ).NewTarget (opts .tag )
10297 } else {
103- cmd .PrintErrln ("Loading Model..." )
104- target , err = newModelRunnerTarget (desktopClient , tag )
98+ target , err = newModelRunnerTarget (desktopClient , opts .tag )
10599 }
106100 if err != nil {
107101 return err
@@ -129,6 +123,11 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
129123 }
130124 }
131125
126+ if opts .push {
127+ cmd .PrintErrln ("Pushing model to registry..." )
128+ } else {
129+ cmd .PrintErrln ("Loading model to Model Runner..." )
130+ }
132131 pr , pw := io .Pipe ()
133132 done := make (chan error , 1 )
134133 go func () {
@@ -159,9 +158,9 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
159158 }
160159 if err := <- done ; err != nil {
161160 if opts .push {
162- return fmt .Errorf ("push : %w" , err )
161+ return fmt .Errorf ("failed to save packaged model : %w" , err )
163162 }
164- return fmt .Errorf ("failed to load model: %w" , err )
163+ return fmt .Errorf ("failed to load packaged model: %w" , err )
165164 }
166165
167166 if opts .push {
@@ -172,6 +171,7 @@ func packageModel(cmd *cobra.Command, tag string, opts packageOptions) error {
172171 return nil
173172}
174173
174+ // modelRunnerTarget loads model to Docker Model Runner via models/load endpoint
175175type modelRunnerTarget struct {
176176 client * desktop.Client
177177 tag name.Tag
@@ -208,19 +208,19 @@ func (t *modelRunnerTarget) Write(ctx context.Context, mdl types.ModelArtifact,
208208 writeErr := <- errCh
209209
210210 if loadErr != nil {
211- return loadErr
211+ return fmt . Errorf ( "loading model archive: %w" , loadErr )
212212 }
213213 if writeErr != nil {
214- return writeErr
214+ return fmt . Errorf ( "writing model archive: %w" , writeErr )
215215 }
216216 id , err := mdl .ID ()
217217 if err != nil {
218218 return fmt .Errorf ("get model ID: %w" , err )
219219 }
220220 if t .tag .String () != "" {
221221 if err := desktopClient .Tag (id , parseRepo (t .tag ), t .tag .TagStr ()); err != nil {
222- return fmt .Errorf ("failed to tag model: %w" , err )
222+ return fmt .Errorf ("tag model: %w" , err )
223223 }
224224 }
225- return writeErr
225+ return nil
226226}
0 commit comments