Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions core/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
AgentJobRetentionDays int `env:"LOCALAI_AGENT_JOB_RETENTION_DAYS,AGENT_JOB_RETENTION_DAYS" default:"30" help:"Number of days to keep agent job history (default: 30)" group:"api"`
OpenResponsesStoreTTL string `env:"LOCALAI_OPEN_RESPONSES_STORE_TTL,OPEN_RESPONSES_STORE_TTL" default:"0" help:"TTL for Open Responses store (e.g., 1h, 30m, 0 = no expiration)" group:"api"`

BackendImagesReleaseTag string `env:"LOCALAI_BACKEND_IMAGES_RELEASE_TAG" default:"latest" help:"Release tag for backend images (e.g., 'latest')" group:"backends"`
BackendImagesBranchTag string `env:"LOCALAI_BACKEND_IMAGES_BRANCH_TAG" default:"master" help:"Branch tag for backend images (e.g., 'master')" group:"backends"`
BackendDevSuffix string `env:"LOCALAI_BACKEND_DEV_SUFFIX" default:"development" help:"Development suffix for backend images (e.g., 'development')" group:"backends"`


Version bool
}

Expand All @@ -98,10 +103,25 @@
os.MkdirAll(r.BackendsPath, 0750)
os.MkdirAll(r.ModelsPath, 0750)

systemStateOpts := []system.SystemStateOptions{}

// Pass backend image fallback tags via system state
if r.BackendImagesReleaseTag != "" {
systemStateOpts = append(systemStateOpts, system.WithBackendImagesReleaseTag(r.BackendImagesReleaseTag))
}
if r.BackendImagesBranchTag != "" {
systemStateOpts = append(systemStateOpts, system.WithBackendImagesBranchTag(r.BackendImagesBranchTag))
}
if r.BackendDevSuffix != "" {
systemStateOpts = append(systemStateOpts, system.WithBackendDevSuffix(r.BackendDevSuffix))
}


systemState, err := system.GetSystemState(
system.WithBackendSystemPath(r.BackendsSystemPath),
system.WithModelPath(r.ModelsPath),

Check failure on line 122 in core/cli/run.go

View workflow job for this annotation

GitHub Actions / tests-apple (1.25.x)

too many arguments in call to system.GetSystemState

Check failure on line 122 in core/cli/run.go

View workflow job for this annotation

GitHub Actions / tests-linux (1.25.x)

too many arguments in call to system.GetSystemState
system.WithBackendPath(r.BackendsPath),
systemStateOpts...,
)
if err != nil {
return err
Expand Down Expand Up @@ -140,12 +160,6 @@
config.WithMachineTag(r.MachineTag),
config.WithAPIAddress(r.Address),
config.WithAgentJobRetentionDays(r.AgentJobRetentionDays),
config.WithTunnelCallback(func(tunnels []string) {
tunnelEnvVar := strings.Join(tunnels, ",")
// TODO: this is very specific to llama.cpp, we should have a more generic way to set the environment variable
os.Setenv("LLAMACPP_GRPC_SERVERS", tunnelEnvVar)
xlog.Debug("setting LLAMACPP_GRPC_SERVERS", "value", tunnelEnvVar)
}),
}

