mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 17:14:28 +00:00
Add Docker command handling for backend options and refactor command building
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package instance
|
package instance
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"llamactl/pkg/backends"
|
"llamactl/pkg/backends"
|
||||||
@@ -9,6 +10,7 @@ import (
|
|||||||
"llamactl/pkg/backends/vllm"
|
"llamactl/pkg/backends/vllm"
|
||||||
"llamactl/pkg/config"
|
"llamactl/pkg/config"
|
||||||
"log"
|
"log"
|
||||||
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateInstanceOptions struct {
|
type CreateInstanceOptions struct {
|
||||||
@@ -201,11 +203,48 @@ func (c *CreateInstanceOptions) BuildCommandArgs() []string {
|
|||||||
}
|
}
|
||||||
case backends.BackendTypeVllm:
|
case backends.BackendTypeVllm:
|
||||||
if c.VllmServerOptions != nil {
|
if c.VllmServerOptions != nil {
|
||||||
// Prepend "serve" as first argument
|
// No longer prepend "serve" - comes from backend config
|
||||||
args := []string{"serve"}
|
return c.VllmServerOptions.BuildCommandArgs()
|
||||||
args = append(args, c.VllmServerOptions.BuildCommandArgs()...)
|
|
||||||
return args
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildCommandArgsWithDocker builds command line arguments for the backend,
|
||||||
|
// handling Docker transformations if needed
|
||||||
|
func (c *CreateInstanceOptions) BuildCommandArgsWithDocker(dockerImage string) []string {
|
||||||
|
switch c.BackendType {
|
||||||
|
case backends.BackendTypeLlamaCpp:
|
||||||
|
if c.LlamaServerOptions != nil {
|
||||||
|
return c.LlamaServerOptions.BuildCommandArgsWithDocker(dockerImage)
|
||||||
|
}
|
||||||
|
case backends.BackendTypeMlxLm:
|
||||||
|
if c.MlxServerOptions != nil {
|
||||||
|
return c.MlxServerOptions.BuildCommandArgsWithDocker(dockerImage)
|
||||||
|
}
|
||||||
|
case backends.BackendTypeVllm:
|
||||||
|
if c.VllmServerOptions != nil {
|
||||||
|
return c.VllmServerOptions.BuildCommandArgsWithDocker(dockerImage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuildCommand builds the complete command for the backend, handling Docker vs native execution
|
||||||
|
func (c *CreateInstanceOptions) BuildCommand(ctx context.Context, backendConfig *config.BackendSettings) (*exec.Cmd, error) {
|
||||||
|
switch c.BackendType {
|
||||||
|
case backends.BackendTypeLlamaCpp:
|
||||||
|
if c.LlamaServerOptions != nil {
|
||||||
|
return c.LlamaServerOptions.BuildCommand(ctx, backendConfig)
|
||||||
|
}
|
||||||
|
case backends.BackendTypeMlxLm:
|
||||||
|
if c.MlxServerOptions != nil {
|
||||||
|
return c.MlxServerOptions.BuildCommand(ctx, backendConfig)
|
||||||
|
}
|
||||||
|
case backends.BackendTypeVllm:
|
||||||
|
if c.VllmServerOptions != nil {
|
||||||
|
return c.VllmServerOptions.BuildCommand(ctx, backendConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("no backend options configured for type: %s", c.BackendType)
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (im *instanceManager) EvictLRUInstance() error {
|
|||||||
im.mu.RLock()
|
im.mu.RLock()
|
||||||
var lruInstance *instance.Process
|
var lruInstance *instance.Process
|
||||||
|
|
||||||
for name, _ := range im.runningInstances {
|
for name := range im.runningInstances {
|
||||||
inst := im.instances[name]
|
inst := im.instances[name]
|
||||||
if inst == nil {
|
if inst == nil {
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user