mirror of
https://github.com/mudler/LocalAI
synced 2026-05-24 09:28:23 +00:00
Some checks are pending
build backend container images / generate-matrix (push) Waiting to run
build backend container images / backend-jobs-multiarch (push) Blocked by required conditions
build backend container images / backend-jobs-singlearch (push) Blocked by required conditions
build backend container images / backend-merge-jobs-multiarch (push) Blocked by required conditions
build backend container images / backend-merge-jobs-singlearch (push) Blocked by required conditions
build backend container images / backend-jobs-darwin (push) Blocked by required conditions
Build test / build-test (push) Waiting to run
Build test / launcher-build-darwin (push) Waiting to run
Build test / launcher-build-linux (push) Waiting to run
GPU tests / ubuntu-latest (1.21.x) (push) Waiting to run
Explorer deployment / build-linux (push) Waiting to run
generate and publish intel docker caches / generate_caches (intel/oneapi-basekit:2025.3.2-0-devel-ubuntu24.04, linux/amd64, arc-runner-set) (push) Waiting to run
build container images / hipblas-jobs (rocm/dev-ubuntu-24.04:7.2.1, hipblas, --jobs=3 --output-sync=target, linux/amd64, ubuntu-latest, auto, -gpu-hipblas, noble, 2404) (push) Waiting to run
build container images / core-image-merge (push) Blocked by required conditions
build container images / gpu-vulkan-image-merge (push) Blocked by required conditions
build container images / gpu-nvidia-cuda-12-image-merge (push) Blocked by required conditions
build container images / gpu-nvidia-cuda-13-image-merge (push) Blocked by required conditions
build container images / gpu-intel-image-merge (push) Blocked by required conditions
build container images / gpu-hipblas-image-merge (push) Blocked by required conditions
build container images / nvidia-l4t-arm64-image-merge (push) Blocked by required conditions
build container images / nvidia-l4t-arm64-cuda-13-image-merge (push) Blocked by required conditions
build container images / core-image-build (intel/oneapi-basekit:2025.3.2-0-devel-ubuntu24.04, intel, --jobs=3 --output-sync=target, linux/amd64, ubuntu-latest, auto, -gpu-intel, noble, 2404) (push) Waiting to run
build container images / core-image-build (ubuntu:22.04, cublas, 13, 0, --jobs=4 --output-sync=target, linux/amd64, ubuntu-latest, false, auto, -gpu-nvidia-cuda-13, noble, 2404) (push) Waiting to run
build container images / core-image-build (ubuntu:24.04, , --jobs=4 --output-sync=target, amd64, linux/amd64, ubuntu-latest, false, auto, , noble, 2404) (push) Waiting to run
build container images / core-image-build (ubuntu:24.04, , --jobs=4 --output-sync=target, arm64, linux/arm64, ubuntu-24.04-arm, false, auto, , noble, 2404) (push) Waiting to run
build container images / core-image-build (ubuntu:24.04, cublas, 12, 8, --jobs=4 --output-sync=target, linux/amd64, ubuntu-latest, false, auto, -gpu-nvidia-cuda-12, noble, 2404) (push) Waiting to run
build container images / core-image-build (ubuntu:24.04, vulkan, --jobs=4 --output-sync=target, amd64, linux/amd64, ubuntu-latest, false, auto, -gpu-vulkan, noble, 2404) (push) Waiting to run
build container images / core-image-build (ubuntu:24.04, vulkan, --jobs=4 --output-sync=target, arm64, linux/arm64, ubuntu-24.04-arm, false, auto, -gpu-vulkan, noble, 2404) (push) Waiting to run
build container images / gh-runner (nvcr.io/nvidia/l4t-jetpack:r36.4.0, cublas, 12, 0, --jobs=4 --output-sync=target, linux/arm64, ubuntu-24.04-arm, true, auto, -nvidia-l4t-arm64, jammy, 2204) (push) Waiting to run
build container images / gh-runner (ubuntu:24.04, cublas, 13, 0, --jobs=4 --output-sync=target, linux/arm64, ubuntu-24.04-arm, false, auto, -nvidia-l4t-arm64-cuda-13, noble, 2404) (push) Waiting to run
lint / golangci-lint (push) Waiting to run
Security Scan / tests (push) Waiting to run
Tests extras backends / detect-changes (push) Waiting to run
Tests extras backends / tests-transformers (push) Blocked by required conditions
Tests extras backends / tests-rerankers (push) Blocked by required conditions
Tests extras backends / tests-diffusers (push) Blocked by required conditions
Tests extras backends / tests-coqui (push) Blocked by required conditions
Tests extras backends / tests-moonshine (push) Blocked by required conditions
Tests extras backends / tests-pocket-tts (push) Blocked by required conditions
Tests extras backends / tests-qwen-tts (push) Blocked by required conditions
Tests extras backends / tests-qwen-asr (push) Blocked by required conditions
Tests extras backends / tests-nemo (push) Blocked by required conditions
Tests extras backends / tests-voxcpm (push) Blocked by required conditions
Tests extras backends / tests-liquid-audio (push) Blocked by required conditions
Tests extras backends / tests-llama-cpp-quantization (push) Blocked by required conditions
Tests extras backends / tests-llama-cpp-grpc (push) Blocked by required conditions
Tests extras backends / tests-llama-cpp-grpc-transcription (push) Blocked by required conditions
Tests extras backends / tests-llama-cpp-smoke (push) Waiting to run
Tests extras backends / tests-sherpa-onnx-realtime (push) Blocked by required conditions
Tests extras backends / tests-sherpa-onnx-grpc-transcription (push) Blocked by required conditions
Tests extras backends / tests-whisper-grpc-transcription (push) Blocked by required conditions
Tests extras backends / tests-sherpa-onnx-grpc-tts (push) Blocked by required conditions
Tests extras backends / tests-ik-llama-cpp-grpc (push) Blocked by required conditions
Tests extras backends / tests-turboquant-grpc (push) Blocked by required conditions
Tests extras backends / tests-acestep-cpp (push) Blocked by required conditions
Tests extras backends / tests-vibevoice-cpp (push) Blocked by required conditions
Tests extras backends / tests-localvqe-grpc-transform (push) Blocked by required conditions
Tests extras backends / tests-qwen3-tts-cpp (push) Blocked by required conditions
Tests extras backends / tests-vibevoice-cpp-grpc-tts (push) Blocked by required conditions
Tests extras backends / tests-vibevoice-cpp-grpc-transcription (push) Blocked by required conditions
Tests extras backends / tests-voxtral (push) Blocked by required conditions
Tests extras backends / tests-kokoros (push) Blocked by required conditions
Tests extras backends / tests-insightface-grpc (push) Blocked by required conditions
Tests extras backends / tests-speaker-recognition-grpc (push) Blocked by required conditions
tests / tests-linux (1.26.x) (push) Waiting to run
tests / tests-apple (1.26.x) (push) Waiting to run
tests-aio / tests-aio (push) Waiting to run
E2E Backend Tests / tests-e2e-backend (1.25.x) (push) Waiting to run
UI E2E Tests / tests-ui-e2e (1.26.x) (push) Waiting to run
* feat(gallery): verify backend OCI images with keyless cosign Close a trust gap where a registry compromise or MITM could silently replace a backend image: the gallery YAML tells LocalAI which image to pull, but until now nothing verified the bytes came from our CI. Consumer (pkg/oci/cosignverify): - New package using sigstore-go to verify keyless-cosign signatures. - OCI 1.1 referrers API + new bundle format (no legacy :tag.sig). - Policy fields: Issuer / IssuerRegex / Identity / IdentityRegex / NotBefore. NotBefore is the revocation lever — keyless Fulcio certs are ephemeral so revocation is policy-side; advancing not_before in the gallery YAML invalidates every signature predating the cutoff. - TUF trusted root cached process-wide so N backends from one gallery do 1 fetch, not N. Plumbing: - pkg/downloader: ImageVerifier interface + WithImageVerifier option threaded through DownloadFileWithContext. Verification runs between oci.GetImage and oci.ExtractOCIImage, with digest pinning via pinnedImageRef to close the TOCTOU window. Skips the verifier's HEAD when the ref is already digest-pinned. - core/config: Gallery.Verification YAML block. - core/gallery: backendDownloadOptions builds the verifier from the policy; applied on initial URI, mirrors, and tag fallbacks. - core/gallery/upgrade: the upgrade path now routes through the same options builder. A regression Ginkgo spec pins this contract — without it, UpgradeBackend silently bypassed verification. - core/cli: --require-backend-integrity (LOCALAI_REQUIRE_BACKEND_INTEGRITY) escalates missing policy / empty SHA256 from warn to hard-fail. Producer (.github/workflows/backend_merge.yml): - id-token: write at job scope (PR-fork-safe via existing event gate). - sigstore/cosign-installer@v3 pinned to v2.4.1. - After each docker buildx imagetools create, resolve the manifest list digest and run cosign sign --recursive --new-bundle-format --registry-referrers-mode=oci-1-1 against repo@digest. --recursive signs the index and every per-arch entry, matching how the consumer resolves a tag to a platform-specific manifest before verifying. Rollout: backend/index.yaml has no `verification:` block yet, so this PR is backward-compatible — installs proceed with a warning until the gallery is populated. Strict mode is opt-in. Assisted-by: claude-code:claude-opus-4-7 [Bash] [Edit] [Read] [Write] [WebSearch] [WebFetch] Signed-off-by: Richard Palethorpe <io@richiejp.com> * refactor(gallery): plumb RequireBackendIntegrity through config instead of env The previous implementation re-exported the --require-backend-integrity CLI flag into LOCALAI_REQUIRE_BACKEND_INTEGRITY via os.Setenv, then re-read it in core/gallery via os.Getenv. This leaked process state into the gallery package and made the flag impossible to override per-call or test without touching the env. Add RequireBackendIntegrity to ApplicationConfig (with a matching WithRequireBackendIntegrity AppOption) and thread the bool through every install/upgrade path: InstallBackend, InstallBackendFromGallery, UpgradeBackend, InstallModelFromGallery, InstallExternalBackend, ApplyGalleryFromString/File, startup.InstallModels. Worker subcommands gain the same env-bound flag on WorkerFlags so distributed-worker installs honor it consistently with the worker daemon path. Add a forbidigo lint rule against os.Getenv / os.LookupEnv / os.Environ to keep the env-leak pattern from creeping back. Existing offenders (p2p, config loaders, etc.) are baseline-grandfathered by the existing new-from-merge-base: origin/master setting; targeted path exclusions cover the legitimate cases — kong CLI entry points, backend subprocesses, system capability probes, gRPC AUTH_TOKEN inheritance, test gating env vars. Assisted-by: claude-code:claude-opus-4-7 Signed-off-by: Richard Palethorpe <io@richiejp.com> --------- Signed-off-by: Richard Palethorpe <io@richiejp.com>
1275 lines
37 KiB
Go
1275 lines
37 KiB
Go
package config
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"regexp"
|
|
"time"
|
|
|
|
"github.com/mudler/LocalAI/pkg/system"
|
|
"github.com/mudler/LocalAI/pkg/xsysinfo"
|
|
"github.com/mudler/xlog"
|
|
)
|
|
|
|
type ApplicationConfig struct {
|
|
Context context.Context
|
|
ConfigFile string
|
|
SystemState *system.SystemState
|
|
ExternalBackends []string
|
|
UploadLimitMB, Threads, ContextSize int
|
|
F16 bool
|
|
Debug bool
|
|
EnableTracing bool
|
|
TracingMaxItems int
|
|
EnableBackendLogging bool
|
|
GeneratedContentDir string
|
|
|
|
UploadDir string
|
|
DataPath string // Persistent data directory for collectiondb, agents, etc.
|
|
|
|
DynamicConfigsDir string
|
|
DynamicConfigsDirPollInterval time.Duration
|
|
CORS bool
|
|
DisableCSRF bool
|
|
PreloadJSONModels string
|
|
PreloadModelsFromPath string
|
|
CORSAllowOrigins string
|
|
ApiKeys []string
|
|
P2PToken string
|
|
P2PNetworkID string
|
|
Federated bool
|
|
|
|
DisableWebUI bool
|
|
OllamaAPIRootEndpoint bool
|
|
EnforcePredownloadScans bool
|
|
OpaqueErrors bool
|
|
UseSubtleKeyComparison bool
|
|
DisableApiKeyRequirementForHttpGet bool
|
|
DisableMetrics bool
|
|
HttpGetExemptedEndpoints []*regexp.Regexp
|
|
DisableGalleryEndpoint bool
|
|
DisableMCP bool
|
|
LoadToMemory []string
|
|
|
|
Galleries []Gallery
|
|
BackendGalleries []Gallery
|
|
|
|
ExternalGRPCBackends map[string]string
|
|
|
|
AutoloadGalleries, AutoloadBackendGalleries bool
|
|
AutoUpgradeBackends bool
|
|
PreferDevelopmentBackends bool
|
|
|
|
// RequireBackendIntegrity promotes a missing SHA256 (tarball/HTTP URIs)
|
|
// or missing verification policy (OCI URIs) from a warning to a hard
|
|
// failure during backend install/upgrade. Off by default to keep
|
|
// upgrades non-breaking; operators opt in explicitly via
|
|
// --require-backend-integrity / LOCALAI_REQUIRE_BACKEND_INTEGRITY.
|
|
RequireBackendIntegrity bool
|
|
|
|
SingleBackend bool // Deprecated: use MaxActiveBackends = 1 instead
|
|
MaxActiveBackends int // Maximum number of active backends (0 = unlimited, 1 = single backend mode)
|
|
WatchDogIdle bool
|
|
WatchDogBusy bool
|
|
WatchDog bool
|
|
|
|
// Memory Reclaimer settings (works with GPU if available, otherwise RAM)
|
|
MemoryReclaimerEnabled bool // Enable memory threshold monitoring
|
|
MemoryReclaimerThreshold float64 // Threshold 0.0-1.0 (e.g., 0.95 = 95%)
|
|
|
|
// Eviction settings
|
|
ForceEvictionWhenBusy bool // Force eviction even when models have active API calls (default: false for safety)
|
|
LRUEvictionMaxRetries int // Maximum number of retries when waiting for busy models to become idle (default: 30)
|
|
LRUEvictionRetryInterval time.Duration // Interval between retries when waiting for busy models (default: 1s)
|
|
|
|
ModelsURL []string
|
|
|
|
WatchDogBusyTimeout, WatchDogIdleTimeout time.Duration
|
|
WatchDogInterval time.Duration // Interval between watchdog checks
|
|
|
|
MachineTag string
|
|
|
|
APIAddress string
|
|
|
|
LlamaCPPTunnelCallback func(tunnels []string)
|
|
MLXTunnelCallback func(tunnels []string)
|
|
|
|
DisableRuntimeSettings bool
|
|
|
|
AgentJobRetentionDays int // Default: 30 days
|
|
|
|
OpenResponsesStoreTTL time.Duration // TTL for Open Responses store (0 = no expiration)
|
|
|
|
PathWithoutAuth []string
|
|
|
|
// Agent Pool (LocalAGI integration)
|
|
AgentPool AgentPoolConfig
|
|
|
|
// Authentication & Authorization
|
|
Auth AuthConfig
|
|
|
|
// Distributed / Horizontal Scaling
|
|
Distributed DistributedConfig
|
|
|
|
// LocalAI Assistant chat modality. Hard-disable the in-process admin MCP
|
|
// server with this flag; runtime-toggleable via /api/settings.
|
|
DisableLocalAIAssistant bool
|
|
|
|
// Branding / whitelabeling — runtime-mutable via /api/settings (text) and
|
|
// /api/branding/asset/:kind (binary uploads). All values optional; empty
|
|
// strings fall back to bundled LocalAI defaults.
|
|
Branding BrandingConfig
|
|
}
|
|
|
|
// BrandingConfig holds the whitelabel/branding configuration of the instance.
|
|
// Text fields are exposed via the public GET /api/branding endpoint so the
|
|
// login page can read them before authentication. Binary asset filenames
|
|
// (logo, horizontal logo, favicon) are stored as basenames; the actual files
|
|
// live under {DynamicConfigsDir}/branding/.
|
|
type BrandingConfig struct {
|
|
InstanceName string
|
|
InstanceTagline string
|
|
LogoFile string
|
|
LogoHorizontalFile string
|
|
FaviconFile string
|
|
}
|
|
|
|
// AuthConfig holds configuration for user authentication and authorization.
|
|
type AuthConfig struct {
|
|
Enabled bool
|
|
DatabaseURL string // "postgres://..." or file path for SQLite
|
|
GitHubClientID string
|
|
GitHubClientSecret string
|
|
OIDCIssuer string // OIDC issuer URL for auto-discovery (e.g. https://accounts.google.com)
|
|
OIDCClientID string
|
|
OIDCClientSecret string
|
|
BaseURL string // for OAuth callback URLs (e.g. "http://localhost:8080")
|
|
AdminEmail string // auto-promote to admin on login
|
|
RegistrationMode string // "open", "approval" (default when empty), "invite"
|
|
DisableLocalAuth bool // disable local email/password registration and login
|
|
APIKeyHMACSecret string // HMAC secret for API key hashing; auto-generated if empty
|
|
DefaultAPIKeyExpiry string // default expiry duration for API keys (e.g. "90d"); empty = no expiry
|
|
}
|
|
|
|
// AgentPoolConfig holds configuration for the LocalAGI agent pool integration.
|
|
type AgentPoolConfig struct {
|
|
Enabled bool // default: true (disabled by LOCALAI_DISABLE_AGENTS=true)
|
|
StateDir string // default: DynamicConfigsDir (LocalAI configuration folder)
|
|
APIURL string // default: self-referencing LocalAI (http://127.0.0.1:<port>)
|
|
APIKey string // default: first API key from LocalAI config
|
|
DefaultModel string
|
|
MultimodalModel string
|
|
TranscriptionModel string
|
|
TranscriptionLanguage string
|
|
TTSModel string
|
|
Timeout string // default: "5m"
|
|
EnableSkills bool
|
|
EnableLogs bool
|
|
CustomActionsDir string
|
|
CollectionDBPath string
|
|
VectorEngine string // default: "chromem"
|
|
EmbeddingModel string // default: "granite-embedding-107m-multilingual"
|
|
MaxChunkingSize int // default: 400
|
|
ChunkOverlap int // default: 0
|
|
DatabaseURL string
|
|
AgentHubURL string // default: "https://agenthub.localai.io"
|
|
}
|
|
|
|
type AppOption func(*ApplicationConfig)
|
|
|
|
func NewApplicationConfig(o ...AppOption) *ApplicationConfig {
|
|
opt := &ApplicationConfig{
|
|
Context: context.Background(),
|
|
UploadLimitMB: 15,
|
|
Debug: true,
|
|
AgentJobRetentionDays: 30, // Default: 30 days
|
|
LRUEvictionMaxRetries: 30, // Default: 30 retries
|
|
LRUEvictionRetryInterval: 1 * time.Second, // Default: 1 second
|
|
WatchDogInterval: 500 * time.Millisecond, // Default: 500ms
|
|
TracingMaxItems: 1024,
|
|
AgentPool: AgentPoolConfig{
|
|
Enabled: true,
|
|
Timeout: "5m",
|
|
VectorEngine: "chromem",
|
|
EmbeddingModel: "granite-embedding-107m-multilingual",
|
|
MaxChunkingSize: 400,
|
|
AgentHubURL: "https://agenthub.localai.io",
|
|
},
|
|
PathWithoutAuth: []string{
|
|
"/static/",
|
|
"/generated-audio/",
|
|
"/generated-images/",
|
|
"/generated-videos/",
|
|
"/favicon.svg",
|
|
"/readyz",
|
|
"/healthz",
|
|
"/api/auth/",
|
|
"/assets/",
|
|
// Branding read endpoint + public asset server. The login
|
|
// screen renders before authentication completes, so it has
|
|
// to be able to GET /api/branding and the configured logo.
|
|
//
|
|
// IMPORTANT: PathWithoutAuth uses a prefix match (see
|
|
// auth.isExemptPath). The "/api/branding" entry therefore
|
|
// also exempts POST/DELETE /api/branding/asset/:kind from
|
|
// the *global* auth middleware. Those routes are still
|
|
// admin-gated because they are registered with the
|
|
// route-level adminMiddleware (auth.RequireAdmin) in
|
|
// core/http/routes/ui_api.go — that's what keeps anonymous
|
|
// uploads/deletes returning 401. Any new admin-only sub-route
|
|
// added under /api/branding/* MUST also carry adminMiddleware
|
|
// at the route registration site, otherwise it ships
|
|
// unauthenticated. The TestBrandingRoutes_AdminGatingHolds
|
|
// integration test in core/http/auth pins this contract.
|
|
"/api/branding",
|
|
"/branding/",
|
|
},
|
|
}
|
|
for _, oo := range o {
|
|
oo(opt)
|
|
}
|
|
return opt
|
|
}
|
|
|
|
func WithModelsURL(urls ...string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.ModelsURL = urls
|
|
}
|
|
}
|
|
|
|
func WithSystemState(state *system.SystemState) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.SystemState = state
|
|
}
|
|
}
|
|
|
|
func WithExternalBackends(backends ...string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.ExternalBackends = backends
|
|
}
|
|
}
|
|
|
|
func WithMachineTag(tag string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.MachineTag = tag
|
|
}
|
|
}
|
|
|
|
func WithCors(b bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.CORS = b
|
|
}
|
|
}
|
|
|
|
func WithP2PNetworkID(s string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.P2PNetworkID = s
|
|
}
|
|
}
|
|
|
|
func WithDisableCSRF(b bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.DisableCSRF = b
|
|
}
|
|
}
|
|
|
|
func WithP2PToken(s string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.P2PToken = s
|
|
}
|
|
}
|
|
|
|
var EnableWatchDog = func(o *ApplicationConfig) {
|
|
o.WatchDog = true
|
|
}
|
|
|
|
var EnableTracing = func(o *ApplicationConfig) {
|
|
o.EnableTracing = true
|
|
}
|
|
|
|
var EnableBackendLogging = func(o *ApplicationConfig) {
|
|
o.EnableBackendLogging = true
|
|
}
|
|
|
|
var EnableWatchDogIdleCheck = func(o *ApplicationConfig) {
|
|
o.WatchDog = true
|
|
o.WatchDogIdle = true
|
|
}
|
|
|
|
var DisableGalleryEndpoint = func(o *ApplicationConfig) {
|
|
o.DisableGalleryEndpoint = true
|
|
}
|
|
|
|
var DisableMCP = func(o *ApplicationConfig) {
|
|
o.DisableMCP = true
|
|
}
|
|
|
|
var EnableWatchDogBusyCheck = func(o *ApplicationConfig) {
|
|
o.WatchDog = true
|
|
o.WatchDogBusy = true
|
|
}
|
|
|
|
var DisableWebUI = func(o *ApplicationConfig) {
|
|
o.DisableWebUI = true
|
|
}
|
|
|
|
var EnableOllamaAPIRootEndpoint = func(o *ApplicationConfig) {
|
|
o.OllamaAPIRootEndpoint = true
|
|
}
|
|
|
|
var DisableRuntimeSettings = func(o *ApplicationConfig) {
|
|
o.DisableRuntimeSettings = true
|
|
}
|
|
|
|
func SetWatchDogBusyTimeout(t time.Duration) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.WatchDogBusyTimeout = t
|
|
}
|
|
}
|
|
|
|
func SetWatchDogIdleTimeout(t time.Duration) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.WatchDogIdleTimeout = t
|
|
}
|
|
}
|
|
|
|
func SetWatchDogInterval(t time.Duration) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.WatchDogInterval = t
|
|
}
|
|
}
|
|
|
|
// EnableMemoryReclaimer enables memory threshold monitoring.
|
|
// When enabled, the watchdog will evict backends if memory usage exceeds the threshold.
|
|
// Works with GPU VRAM if available, otherwise uses system RAM.
|
|
var EnableMemoryReclaimer = func(o *ApplicationConfig) {
|
|
o.MemoryReclaimerEnabled = true
|
|
o.WatchDog = true // Memory reclaimer requires watchdog infrastructure
|
|
}
|
|
|
|
// SetMemoryReclaimerThreshold sets the memory usage threshold (0.0-1.0).
|
|
// When memory usage exceeds this threshold, backends will be evicted using LRU strategy.
|
|
func SetMemoryReclaimerThreshold(threshold float64) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
if threshold > 0 && threshold <= 1.0 {
|
|
o.MemoryReclaimerThreshold = threshold
|
|
o.MemoryReclaimerEnabled = true
|
|
o.WatchDog = true // Memory reclaimer requires watchdog infrastructure
|
|
}
|
|
}
|
|
}
|
|
|
|
// WithMemoryReclaimer configures the memory reclaimer with the given settings
|
|
func WithMemoryReclaimer(enabled bool, threshold float64) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.MemoryReclaimerEnabled = enabled
|
|
if threshold > 0 && threshold <= 1.0 {
|
|
o.MemoryReclaimerThreshold = threshold
|
|
}
|
|
if enabled {
|
|
o.WatchDog = true // Memory reclaimer requires watchdog infrastructure
|
|
}
|
|
}
|
|
}
|
|
|
|
// EnableSingleBackend is deprecated: use SetMaxActiveBackends(1) instead.
|
|
// This is kept for backward compatibility.
|
|
var EnableSingleBackend = func(o *ApplicationConfig) {
|
|
o.SingleBackend = true
|
|
o.MaxActiveBackends = 1
|
|
}
|
|
|
|
// SetMaxActiveBackends sets the maximum number of active backends.
|
|
// 0 = unlimited, 1 = single backend mode (replaces EnableSingleBackend)
|
|
func SetMaxActiveBackends(n int) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.MaxActiveBackends = n
|
|
// For backward compatibility, also set SingleBackend if n == 1
|
|
if n == 1 {
|
|
o.SingleBackend = true
|
|
}
|
|
}
|
|
}
|
|
|
|
// GetEffectiveMaxActiveBackends returns the effective max active backends limit.
|
|
// It considers both MaxActiveBackends and the deprecated SingleBackend setting.
|
|
// If MaxActiveBackends is set (> 0), it takes precedence.
|
|
// If SingleBackend is true and MaxActiveBackends is 0, returns 1.
|
|
// Otherwise returns 0 (unlimited).
|
|
func (o *ApplicationConfig) GetEffectiveMaxActiveBackends() int {
|
|
if o.MaxActiveBackends > 0 {
|
|
return o.MaxActiveBackends
|
|
}
|
|
if o.SingleBackend {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// WithForceEvictionWhenBusy sets whether to force eviction even when models have active API calls
|
|
func WithForceEvictionWhenBusy(enabled bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.ForceEvictionWhenBusy = enabled
|
|
}
|
|
}
|
|
|
|
// WithLRUEvictionMaxRetries sets the maximum number of retries when waiting for busy models to become idle
|
|
func WithLRUEvictionMaxRetries(maxRetries int) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
if maxRetries > 0 {
|
|
o.LRUEvictionMaxRetries = maxRetries
|
|
}
|
|
}
|
|
}
|
|
|
|
// WithLRUEvictionRetryInterval sets the interval between retries when waiting for busy models
|
|
func WithLRUEvictionRetryInterval(interval time.Duration) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
if interval > 0 {
|
|
o.LRUEvictionRetryInterval = interval
|
|
}
|
|
}
|
|
}
|
|
|
|
var EnableGalleriesAutoload = func(o *ApplicationConfig) {
|
|
o.AutoloadGalleries = true
|
|
}
|
|
|
|
var EnableBackendGalleriesAutoload = func(o *ApplicationConfig) {
|
|
o.AutoloadBackendGalleries = true
|
|
}
|
|
|
|
func WithAutoUpgradeBackends(v bool) AppOption {
|
|
return func(o *ApplicationConfig) { o.AutoUpgradeBackends = v }
|
|
}
|
|
|
|
func WithRequireBackendIntegrity(v bool) AppOption {
|
|
return func(o *ApplicationConfig) { o.RequireBackendIntegrity = v }
|
|
}
|
|
|
|
func WithPreferDevelopmentBackends(v bool) AppOption {
|
|
return func(o *ApplicationConfig) { o.PreferDevelopmentBackends = v }
|
|
}
|
|
|
|
var EnableFederated = func(o *ApplicationConfig) {
|
|
o.Federated = true
|
|
}
|
|
|
|
func WithExternalBackend(name string, uri string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
if o.ExternalGRPCBackends == nil {
|
|
o.ExternalGRPCBackends = make(map[string]string)
|
|
}
|
|
o.ExternalGRPCBackends[name] = uri
|
|
}
|
|
}
|
|
|
|
func WithCorsAllowOrigins(b string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.CORSAllowOrigins = b
|
|
}
|
|
}
|
|
|
|
func WithStringGalleries(galls string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
if galls == "" {
|
|
o.Galleries = []Gallery{}
|
|
return
|
|
}
|
|
var galleries []Gallery
|
|
if err := json.Unmarshal([]byte(galls), &galleries); err != nil {
|
|
xlog.Error("failed loading galleries", "error", err)
|
|
}
|
|
o.Galleries = append(o.Galleries, galleries...)
|
|
}
|
|
}
|
|
|
|
func WithBackendGalleries(galls string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
if galls == "" {
|
|
o.BackendGalleries = []Gallery{}
|
|
return
|
|
}
|
|
var galleries []Gallery
|
|
if err := json.Unmarshal([]byte(galls), &galleries); err != nil {
|
|
xlog.Error("failed loading galleries", "error", err)
|
|
}
|
|
o.BackendGalleries = append(o.BackendGalleries, galleries...)
|
|
}
|
|
}
|
|
|
|
func WithGalleries(galleries []Gallery) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Galleries = append(o.Galleries, galleries...)
|
|
}
|
|
}
|
|
|
|
func WithContext(ctx context.Context) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Context = ctx
|
|
}
|
|
}
|
|
|
|
func WithYAMLConfigPreload(configFile string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.PreloadModelsFromPath = configFile
|
|
}
|
|
}
|
|
|
|
func WithJSONStringPreload(configFile string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.PreloadJSONModels = configFile
|
|
}
|
|
}
|
|
func WithConfigFile(configFile string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.ConfigFile = configFile
|
|
}
|
|
}
|
|
|
|
func WithUploadLimitMB(limit int) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.UploadLimitMB = limit
|
|
}
|
|
}
|
|
|
|
func WithThreads(threads int) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
if threads == 0 { // 0 is not allowed
|
|
threads = xsysinfo.CPUPhysicalCores()
|
|
}
|
|
o.Threads = threads
|
|
}
|
|
}
|
|
|
|
func WithContextSize(ctxSize int) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.ContextSize = ctxSize
|
|
}
|
|
}
|
|
|
|
func WithLlamaCPPTunnelCallback(callback func(tunnels []string)) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.LlamaCPPTunnelCallback = callback
|
|
}
|
|
}
|
|
|
|
func WithMLXTunnelCallback(callback func(tunnels []string)) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.MLXTunnelCallback = callback
|
|
}
|
|
}
|
|
|
|
func WithF16(f16 bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.F16 = f16
|
|
}
|
|
}
|
|
|
|
func WithDebug(debug bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Debug = debug
|
|
}
|
|
}
|
|
|
|
func WithTracingMaxItems(items int) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.TracingMaxItems = items
|
|
}
|
|
}
|
|
|
|
func WithGeneratedContentDir(generatedContentDir string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.GeneratedContentDir = generatedContentDir
|
|
}
|
|
}
|
|
|
|
func WithUploadDir(uploadDir string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.UploadDir = uploadDir
|
|
}
|
|
}
|
|
|
|
func WithDataPath(dataPath string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.DataPath = dataPath
|
|
}
|
|
}
|
|
|
|
func WithDynamicConfigDir(dynamicConfigsDir string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.DynamicConfigsDir = dynamicConfigsDir
|
|
}
|
|
}
|
|
|
|
func WithDynamicConfigDirPollInterval(interval time.Duration) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.DynamicConfigsDirPollInterval = interval
|
|
}
|
|
}
|
|
|
|
func WithApiKeys(apiKeys []string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.ApiKeys = apiKeys
|
|
}
|
|
}
|
|
|
|
func WithAgentJobRetentionDays(days int) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentJobRetentionDays = days
|
|
}
|
|
}
|
|
|
|
func WithOpenResponsesStoreTTL(ttl time.Duration) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.OpenResponsesStoreTTL = ttl
|
|
}
|
|
}
|
|
|
|
func WithEnforcedPredownloadScans(enforced bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.EnforcePredownloadScans = enforced
|
|
}
|
|
}
|
|
|
|
func WithOpaqueErrors(opaque bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.OpaqueErrors = opaque
|
|
}
|
|
}
|
|
|
|
func WithLoadToMemory(models []string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.LoadToMemory = models
|
|
}
|
|
}
|
|
|
|
func WithSubtleKeyComparison(subtle bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.UseSubtleKeyComparison = subtle
|
|
}
|
|
}
|
|
|
|
func WithDisableApiKeyRequirementForHttpGet(required bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.DisableApiKeyRequirementForHttpGet = required
|
|
}
|
|
}
|
|
|
|
func WithAPIAddress(address string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.APIAddress = address
|
|
}
|
|
}
|
|
|
|
var DisableMetricsEndpoint AppOption = func(o *ApplicationConfig) {
|
|
o.DisableMetrics = true
|
|
}
|
|
|
|
func WithHttpGetExemptedEndpoints(endpoints []string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.HttpGetExemptedEndpoints = []*regexp.Regexp{}
|
|
for _, epr := range endpoints {
|
|
r, err := regexp.Compile(epr)
|
|
if err == nil && r != nil {
|
|
o.HttpGetExemptedEndpoints = append(o.HttpGetExemptedEndpoints, r)
|
|
} else {
|
|
xlog.Warn("Error while compiling HTTP Get Exemption regex, skipping this entry.", "error", err, "regex", epr)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Agent Pool options
|
|
|
|
var DisableAgentPool = func(o *ApplicationConfig) {
|
|
o.AgentPool.Enabled = false
|
|
}
|
|
|
|
func WithAgentPoolAPIURL(url string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.APIURL = url
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolAPIKey(key string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.APIKey = key
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolDefaultModel(model string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.DefaultModel = model
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolMultimodalModel(model string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.MultimodalModel = model
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolTranscriptionModel(model string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.TranscriptionModel = model
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolTranscriptionLanguage(lang string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.TranscriptionLanguage = lang
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolTTSModel(model string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.TTSModel = model
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolStateDir(dir string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.StateDir = dir
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolTimeout(timeout string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.Timeout = timeout
|
|
}
|
|
}
|
|
|
|
var EnableAgentPoolSkills = func(o *ApplicationConfig) {
|
|
o.AgentPool.EnableSkills = true
|
|
}
|
|
|
|
func WithAgentPoolVectorEngine(engine string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.VectorEngine = engine
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolEmbeddingModel(model string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.EmbeddingModel = model
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolCustomActionsDir(dir string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.CustomActionsDir = dir
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolDatabaseURL(url string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.DatabaseURL = url
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolMaxChunkingSize(size int) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.MaxChunkingSize = size
|
|
}
|
|
}
|
|
|
|
func WithAgentPoolChunkOverlap(overlap int) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.ChunkOverlap = overlap
|
|
}
|
|
}
|
|
|
|
var EnableAgentPoolLogs = func(o *ApplicationConfig) {
|
|
o.AgentPool.EnableLogs = true
|
|
}
|
|
|
|
func WithAgentPoolCollectionDBPath(path string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.CollectionDBPath = path
|
|
}
|
|
}
|
|
|
|
func WithAgentHubURL(url string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.AgentPool.AgentHubURL = url
|
|
}
|
|
}
|
|
|
|
// Auth options
|
|
|
|
func WithAuthEnabled(enabled bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.Enabled = enabled
|
|
}
|
|
}
|
|
|
|
func WithAuthDatabaseURL(url string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.DatabaseURL = url
|
|
}
|
|
}
|
|
|
|
func WithAuthGitHubClientID(clientID string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.GitHubClientID = clientID
|
|
}
|
|
}
|
|
|
|
func WithAuthGitHubClientSecret(clientSecret string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.GitHubClientSecret = clientSecret
|
|
}
|
|
}
|
|
|
|
func WithAuthBaseURL(baseURL string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.BaseURL = baseURL
|
|
}
|
|
}
|
|
|
|
func WithAuthAdminEmail(email string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.AdminEmail = email
|
|
}
|
|
}
|
|
|
|
func WithAuthRegistrationMode(mode string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.RegistrationMode = mode
|
|
}
|
|
}
|
|
|
|
func WithAuthDisableLocalAuth(disable bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.DisableLocalAuth = disable
|
|
}
|
|
}
|
|
|
|
func WithAuthOIDCIssuer(issuer string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.OIDCIssuer = issuer
|
|
}
|
|
}
|
|
|
|
func WithAuthOIDCClientID(clientID string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.OIDCClientID = clientID
|
|
}
|
|
}
|
|
|
|
func WithAuthOIDCClientSecret(clientSecret string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.OIDCClientSecret = clientSecret
|
|
}
|
|
}
|
|
|
|
func WithAuthAPIKeyHMACSecret(secret string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.APIKeyHMACSecret = secret
|
|
}
|
|
}
|
|
|
|
func WithAuthDefaultAPIKeyExpiry(expiry string) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.Auth.DefaultAPIKeyExpiry = expiry
|
|
}
|
|
}
|
|
|
|
// WithDisableLocalAIAssistant hard-disables the in-process admin MCP server.
|
|
// When set, the chat-handler branch for metadata.localai_assistant=true
|
|
// returns a "feature unavailable" error.
|
|
func WithDisableLocalAIAssistant(disabled bool) AppOption {
|
|
return func(o *ApplicationConfig) {
|
|
o.DisableLocalAIAssistant = disabled
|
|
}
|
|
}
|
|
|
|
// ToConfigLoaderOptions returns a slice of ConfigLoader Option.
|
|
// Some options defined at the application level are going to be passed as defaults for
|
|
// all the configuration for the models.
|
|
// This includes for instance the context size or the number of threads.
|
|
// If a model doesn't set configs directly to the config model file
|
|
// it will use the defaults defined here.
|
|
func (o *ApplicationConfig) ToConfigLoaderOptions() []ConfigLoaderOption {
|
|
return []ConfigLoaderOption{
|
|
LoadOptionContextSize(o.ContextSize),
|
|
LoadOptionDebug(o.Debug),
|
|
LoadOptionF16(o.F16),
|
|
LoadOptionThreads(o.Threads),
|
|
ModelPath(o.SystemState.Model.ModelsPath),
|
|
}
|
|
}
|
|
|
|
// ToRuntimeSettings converts ApplicationConfig to RuntimeSettings for API responses and JSON serialization.
|
|
// This provides a single source of truth - ApplicationConfig holds the live values,
|
|
// and this method creates a RuntimeSettings snapshot for external consumption.
|
|
func (o *ApplicationConfig) ToRuntimeSettings() RuntimeSettings {
|
|
// Create local copies for pointer fields
|
|
watchdogEnabled := o.WatchDog
|
|
watchdogIdle := o.WatchDogIdle
|
|
watchdogBusy := o.WatchDogBusy
|
|
singleBackend := o.SingleBackend
|
|
maxActiveBackends := o.MaxActiveBackends
|
|
memoryReclaimerEnabled := o.MemoryReclaimerEnabled
|
|
memoryReclaimerThreshold := o.MemoryReclaimerThreshold
|
|
forceEvictionWhenBusy := o.ForceEvictionWhenBusy
|
|
lruEvictionMaxRetries := o.LRUEvictionMaxRetries
|
|
threads := o.Threads
|
|
contextSize := o.ContextSize
|
|
f16 := o.F16
|
|
debug := o.Debug
|
|
tracingMaxItems := o.TracingMaxItems
|
|
enableTracing := o.EnableTracing
|
|
enableBackendLogging := o.EnableBackendLogging
|
|
cors := o.CORS
|
|
csrf := o.DisableCSRF
|
|
corsAllowOrigins := o.CORSAllowOrigins
|
|
p2pToken := o.P2PToken
|
|
p2pNetworkID := o.P2PNetworkID
|
|
federated := o.Federated
|
|
galleries := o.Galleries
|
|
backendGalleries := o.BackendGalleries
|
|
autoloadGalleries := o.AutoloadGalleries
|
|
autoloadBackendGalleries := o.AutoloadBackendGalleries
|
|
autoUpgradeBackends := o.AutoUpgradeBackends
|
|
preferDevelopmentBackends := o.PreferDevelopmentBackends
|
|
apiKeys := o.ApiKeys
|
|
agentJobRetentionDays := o.AgentJobRetentionDays
|
|
|
|
// Format timeouts as strings
|
|
var idleTimeout, busyTimeout, watchdogInterval string
|
|
if o.WatchDogIdleTimeout > 0 {
|
|
idleTimeout = o.WatchDogIdleTimeout.String()
|
|
} else {
|
|
idleTimeout = "15m" // default
|
|
}
|
|
if o.WatchDogBusyTimeout > 0 {
|
|
busyTimeout = o.WatchDogBusyTimeout.String()
|
|
} else {
|
|
busyTimeout = "5m" // default
|
|
}
|
|
if o.WatchDogInterval > 0 {
|
|
watchdogInterval = o.WatchDogInterval.String()
|
|
} else {
|
|
watchdogInterval = "2s" // default
|
|
}
|
|
var lruEvictionRetryInterval string
|
|
if o.LRUEvictionRetryInterval > 0 {
|
|
lruEvictionRetryInterval = o.LRUEvictionRetryInterval.String()
|
|
} else {
|
|
lruEvictionRetryInterval = "1s" // default
|
|
}
|
|
var openResponsesStoreTTL string
|
|
if o.OpenResponsesStoreTTL > 0 {
|
|
openResponsesStoreTTL = o.OpenResponsesStoreTTL.String()
|
|
} else {
|
|
openResponsesStoreTTL = "0" // default: no expiration
|
|
}
|
|
|
|
// Agent Pool settings
|
|
agentPoolEnabled := o.AgentPool.Enabled
|
|
agentPoolDefaultModel := o.AgentPool.DefaultModel
|
|
agentPoolEmbeddingModel := o.AgentPool.EmbeddingModel
|
|
agentPoolMaxChunkingSize := o.AgentPool.MaxChunkingSize
|
|
agentPoolChunkOverlap := o.AgentPool.ChunkOverlap
|
|
agentPoolEnableLogs := o.AgentPool.EnableLogs
|
|
agentPoolCollectionDBPath := o.AgentPool.CollectionDBPath
|
|
agentPoolVectorEngine := o.AgentPool.VectorEngine
|
|
agentPoolDatabaseURL := o.AgentPool.DatabaseURL
|
|
agentPoolAgentHubURL := o.AgentPool.AgentHubURL
|
|
|
|
// LocalAI Assistant settings
|
|
localAIAssistantEnabled := !o.DisableLocalAIAssistant
|
|
|
|
// Branding settings
|
|
instanceName := o.Branding.InstanceName
|
|
instanceTagline := o.Branding.InstanceTagline
|
|
logoFile := o.Branding.LogoFile
|
|
logoHorizontalFile := o.Branding.LogoHorizontalFile
|
|
faviconFile := o.Branding.FaviconFile
|
|
|
|
return RuntimeSettings{
|
|
WatchdogEnabled: &watchdogEnabled,
|
|
WatchdogIdleEnabled: &watchdogIdle,
|
|
WatchdogBusyEnabled: &watchdogBusy,
|
|
WatchdogIdleTimeout: &idleTimeout,
|
|
WatchdogBusyTimeout: &busyTimeout,
|
|
WatchdogInterval: &watchdogInterval,
|
|
SingleBackend: &singleBackend,
|
|
MaxActiveBackends: &maxActiveBackends,
|
|
MemoryReclaimerEnabled: &memoryReclaimerEnabled,
|
|
MemoryReclaimerThreshold: &memoryReclaimerThreshold,
|
|
ForceEvictionWhenBusy: &forceEvictionWhenBusy,
|
|
LRUEvictionMaxRetries: &lruEvictionMaxRetries,
|
|
LRUEvictionRetryInterval: &lruEvictionRetryInterval,
|
|
Threads: &threads,
|
|
ContextSize: &contextSize,
|
|
F16: &f16,
|
|
Debug: &debug,
|
|
TracingMaxItems: &tracingMaxItems,
|
|
EnableTracing: &enableTracing,
|
|
EnableBackendLogging: &enableBackendLogging,
|
|
CORS: &cors,
|
|
CSRF: &csrf,
|
|
CORSAllowOrigins: &corsAllowOrigins,
|
|
P2PToken: &p2pToken,
|
|
P2PNetworkID: &p2pNetworkID,
|
|
Federated: &federated,
|
|
Galleries: &galleries,
|
|
BackendGalleries: &backendGalleries,
|
|
AutoloadGalleries: &autoloadGalleries,
|
|
AutoloadBackendGalleries: &autoloadBackendGalleries,
|
|
AutoUpgradeBackends: &autoUpgradeBackends,
|
|
PreferDevelopmentBackends: &preferDevelopmentBackends,
|
|
ApiKeys: &apiKeys,
|
|
AgentJobRetentionDays: &agentJobRetentionDays,
|
|
OpenResponsesStoreTTL: &openResponsesStoreTTL,
|
|
AgentPoolEnabled: &agentPoolEnabled,
|
|
AgentPoolDefaultModel: &agentPoolDefaultModel,
|
|
AgentPoolEmbeddingModel: &agentPoolEmbeddingModel,
|
|
AgentPoolMaxChunkingSize: &agentPoolMaxChunkingSize,
|
|
AgentPoolChunkOverlap: &agentPoolChunkOverlap,
|
|
AgentPoolEnableLogs: &agentPoolEnableLogs,
|
|
AgentPoolCollectionDBPath: &agentPoolCollectionDBPath,
|
|
AgentPoolVectorEngine: &agentPoolVectorEngine,
|
|
AgentPoolDatabaseURL: &agentPoolDatabaseURL,
|
|
AgentPoolAgentHubURL: &agentPoolAgentHubURL,
|
|
LocalAIAssistantEnabled: &localAIAssistantEnabled,
|
|
InstanceName: &instanceName,
|
|
InstanceTagline: &instanceTagline,
|
|
LogoFile: &logoFile,
|
|
LogoHorizontalFile: &logoHorizontalFile,
|
|
FaviconFile: &faviconFile,
|
|
}
|
|
}
|
|
|
|
// ApplyRuntimeSettings applies RuntimeSettings to ApplicationConfig.
|
|
// Only non-nil fields in RuntimeSettings are applied.
|
|
// Returns true if watchdog-related settings changed (requiring restart).
|
|
func (o *ApplicationConfig) ApplyRuntimeSettings(settings *RuntimeSettings) (requireRestart bool) {
|
|
if settings == nil {
|
|
return false
|
|
}
|
|
|
|
if settings.WatchdogEnabled != nil {
|
|
o.WatchDog = *settings.WatchdogEnabled
|
|
requireRestart = true
|
|
}
|
|
if settings.WatchdogIdleEnabled != nil {
|
|
o.WatchDogIdle = *settings.WatchdogIdleEnabled
|
|
if o.WatchDogIdle {
|
|
o.WatchDog = true
|
|
}
|
|
requireRestart = true
|
|
}
|
|
if settings.WatchdogBusyEnabled != nil {
|
|
o.WatchDogBusy = *settings.WatchdogBusyEnabled
|
|
if o.WatchDogBusy {
|
|
o.WatchDog = true
|
|
}
|
|
requireRestart = true
|
|
}
|
|
if settings.WatchdogIdleTimeout != nil {
|
|
if dur, err := time.ParseDuration(*settings.WatchdogIdleTimeout); err == nil {
|
|
o.WatchDogIdleTimeout = dur
|
|
requireRestart = true
|
|
}
|
|
}
|
|
if settings.WatchdogBusyTimeout != nil {
|
|
if dur, err := time.ParseDuration(*settings.WatchdogBusyTimeout); err == nil {
|
|
o.WatchDogBusyTimeout = dur
|
|
requireRestart = true
|
|
}
|
|
}
|
|
if settings.WatchdogInterval != nil {
|
|
if dur, err := time.ParseDuration(*settings.WatchdogInterval); err == nil {
|
|
o.WatchDogInterval = dur
|
|
requireRestart = true
|
|
}
|
|
}
|
|
if settings.MaxActiveBackends != nil {
|
|
o.MaxActiveBackends = *settings.MaxActiveBackends
|
|
o.SingleBackend = (*settings.MaxActiveBackends == 1)
|
|
requireRestart = true
|
|
} else if settings.SingleBackend != nil {
|
|
o.SingleBackend = *settings.SingleBackend
|
|
if *settings.SingleBackend {
|
|
o.MaxActiveBackends = 1
|
|
} else {
|
|
o.MaxActiveBackends = 0
|
|
}
|
|
requireRestart = true
|
|
}
|
|
if settings.MemoryReclaimerEnabled != nil {
|
|
o.MemoryReclaimerEnabled = *settings.MemoryReclaimerEnabled
|
|
if *settings.MemoryReclaimerEnabled {
|
|
o.WatchDog = true
|
|
}
|
|
requireRestart = true
|
|
}
|
|
if settings.MemoryReclaimerThreshold != nil {
|
|
if *settings.MemoryReclaimerThreshold > 0 && *settings.MemoryReclaimerThreshold <= 1.0 {
|
|
o.MemoryReclaimerThreshold = *settings.MemoryReclaimerThreshold
|
|
requireRestart = true
|
|
}
|
|
}
|
|
if settings.ForceEvictionWhenBusy != nil {
|
|
o.ForceEvictionWhenBusy = *settings.ForceEvictionWhenBusy
|
|
// This setting doesn't require restart, can be updated dynamically
|
|
}
|
|
if settings.LRUEvictionMaxRetries != nil {
|
|
o.LRUEvictionMaxRetries = *settings.LRUEvictionMaxRetries
|
|
// This setting doesn't require restart, can be updated dynamically
|
|
}
|
|
if settings.LRUEvictionRetryInterval != nil {
|
|
if dur, err := time.ParseDuration(*settings.LRUEvictionRetryInterval); err == nil {
|
|
o.LRUEvictionRetryInterval = dur
|
|
// This setting doesn't require restart, can be updated dynamically
|
|
}
|
|
}
|
|
if settings.Threads != nil {
|
|
o.Threads = *settings.Threads
|
|
}
|
|
if settings.ContextSize != nil {
|
|
o.ContextSize = *settings.ContextSize
|
|
}
|
|
if settings.F16 != nil {
|
|
o.F16 = *settings.F16
|
|
}
|
|
if settings.Debug != nil {
|
|
o.Debug = *settings.Debug
|
|
}
|
|
if settings.EnableTracing != nil {
|
|
o.EnableTracing = *settings.EnableTracing
|
|
}
|
|
if settings.TracingMaxItems != nil {
|
|
o.TracingMaxItems = *settings.TracingMaxItems
|
|
}
|
|
if settings.EnableBackendLogging != nil {
|
|
o.EnableBackendLogging = *settings.EnableBackendLogging
|
|
}
|
|
if settings.CORS != nil {
|
|
o.CORS = *settings.CORS
|
|
}
|
|
if settings.CSRF != nil {
|
|
o.DisableCSRF = *settings.CSRF
|
|
}
|
|
if settings.CORSAllowOrigins != nil {
|
|
o.CORSAllowOrigins = *settings.CORSAllowOrigins
|
|
}
|
|
if settings.P2PToken != nil {
|
|
o.P2PToken = *settings.P2PToken
|
|
}
|
|
if settings.P2PNetworkID != nil {
|
|
o.P2PNetworkID = *settings.P2PNetworkID
|
|
}
|
|
if settings.Federated != nil {
|
|
o.Federated = *settings.Federated
|
|
}
|
|
if settings.Galleries != nil {
|
|
o.Galleries = *settings.Galleries
|
|
}
|
|
if settings.BackendGalleries != nil {
|
|
o.BackendGalleries = *settings.BackendGalleries
|
|
}
|
|
if settings.AutoloadGalleries != nil {
|
|
o.AutoloadGalleries = *settings.AutoloadGalleries
|
|
}
|
|
if settings.AutoloadBackendGalleries != nil {
|
|
o.AutoloadBackendGalleries = *settings.AutoloadBackendGalleries
|
|
}
|
|
if settings.AutoUpgradeBackends != nil {
|
|
o.AutoUpgradeBackends = *settings.AutoUpgradeBackends
|
|
}
|
|
if settings.PreferDevelopmentBackends != nil {
|
|
o.PreferDevelopmentBackends = *settings.PreferDevelopmentBackends
|
|
}
|
|
if settings.AgentJobRetentionDays != nil {
|
|
o.AgentJobRetentionDays = *settings.AgentJobRetentionDays
|
|
}
|
|
if settings.OpenResponsesStoreTTL != nil {
|
|
if *settings.OpenResponsesStoreTTL == "0" || *settings.OpenResponsesStoreTTL == "" {
|
|
o.OpenResponsesStoreTTL = 0 // No expiration
|
|
} else if dur, err := time.ParseDuration(*settings.OpenResponsesStoreTTL); err == nil {
|
|
o.OpenResponsesStoreTTL = dur
|
|
}
|
|
// This setting doesn't require restart, can be updated dynamically
|
|
}
|
|
// Agent Pool settings
|
|
if settings.AgentPoolEnabled != nil {
|
|
o.AgentPool.Enabled = *settings.AgentPoolEnabled
|
|
requireRestart = true
|
|
}
|
|
if settings.AgentPoolDefaultModel != nil {
|
|
o.AgentPool.DefaultModel = *settings.AgentPoolDefaultModel
|
|
requireRestart = true
|
|
}
|
|
if settings.AgentPoolEmbeddingModel != nil {
|
|
o.AgentPool.EmbeddingModel = *settings.AgentPoolEmbeddingModel
|
|
requireRestart = true
|
|
}
|
|
if settings.AgentPoolMaxChunkingSize != nil {
|
|
o.AgentPool.MaxChunkingSize = *settings.AgentPoolMaxChunkingSize
|
|
requireRestart = true
|
|
}
|
|
if settings.AgentPoolChunkOverlap != nil {
|
|
o.AgentPool.ChunkOverlap = *settings.AgentPoolChunkOverlap
|
|
requireRestart = true
|
|
}
|
|
if settings.AgentPoolEnableLogs != nil {
|
|
o.AgentPool.EnableLogs = *settings.AgentPoolEnableLogs
|
|
requireRestart = true
|
|
}
|
|
if settings.AgentPoolCollectionDBPath != nil {
|
|
o.AgentPool.CollectionDBPath = *settings.AgentPoolCollectionDBPath
|
|
requireRestart = true
|
|
}
|
|
if settings.AgentPoolVectorEngine != nil {
|
|
o.AgentPool.VectorEngine = *settings.AgentPoolVectorEngine
|
|
requireRestart = true
|
|
}
|
|
if settings.AgentPoolDatabaseURL != nil {
|
|
o.AgentPool.DatabaseURL = *settings.AgentPoolDatabaseURL
|
|
requireRestart = true
|
|
}
|
|
if settings.AgentPoolAgentHubURL != nil {
|
|
o.AgentPool.AgentHubURL = *settings.AgentPoolAgentHubURL
|
|
requireRestart = true
|
|
}
|
|
|
|
// LocalAI Assistant: read live at request entry by the chat handler, so
|
|
// flipping the disable flag takes effect on the next request without a
|
|
// restart.
|
|
if settings.LocalAIAssistantEnabled != nil {
|
|
o.DisableLocalAIAssistant = !*settings.LocalAIAssistantEnabled
|
|
}
|
|
|
|
// Branding: read live by the public /api/branding endpoint and asset
|
|
// server, so changes apply on the next request without a restart.
|
|
if settings.InstanceName != nil {
|
|
o.Branding.InstanceName = *settings.InstanceName
|
|
}
|
|
if settings.InstanceTagline != nil {
|
|
o.Branding.InstanceTagline = *settings.InstanceTagline
|
|
}
|
|
if settings.LogoFile != nil {
|
|
o.Branding.LogoFile = *settings.LogoFile
|
|
}
|
|
if settings.LogoHorizontalFile != nil {
|
|
o.Branding.LogoHorizontalFile = *settings.LogoHorizontalFile
|
|
}
|
|
if settings.FaviconFile != nil {
|
|
o.Branding.FaviconFile = *settings.FaviconFile
|
|
}
|
|
|
|
// Note: ApiKeys requires special handling (merging with startup keys) - handled in caller
|
|
|
|
return requireRestart
|
|
}
|
|
|
|
// func WithMetrics(meter *metrics.Metrics) AppOption {
|
|
// return func(o *StartupOptions) {
|
|
// o.Metrics = meter
|
|
// }
|
|
// }
|