if r.DisableMetricsEndpoint {
Expand Down
36 changes: 26 additions & 10 deletions core/gallery/backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,29 @@ const (
envDevSuffix = "LOCALAI_BACKEND_DEV_SUFFIX"
)

// getFallbackTagValues returns the configurable fallback tag values from environment variables
func getFallbackTagValues() (latestTag, masterTag, devSuffix string) {
latestTag = os.Getenv(envLatestTag)
masterTag = os.Getenv(envMasterTag)
devSuffix = os.Getenv(envDevSuffix)
// getFallbackTagValues returns the configurable fallback tag values from system state, falling back to environment variables
func getFallbackTagValues(systemState *system.SystemState) (latestTag, masterTag, devSuffix string) {
// First try to get values from system state
if systemState != nil && systemState.Backend.BackendImagesReleaseTag != "" {
latestTag = systemState.Backend.BackendImagesReleaseTag
} else {
// Fallback to environment variables
latestTag = os.Getenv(envLatestTag)
}

if systemState != nil && systemState.Backend.BackendImagesBranchTag != "" {
masterTag = systemState.Backend.BackendImagesBranchTag
} else {
masterTag = os.Getenv(envMasterTag)
}

if systemState != nil && systemState.Backend.BackendDevSuffix != "" {
devSuffix = systemState.Backend.BackendDevSuffix
} else {
devSuffix = os.Getenv(envDevSuffix)
}

// Use defaults if environment variables are not set
// Use defaults if values are not set
if latestTag == "" {
latestTag = defaultLatestTag
}
Expand Down Expand Up @@ -172,8 +188,8 @@ func InstallBackendFromGallery(ctx context.Context, galleries []config.Gallery,
}

func InstallBackend(ctx context.Context, systemState *system.SystemState, modelLoader *model.ModelLoader, config *GalleryBackend, downloadStatus func(string, string, string, float64)) error {
// Get configurable fallback tag values from environment variables
latestTag, masterTag, devSuffix := getFallbackTagValues()
// Get configurable fallback tag values from system state, falling back to environment variables
latestTag, masterTag, devSuffix := getFallbackTagValues(systemState)

// Create base path if it doesn't exist
err := os.MkdirAll(systemState.Backend.BackendsPath, 0750)
Expand Down Expand Up @@ -225,7 +241,7 @@ func InstallBackend(ctx context.Context, systemState *system.SystemState, modelL
}

// Try fallback: replace latestTag + "-" with masterTag + "-" in the URI
fallbackURI := strings.Replace(string(config.URI), latestTag + "-", masterTag + "-", 1)
fallbackURI := strings.Replace(string(config.URI), latestTag+"-", masterTag+"-", 1)
if fallbackURI != string(config.URI) {
xlog.Debug("Trying fallback URI", "original", config.URI, "fallback", fallbackURI)
if err := downloader.URI(fallbackURI).DownloadFileWithContext(ctx, backendPath, "", 1, 1, downloadStatus); err == nil {
Expand All @@ -234,7 +250,7 @@ func InstallBackend(ctx context.Context, systemState *system.SystemState, modelL
} else {
// Try another fallback: add "-" + devSuffix suffix to the backend name
// For example: master-gpu-nvidia-cuda-13-ace-step -> master-gpu-nvidia-cuda-13-ace-step-development
if !strings.Contains(fallbackURI, "-" + devSuffix) {
if !strings.Contains(fallbackURI, "-"+devSuffix) {
// Extract backend name from URI and add -development
parts := strings.Split(fallbackURI, "-")
if len(parts) >= 2 {
Expand Down
25 changes: 23 additions & 2 deletions pkg/system/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
)

type Backend struct {
BackendsPath string
BackendsSystemPath string
BackendsPath string
BackendsSystemPath string
BackendImagesReleaseTag string // Release tag for backend images
BackendImagesBranchTag string // Branch tag for backend images
BackendDevSuffix string // Development suffix for backend images
}

type Model struct {
Expand Down Expand Up @@ -43,6 +46,24 @@ func WithModelPath(path string) SystemStateOptions {
}
}

func WithBackendImagesReleaseTag(tag string) SystemStateOptions {
return func(s *SystemState) {
s.Backend.BackendImagesReleaseTag = tag
}
}

func WithBackendImagesBranchTag(tag string) SystemStateOptions {
return func(s *SystemState) {
s.Backend.BackendImagesBranchTag = tag
}
}

func WithBackendDevSuffix(suffix string) SystemStateOptions {
return func(s *SystemState) {
s.Backend.BackendDevSuffix = suffix
}
}

func GetSystemState(opts ...SystemStateOptions) (*SystemState, error) {
state := &SystemState{}
for _, opt := range opts {
Expand Down
Loading