@@ -3,6 +3,7 @@ package desktop
33import (
44 "context"
55 "fmt"
6+ "github.com/docker/model-cli/pkg/types"
67 "net/http"
78 "net/url"
89 "os"
@@ -79,47 +80,11 @@ func DockerClientForContext(cli *command.DockerCli, name string) (*clientpkg.Cli
7980 )
8081}
8182
82- // ModelRunnerEngineKind encodes the kind of Docker engine associated with the
83- // model runner context.
84- type ModelRunnerEngineKind uint8
85-
86- const (
87- // ModelRunnerEngineKindMoby represents a non-Desktop/Cloud engine on which
88- // the Model CLI command is responsible for managing a Model Runner.
89- ModelRunnerEngineKindMoby ModelRunnerEngineKind = iota
90- // ModelRunnerEngineKindMobyManual represents a non-Desktop/Cloud engine
91- // that's explicitly targeted by a MODEL_RUNNER_HOST environment variable on
92- // which the user is responsible for managing a Model Runner.
93- ModelRunnerEngineKindMobyManual
94- // ModelRunnerEngineKindDesktop represents a Docker Desktop engine. It only
95- // refers to a Docker Desktop Linux engine, i.e. not a Windows container
96- // engine in the case of Docker Desktop for Windows.
97- ModelRunnerEngineKindDesktop
98- // ModelRunnerEngineKindCloud represents a Docker Cloud engine.
99- ModelRunnerEngineKindCloud
100- )
101-
102- // String returns a human-readable engine kind description.
103- func (k ModelRunnerEngineKind ) String () string {
104- switch k {
105- case ModelRunnerEngineKindMoby :
106- return "Docker Engine"
107- case ModelRunnerEngineKindMobyManual :
108- return "Docker Engine (Manual Install)"
109- case ModelRunnerEngineKindDesktop :
110- return "Docker Desktop"
111- case ModelRunnerEngineKindCloud :
112- return "Docker Cloud"
113- default :
114- return "Unknown"
115- }
116- }
117-
11883// ModelRunnerContext encodes the operational context of a Model CLI command and
11984// provides facilities for inspecting and interacting with the Model Runner.
12085type ModelRunnerContext struct {
12186 // kind stores the associated engine kind.
122- kind ModelRunnerEngineKind
87+ kind types. ModelRunnerEngineKind
12388 // urlPrefix is the prefix URL for all requests.
12489 urlPrefix * url.URL
12590 // client is the model runner client.
@@ -134,7 +99,7 @@ func NewContextForMock(client DockerHttpClient) *ModelRunnerContext {
13499 panic ("error occurred while parsing known-good URL" )
135100 }
136101 return & ModelRunnerContext {
137- kind : ModelRunnerEngineKindDesktop ,
102+ kind : types . ModelRunnerEngineKindDesktop ,
138103 urlPrefix : urlPrefix ,
139104 client : client ,
140105 }
@@ -150,25 +115,25 @@ func DetectContext(ctx context.Context, cli *command.DockerCli) (*ModelRunnerCon
150115 treatDesktopAsMoby := os .Getenv ("_MODEL_RUNNER_TREAT_DESKTOP_AS_MOBY" ) == "1"
151116
152117 // Detect the associated engine type.
153- kind := ModelRunnerEngineKindMoby
118+ kind := types . ModelRunnerEngineKindMoby
154119 if modelRunnerHost != "" {
155- kind = ModelRunnerEngineKindMobyManual
120+ kind = types . ModelRunnerEngineKindMobyManual
156121 } else if isDesktopContext (ctx , cli ) {
157- kind = ModelRunnerEngineKindDesktop
122+ kind = types . ModelRunnerEngineKindDesktop
158123 if treatDesktopAsMoby {
159- kind = ModelRunnerEngineKindMoby
124+ kind = types . ModelRunnerEngineKindMoby
160125 }
161126 } else if isCloudContext (cli ) {
162- kind = ModelRunnerEngineKindCloud
127+ kind = types . ModelRunnerEngineKindCloud
163128 }
164129
165130 // Compute the URL prefix based on the associated engine kind.
166131 var rawURLPrefix string
167- if kind == ModelRunnerEngineKindMoby {
132+ if kind == types . ModelRunnerEngineKindMoby {
168133 rawURLPrefix = "http://localhost:" + strconv .Itoa (standalone .DefaultControllerPortMoby )
169- } else if kind == ModelRunnerEngineKindCloud {
134+ } else if kind == types . ModelRunnerEngineKindCloud {
170135 rawURLPrefix = "http://localhost:" + strconv .Itoa (standalone .DefaultControllerPortCloud )
171- } else if kind == ModelRunnerEngineKindMobyManual {
136+ } else if kind == types . ModelRunnerEngineKindMobyManual {
172137 rawURLPrefix = modelRunnerHost
173138 } else { // ModelRunnerEngineKindDesktop
174139 rawURLPrefix = "http://localhost" + inference .ExperimentalEndpointsPrefix
@@ -180,7 +145,7 @@ func DetectContext(ctx context.Context, cli *command.DockerCli) (*ModelRunnerCon
180145
181146 // Construct the HTTP client.
182147 var client DockerHttpClient
183- if kind == ModelRunnerEngineKindDesktop {
148+ if kind == types . ModelRunnerEngineKindDesktop {
184149 dockerClient , err := DockerClientForContext (cli , cli .CurrentContext ())
185150 if err != nil {
186151 return nil , fmt .Errorf ("unable to create model runner client: %w" , err )
@@ -199,7 +164,7 @@ func DetectContext(ctx context.Context, cli *command.DockerCli) (*ModelRunnerCon
199164}
200165
201166// EngineKind returns the Docker engine kind associated with the model runner.
202- func (c * ModelRunnerContext ) EngineKind () ModelRunnerEngineKind {
167+ func (c * ModelRunnerContext ) EngineKind () types. ModelRunnerEngineKind {
203168 return c .kind
204169}
205170
0 commit comments