Add MLX backend config options

This commit is contained in:
2025-09-16 21:14:19 +02:00
parent 1f25e9d05b
commit 988c4aca40
4 changed files with 491 additions and 1 deletions

View File

@@ -10,9 +10,22 @@ import (
"gopkg.in/yaml.v3"
)
// BackendConfig contains backend executable configurations
type BackendConfig struct {
// Path to llama-server executable (llama.cpp backend)
LlamaExecutable string `yaml:"llama_executable"`
// Path to mlx_lm executable (MLX-LM backend)
MLXLMExecutable string `yaml:"mlx_lm_executable"`
// Optional: Default Python virtual environment path for MLX backends
MLXPythonPath string `yaml:"mlx_python_path,omitempty"`
}
// AppConfig represents the configuration for llamactl
type AppConfig struct {
Server ServerConfig `yaml:"server"`
Backends BackendConfig `yaml:"backends"`
Instances InstancesConfig `yaml:"instances"`
Auth AuthConfig `yaml:"auth"`
Version string `yaml:"-"`
@@ -112,6 +125,11 @@ func LoadConfig(configPath string) (AppConfig, error) {
AllowedOrigins: []string{"*"}, // Default to allow all origins
EnableSwagger: false,
},
Backends: BackendConfig{
LlamaExecutable: "llama-server",
MLXLMExecutable: "mlx_lm.server",
MLXPythonPath: "", // Empty means use system Python
},
Instances: InstancesConfig{
PortRange: [2]int{8000, 9000},
DataDir: getDefaultDataDirectory(),
@@ -229,8 +247,16 @@ func loadEnvVars(cfg *AppConfig) {
cfg.Instances.EnableLRUEviction = b
}
}
// Backend config
if llamaExec := os.Getenv("LLAMACTL_LLAMA_EXECUTABLE"); llamaExec != "" {
cfg.Instances.LlamaExecutable = llamaExec
cfg.Backends.LlamaExecutable = llamaExec
cfg.Instances.LlamaExecutable = llamaExec // Keep for backward compatibility
}
if mlxLMExec := os.Getenv("LLAMACTL_MLX_LM_EXECUTABLE"); mlxLMExec != "" {
cfg.Backends.MLXLMExecutable = mlxLMExec
}
if mlxPython := os.Getenv("LLAMACTL_MLX_PYTHON_PATH"); mlxPython != "" {
cfg.Backends.MLXPythonPath = mlxPython
}
if autoRestart := os.Getenv("LLAMACTL_DEFAULT_AUTO_RESTART"); autoRestart != "" {
if b, err := strconv.ParseBool(autoRestart); err == nil {