mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-05 16:44:22 +00:00
Add environment variable support to instance options and command building
This commit is contained in:
@@ -372,13 +372,23 @@ func (i *Process) buildCommand() (*exec.Cmd, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build the environment variables
|
||||||
|
env := i.options.BuildEnvironment(backendConfig)
|
||||||
|
|
||||||
// Get the command to execute
|
// Get the command to execute
|
||||||
cmd := i.options.GetCommand(backendConfig)
|
command := i.options.GetCommand(backendConfig)
|
||||||
|
|
||||||
// Build command arguments
|
// Build command arguments
|
||||||
args := i.options.BuildCommandArgs(backendConfig)
|
args := i.options.BuildCommandArgs(backendConfig)
|
||||||
|
|
||||||
return exec.Command(cmd, args...), nil
|
// Create the exec.Cmd
|
||||||
|
cmd := exec.CommandContext(i.ctx, command, args...)
|
||||||
|
cmd.Env = []string{}
|
||||||
|
for k, v := range env {
|
||||||
|
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getBackendConfig resolves the backend configuration for the current instance
|
// getBackendConfig resolves the backend configuration for the current instance
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"llamactl/pkg/backends/vllm"
|
"llamactl/pkg/backends/vllm"
|
||||||
"llamactl/pkg/config"
|
"llamactl/pkg/config"
|
||||||
"log"
|
"log"
|
||||||
|
"maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CreateInstanceOptions struct {
|
type CreateInstanceOptions struct {
|
||||||
@@ -20,6 +21,8 @@ type CreateInstanceOptions struct {
|
|||||||
OnDemandStart *bool `json:"on_demand_start,omitempty"`
|
OnDemandStart *bool `json:"on_demand_start,omitempty"`
|
||||||
// Idle timeout
|
// Idle timeout
|
||||||
IdleTimeout *int `json:"idle_timeout,omitempty"` // minutes
|
IdleTimeout *int `json:"idle_timeout,omitempty"` // minutes
|
||||||
|
//Environment variables
|
||||||
|
Environment map[string]string `json:"environment,omitempty"`
|
||||||
|
|
||||||
BackendType backends.BackendType `json:"backend_type"`
|
BackendType backends.BackendType `json:"backend_type"`
|
||||||
BackendOptions map[string]any `json:"backend_options,omitempty"`
|
BackendOptions map[string]any `json:"backend_options,omitempty"`
|
||||||
@@ -240,3 +243,23 @@ func (c *CreateInstanceOptions) BuildCommandArgs(backendConfig *config.BackendSe
|
|||||||
|
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CreateInstanceOptions) BuildEnvironment(backendConfig *config.BackendSettings) map[string]string {
|
||||||
|
env := map[string]string{}
|
||||||
|
|
||||||
|
if backendConfig.Environment != nil {
|
||||||
|
maps.Copy(env, backendConfig.Environment)
|
||||||
|
}
|
||||||
|
|
||||||
|
if backendConfig.Docker != nil && backendConfig.Docker.Enabled && c.BackendType != backends.BackendTypeMlxLm {
|
||||||
|
if backendConfig.Docker.Environment != nil {
|
||||||
|
maps.Copy(env, backendConfig.Docker.Environment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Environment != nil {
|
||||||
|
maps.Copy(env, c.Environment)
|
||||||
|
}
|
||||||
|
|
||||||
|
return env
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user