Files
LocalAI/core/config/hooks_localai_proxy.go
T
Ettore Di Giacinto 8db6c15fe0 refactor: name the proxy backends with constants
Review asked for constants instead of the "cloud-proxy" and
"localai-proxy" literals. Add CloudProxyBackend and LocalAIProxyBackend next
to the other backend-name constants in pkg/model (WhisperBackend,
TransformersBackend, ...), which core/config already imports, and use them
in every production check: the proxy options builder, IsRemoteProxy,
IsCloudProxyBackendPassthrough, the PII defaults, the localai-proxy backend
hook and loader warning, and the PII middleware metadata in the routes and
the in-process MCP client.

The proxy options builder now calls IsRemoteProxy() instead of repeating
the two-backend check, so the set of proxy backends is defined once.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
2026-09-27 07:42:21 +00:00

31 lines
1.2 KiB
Go

package config
import "github.com/mudler/LocalAI/pkg/model"
func init() {
RegisterBackendHook(model.LocalAIProxyBackend, localAIProxyDefaults)
}
// localAIProxyDefaults makes chat requests reach the upstream as structured
// messages. Without the tokenizer template core renders the prompt itself
// with no template, and the proxy can only send that text to
// /v1/completions, bypassing the upstream model's chat template, tool
// handling and reasoning parsing.
//
// Only configs that declare the chat usecase get it: usecase guessing reads
// the tokenizer template as "this model chats", so setting it on a
// transcription or embedding proxy would offer that model to chat pickers
// and default-model selection. A config that brings its own templates keeps
// them: the operator chose local templating.
func localAIProxyDefaults(cfg *ModelConfig, _ string) {
t := cfg.TemplateConfig
if t.UseTokenizerTemplate || t.Chat != "" || t.ChatMessage != "" || t.Completion != "" || t.Edit != "" {
return
}
declared := GetUsecasesFromYAML(cfg.KnownUsecaseStrings)
if declared == nil || *declared&FLAG_CHAT != FLAG_CHAT {
return
}
cfg.TemplateConfig.UseTokenizerTemplate = true
}