MCPcopy
hub / github.com/mudler/LocalAI / SetDefaults

Method SetDefaults

core/config/model_config.go:1213–1294  ·  view source on GitHub ↗
(opts ...ConfigLoaderOption)

Source from the content-addressed store, hash-verified

1211}
1212
1213func (cfg *ModelConfig) SetDefaults(opts ...ConfigLoaderOption) {
1214 lo := &LoadOptions{}
1215 lo.Apply(opts...)
1216
1217 ctx := lo.ctxSize
1218 threads := lo.threads
1219 f16 := lo.f16
1220 debug := lo.debug
1221
1222 // Cloud-proxy: normalise empty Mode so downstream consumers
1223 // switch on two concrete values only. Validate accepts empty too,
1224 // but SetDefaults is the chokepoint that runs before any
1225 // inference path reads cfg.Proxy.Mode.
1226 if cfg.Proxy.Mode == "" {
1227 cfg.Proxy.Mode = ProxyModePassthrough
1228 }
1229
1230 // When templating is delegated to the backend (use_tokenizer_template),
1231 // the backend also owns tool-call grammar generation and parsing. Sending
1232 // a LocalAI-generated grammar alongside overrides the backend's native
1233 // (name-first) tool pipeline and makes it stream the tool-call JSON back as
1234 // plain content (issue #10052). The GGUF auto-import path already couples
1235 // these two flags; enforce it here so gallery and hand-written configs that
1236 // set use_tokenizer_template directly stay consistent.
1237 if cfg.TemplateConfig.UseTokenizerTemplate {
1238 cfg.FunctionsConfig.GrammarConfig.NoGrammar = true
1239 }
1240
1241 // Apply model-family-specific inference defaults before generic fallbacks.
1242 // This ensures gallery-installed and runtime-loaded models get optimal parameters.
1243 ApplyInferenceDefaults(cfg, cfg.Name, cfg.Model)
1244
1245 // Apply serving-policy defaults (device-independent): cross-request prefix
1246 // caching. Propagates to distributed nodes via the model options.
1247 ApplyServingDefaults(cfg)
1248
1249 // Generic fallback defaults (sampling params + runtime flags), applied after
1250 // the model-family / hardware / serving tiers above. Only fills unset values.
1251 ApplyGenericDefaults(cfg)
1252
1253 trueV := true
1254 falseV := false
1255
1256 if threads == 0 {
1257 // Threads can't be 0
1258 threads = 4
1259 }
1260
1261 if cfg.Threads == nil {
1262 cfg.Threads = &threads
1263 }
1264
1265 if cfg.F16 == nil {
1266 cfg.F16 = &f16
1267 }
1268
1269 if cfg.Debug == nil {
1270 cfg.Debug = &falseV

Callers 8

RunMethod · 0.95
RunMethod · 0.95
readModelConfigsFromFileFunction · 0.95
hooks_test.goFile · 0.80

Calls 7

ApplyMethod · 0.95
ApplyInferenceDefaultsFunction · 0.85
ApplyServingDefaultsFunction · 0.85
ApplyGenericDefaultsFunction · 0.85
runBackendHooksFunction · 0.85
ApplyHardwareDefaultsFunction · 0.85

Tested by

no test coverage detected