mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-05 04:24:39 -04:00
* fix(schema): preserve SystemOne image inputs Assisted-by: OpenAI * test(schema): follow Ginkgo conventions for decision inputs Assisted-by: OpenAI * feat(llama-cpp): dispatch native decisions through Score Upgrade the stock dependency and reconcile Score/TTS patches. Reuse native decision parsing, tasks, formatting and response-reader cleanup; preserve ordinary scoring admission and guard older dependencies. Assisted-by: OpenAI * refactor(systemone): share request and model validation Assisted-by: OpenAI:gpt-5 * fix(systemone): preserve HTTP wire-byte validation limit Keep structural validation separate from the serialized internal request bound so HTML escaping cannot reject valid HTTP payloads. Assisted-by: OpenAI:gpt-5 * feat(systemone): bound images and account native decisions Preserve public wire limits independently from router serialization. Reject unsupported NER images, map native request/capability errors, and stamp explicit usage once. Advertise decisions for stock llama-cpp. Assisted-by: OpenAI * fix(systemone): record usage on registered native route Exercise real registration and billing with a mock native backend. Reject empty native responses, malformed image URLs, trailing JSON, and wire overflow including whitespace. Assisted-by: OpenAI * feat(router): add lazy native decision transport Bind named models through internal ModelSystemOne calls with shared validation and bounded abandoned operations. Remove request and echoed-error contents from decision traces. Assisted-by: OpenAI:gpt-5 * feat(router): classify overlapping policies with native decisions Ask independent noul questions, validate probabilities and preserve first-superset routing. Wire the central factory with config-sensitive invalidation and cancellation-safe resolution. Document native framing and bounded operation limits. Assisted-by: OpenAI:gpt-5 * feat(gallery): add pinned Julia-1 native decision model Add a separate text-only llama-cpp Q8 entry with pinned Apache-2.0 source provenance and checksum. Installed using the gallery installer and exercised choice, score and noul on CPU. Assisted-by: OpenAI * test(router): verify native decisions through central factory Add an opt-in real-model Ginkgo integration covering the native Go loader and C++ transport, token usage, independent overlapping labels, and candidate selection. Document owned-server execution and the intentionally non-quality threshold. Assisted-by: Codex:gpt-5 * fix(llama-cpp): align upstream pin and preserve decision signatures Advance to bed0a856 without losing the automated upstream bump. Detect full-request fill_task support at compile time and forward every question for Nimble framing while retaining the earlier native signature. Preserve reconciled SCORE/TTS patches; add standalone compatibility coverage. Assisted-by: Codex:gpt-5 * feat(gallery): add native decision family defaults Pin Laya, Kev-4B, lev, OpenJev and Nimble artifacts. Verify Laya/Kev/lev gallery installs and CPU contracts on both native pins; clearly mark OpenJev/Nimble runtime validation pending and their noncommercial licenses. Assisted-by: OpenAI * docs(decisions): clarify integrated Nimble prerequisite Record the exact combined backend pin while retaining pending OpenJev and Nimble installation/runtime validation status. Assisted-by: Codex:gpt-5 * fix(gallery): indent native decision model sequences Match repository yamllint indentation for Laya, Kev, lev and OpenJev list fields. Parsed gallery data is unchanged; reproduce CI gallery lint failure before the whitespace-only fix and pass the same command afterward. Assisted-by: Codex:gpt-5 * docs(decisions): record OpenJev and Nimble CPU validation Record gallery installation, checksum/metadata verification and multiquestion native smoke results on bed0a856. Retain noncommercial and text-only limitations without accuracy or deterministic-output claims. Assisted-by: OpenAI * fix(ui): expose native Decisions router classifiers Select classifier models using metadata-driven capability routing, retain tuned thresholds, and validate native decision selections before saving. Cover both native backends and create/save/reopen in the real React editor. Assisted-by: Codex:gpt-5 * fix(router): exclude aliases from native decision discovery Check the originally named config before advertising native Decisions eligibility. Retain target capability inheritance for ordinary generation aliases. Exercise the actual capabilities endpoint with native models on both backends, aliases, and disabled models. Assisted-by: Codex:gpt-5 * feat(systemone): share bounded multimodal input validation Preserve text wire limits while admitting bounded PNG/JPEG decision input. Share collection and header validation across internal and public callers and keep the native runner response budget independent. Assisted-by: OpenAI:API-assistant * fix(systemone): bound admission lifetimes and validate complete images Retain shared admission leases through actual work completion, including abandoned internal operations. Decode bounded image pixels, cap public native responses before usage stamping, and preserve oversized malformed text status precedence. Assisted-by: OpenAI:API-assistant * fix(router): classify images before media fetching Preserve ordered structured probes for native decisions. Defer OpenAI media preparation until routing selects the served model, so rejected decision URLs cannot trigger downloads before shared validation. Guard direct image collection with context-aware shared admission. Keep text classifiers and embedding caches from discarding image input. Retain fail-closed classifier configuration and runtime fallback policy. Add middleware, typed-content, admission, cancellation and cache tests. Assisted-by: OpenAI:API-assistant * fix(router): bound extraction before serialization Check probe budgets before copying text or marshaling message state. Count JSON escaping so oversized internal inputs fail before allocation. Preserve typed Anthropic blocks through selected-model conversion and fallback. Keep retry coverage in Ginkgo without global test registration. Assisted-by: OpenAI * fix(router): bound supported probe serialization Arbitrary structs can bypass the probe budget through pointer marshalers, string tags, and promoted fields. Accept concrete chat schema types and plain JSON values instead of emulating arbitrary struct serialization. Budget escaped direct prompts before marshaling so raw length cannot hide serialized expansion. Preserve runtime fallback and reject oversized input before invoking the decision runner. Add Ginkgo allocation, boundary, and marshaler invocation regressions. Six-package tests, three-package race tests, and full-T2 delta lint pass. Assisted-by: OpenAI:GPT-5 golangci-lint * feat(decisions): enable bounded OpenJev images Validate native decision images before permissive media parsing and pixel allocation. Require both decision image support and a vision projector; missing or audio-only projectors cannot silently become text decisions. Pin the OpenJev Q8 projector and document its license and disk footprint. Add native safety tests, canonical limit parity, gallery and load-option checks, and a reproducible CPU direct-RPC contrasting-image smoke. Assisted-by: OpenAI:GPT-5 * fix(decisions): reject incomplete image streams stb accepts corrupt PNG Adler checksums and truncated JPEG scans. Use bounded zlib validation and strict libjpeg decoding before parsing. Keep dimension and aggregate pixel checks ahead of decoder allocations. Wire decoder dependencies into native builds and runtime packaging. Add regressions for appended EOI and embedded marker bypasses. Assisted-by: OpenAI:GPT-5 * fix(ci): gate native decision image validation Run the decoder security tests outside the stdlib-only native suite. Fetch vendor headers at the backend pin and provision decoder dependencies. Gate Go limit parity and production CMake wiring without model downloads. Assisted-by: OpenAI:GPT-5 * test(decisions): cover multimodal public API paths Exercise shared image contracts through the registered HTTP routes and external mock backend. Add opt-in cached gallery installation and real OpenJev image decisions through SystemOne and both routing APIs. Assisted-by: Codex:gpt-5 * test(decisions): assert isolation and cache bypass Observe external RPC calls and compare complete classifier history. Winner-only and cache-miss checks could hide dropped history or cache use. Give real inference its own application and model directory so shared backend mappings and loaded processes cannot affect mixed suite order. Assisted-by: OpenAI:ChatGPT * test(decisions): isolate fixture globals Disable optional global services in the isolated HTTP fixture and register cleanup before setup assertions. Verify meter provider identity survives fixture creation and destruction. Snapshot observed usage before assertions so failures cannot retain the mutex. Require a successful usage stamp before checking error responses. Assisted-by: Codex:gpt-5 golangci-lint * fix(application): honor optional telemetry controls Skip failover gauge registration when metrics are disabled. Register against the application meter rather than looking up the global provider. Allow embedders to retain the bounded routing log without billing stats. Keep the existing default when stats are disabled. The isolated HTTP fixture uses this option without losing its native router assertions. Assisted-by: Codex:gpt-5 golangci-lint --------- Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
261 lines
10 KiB
Go
261 lines
10 KiB
Go
package config
|
|
|
|
import "slices"
|
|
|
|
// This file is the single source of truth for deriving a model's user-facing
|
|
// capabilities and input/output modalities from its ModelConfig. Both the
|
|
// OpenAI-compatible /v1/models/capabilities endpoint and the Ollama-compatible
|
|
// /api/tags|/api/show surface consume these, so the vocabulary stays consistent
|
|
// across clients. Keep the detection heuristics here rather than duplicating
|
|
// them per endpoint.
|
|
|
|
// Canonical model modality values used by config declarations and discovery APIs.
|
|
const (
|
|
ModalityText = "text"
|
|
ModalityImage = "image"
|
|
ModalityAudio = "audio"
|
|
ModalityVideo = "video"
|
|
Modality3D = "3d"
|
|
)
|
|
|
|
var modalityOrder = []string{ModalityText, ModalityImage, ModalityAudio, ModalityVideo, Modality3D}
|
|
|
|
func declaredModalities(modalities []string) map[string]bool {
|
|
declared := make(map[string]bool, len(modalities))
|
|
for _, modality := range modalities {
|
|
if slices.Contains(modalityOrder, modality) {
|
|
declared[modality] = true
|
|
}
|
|
}
|
|
return declared
|
|
}
|
|
|
|
func orderedModalities(modalities map[string]bool) []string {
|
|
result := make([]string, 0, len(modalityOrder))
|
|
for _, modality := range modalityOrder {
|
|
if modalities[modality] {
|
|
result = append(result, modality)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
// VisionSupported reports whether the model can accept image inputs.
|
|
//
|
|
// We deliberately avoid HasUsecases(FLAG_VISION): GuessUsecases has no
|
|
// FLAG_VISION branch and reports true for any chat model, so it would paint
|
|
// vision onto text-only models. Instead we look for explicit signals: the
|
|
// declared input modality or KnownUsecases bit, a multimodal projector, or a
|
|
// template/backend multimodal marker.
|
|
func (c *ModelConfig) VisionSupported() bool {
|
|
if slices.Contains(c.KnownInputModalities, ModalityImage) {
|
|
return true
|
|
}
|
|
if c.KnownUsecases != nil && (*c.KnownUsecases&FLAG_VISION) == FLAG_VISION {
|
|
return true
|
|
}
|
|
// A TTS model's mmproj holds a speaker encoder and code predictor, not a
|
|
// vision tower, and llama.cpp builds an mtmd context (and so reports a media
|
|
// marker on the first chat probe) for it all the same. Neither signal proves
|
|
// image input on a declared-TTS model. Callers that genuinely are both
|
|
// declare FLAG_VISION, checked above.
|
|
declaredTTS := c.KnownUsecases != nil && (*c.KnownUsecases&FLAG_TTS) == FLAG_TTS
|
|
if c.MMProj != "" && !declaredTTS {
|
|
return true
|
|
}
|
|
if c.TemplateConfig.Multimodal != "" {
|
|
return true
|
|
}
|
|
if c.MediaMarker != "" && !declaredTTS {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ToolSupported reports whether the model is wired up for tool / function
|
|
// calling. We look for any of the explicit knobs LocalAI uses to drive
|
|
// function-call extraction (regex match, response regex, grammar triggers, XML
|
|
// format) or the auto-detected tool-format markers the llama.cpp backend
|
|
// populates during model load.
|
|
func (c *ModelConfig) ToolSupported() bool {
|
|
fc := c.FunctionsConfig
|
|
if fc.ToolFormatMarkers != nil && fc.ToolFormatMarkers.FormatType != "" {
|
|
return true
|
|
}
|
|
if len(fc.JSONRegexMatch) > 0 || len(fc.ResponseRegex) > 0 {
|
|
return true
|
|
}
|
|
if fc.XMLFormatPreset != "" || fc.XMLFormat != nil {
|
|
return true
|
|
}
|
|
if len(fc.GrammarConfig.GrammarTriggers) > 0 || fc.GrammarConfig.SchemaType != "" {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ThinkingSupported reports whether the model has reasoning / thinking enabled.
|
|
// LocalAI sets DisableReasoning=false (or leaves thinking markers configured)
|
|
// when the backend probe reports that the model supports thinking.
|
|
func (c *ModelConfig) ThinkingSupported() bool {
|
|
rc := c.ReasoningConfig
|
|
if rc.DisableReasoning != nil && !*rc.DisableReasoning {
|
|
return true
|
|
}
|
|
if len(rc.ThinkingStartTokens) > 0 || len(rc.TagPairs) > 0 {
|
|
// Explicit thinking markers imply support unless explicitly disabled.
|
|
return rc.DisableReasoning == nil || !*rc.DisableReasoning
|
|
}
|
|
return false
|
|
}
|
|
|
|
// AudioInputSupported reports whether a chat/generation model accepts audio as
|
|
// input. Model configs can declare this directly; vLLM-family configs can also
|
|
// signal it through the per-prompt audio limit. Transcription models are
|
|
// handled separately in InputModalities via FLAG_TRANSCRIPT.
|
|
func (c *ModelConfig) AudioInputSupported() bool {
|
|
return slices.Contains(c.KnownInputModalities, ModalityAudio) ||
|
|
c.LimitMMPerPrompt.LimitAudioPerPrompt > 0
|
|
}
|
|
|
|
// VideoInputSupported reports whether a chat/generation model accepts video as
|
|
// input. Model configs can declare this directly; vLLM-family configs can also
|
|
// signal it through the per-prompt video limit. This is distinct from
|
|
// FLAG_VIDEO, which denotes video generation — an output modality.
|
|
func (c *ModelConfig) VideoInputSupported() bool {
|
|
return slices.Contains(c.KnownInputModalities, ModalityVideo) ||
|
|
c.LimitMMPerPrompt.LimitVideoPerPrompt > 0
|
|
}
|
|
|
|
// Capabilities returns the ordered list of capability strings the model
|
|
// supports, using the canonical usecase vocabulary (chat, vision, transcript,
|
|
// tts, embeddings, image, video, ...) plus the modifier capabilities "tools"
|
|
// and "thinking". Vision is resolved via VisionSupported (not HasUsecases) to
|
|
// avoid the guess-heuristic false positive.
|
|
func (c *ModelConfig) Capabilities() []string {
|
|
chat := c.HasUsecases(FLAG_CHAT)
|
|
completion := c.HasUsecases(FLAG_COMPLETION)
|
|
|
|
var caps []string
|
|
add := func(cond bool, name string) {
|
|
if cond {
|
|
caps = append(caps, name)
|
|
}
|
|
}
|
|
|
|
add(c.NativeDecisionsEligible(), UsecaseDecisions)
|
|
add(c.HasUsecases(FLAG_SCORE), UsecaseScore)
|
|
add(chat, UsecaseChat)
|
|
add(completion, UsecaseCompletion)
|
|
add(c.HasUsecases(FLAG_EDIT), UsecaseEdit)
|
|
add(c.HasUsecases(FLAG_EMBEDDINGS), UsecaseEmbeddings)
|
|
add(c.HasUsecases(FLAG_RERANK), UsecaseRerank)
|
|
// Vision is only meaningful as an image-understanding modifier on a chat/
|
|
// completion model. Gating on (chat||completion) matches the Ollama surface
|
|
// and avoids a false positive when config defaults hydrate a MediaMarker on
|
|
// a non-chat model (e.g. a pure ASR/TTS backend).
|
|
add((chat || completion) && c.VisionSupported(), UsecaseVision)
|
|
// tools/thinking are modifiers on the chat/completion surface.
|
|
add((chat || completion) && c.ToolSupported(), "tools")
|
|
add((chat || completion) && c.ThinkingSupported(), "thinking")
|
|
add(c.HasUsecases(FLAG_TRANSCRIPT), UsecaseTranscript)
|
|
add(c.HasUsecases(FLAG_TTS), UsecaseTTS)
|
|
add(c.HasUsecases(FLAG_SOUND_GENERATION), UsecaseSoundGeneration)
|
|
add(c.HasUsecases(FLAG_IMAGE), UsecaseImage)
|
|
add(c.HasUsecases(FLAG_VIDEO), UsecaseVideo)
|
|
add(c.HasUsecases(FLAG_3D), Usecase3D)
|
|
add(c.HasUsecases(FLAG_3D_ANIMATION), Usecase3DAnimation)
|
|
add(c.HasUsecases(FLAG_VAD), UsecaseVAD)
|
|
add(c.HasUsecases(FLAG_DETECTION), UsecaseDetection)
|
|
add(c.HasUsecases(FLAG_DEPTH), UsecaseDepth)
|
|
add(c.HasUsecases(FLAG_AUDIO_TRANSFORM), UsecaseAudioTransform)
|
|
add(c.HasUsecases(FLAG_DIARIZATION), UsecaseDiarization)
|
|
add(c.HasUsecases(FLAG_SOUND_CLASSIFICATION), UsecaseSoundClassification)
|
|
add(c.HasUsecases(FLAG_REALTIME_AUDIO), UsecaseRealtimeAudio)
|
|
add(c.HasUsecases(FLAG_FACE_RECOGNITION), UsecaseFaceRecognition)
|
|
add(c.HasUsecases(FLAG_SPEAKER_RECOGNITION), UsecaseSpeakerRecognition)
|
|
return caps
|
|
}
|
|
|
|
// InputModalities returns the set of modalities (text, image, audio, video) the
|
|
// model accepts as input, ordered text→image→audio→video. This is what an
|
|
// attachment router consults to decide whether an image/audio/video file can be
|
|
// handed to the active model directly.
|
|
func (c *ModelConfig) InputModalities() []string {
|
|
modalities := declaredModalities(c.KnownInputModalities)
|
|
for _, operation := range c.ThreeDOperations() {
|
|
if operation.ID != "animate" {
|
|
continue
|
|
}
|
|
for _, input := range operation.Inputs {
|
|
modality := input.Type
|
|
if modality == "mesh" {
|
|
modality = Modality3D
|
|
}
|
|
modalities[modality] = true
|
|
}
|
|
}
|
|
imageGen := c.HasUsecases(FLAG_IMAGE)
|
|
videoGen := c.HasUsecases(FLAG_VIDEO)
|
|
chatish := c.HasUsecases(FLAG_CHAT) || c.HasUsecases(FLAG_COMPLETION)
|
|
|
|
textIn := chatish || c.HasUsecases(FLAG_EDIT) ||
|
|
c.HasUsecases(FLAG_EMBEDDINGS) || c.HasUsecases(FLAG_RERANK) || c.HasUsecases(FLAG_TOKENIZE) ||
|
|
c.HasUsecases(FLAG_TTS) || c.HasUsecases(FLAG_SOUND_GENERATION) || imageGen || videoGen
|
|
|
|
// Image input via a chat model requires vision (gated on chat, like the
|
|
// Ollama surface); detection/depth/face/3D models consume images directly.
|
|
imageIn := (chatish && c.VisionSupported()) || c.LimitMMPerPrompt.LimitImagePerPrompt > 0 ||
|
|
c.HasUsecases(FLAG_DETECTION) || c.HasUsecases(FLAG_DEPTH) || c.HasUsecases(FLAG_FACE_RECOGNITION) ||
|
|
c.HasUsecases(FLAG_3D)
|
|
|
|
audioIn := c.AudioInputSupported() || c.HasUsecases(FLAG_TRANSCRIPT) || c.HasUsecases(FLAG_AUDIO_TRANSFORM) ||
|
|
c.HasUsecases(FLAG_REALTIME_AUDIO) || c.HasUsecases(FLAG_VAD) || c.HasUsecases(FLAG_DIARIZATION) ||
|
|
c.HasUsecases(FLAG_SOUND_CLASSIFICATION) || c.HasUsecases(FLAG_SPEAKER_RECOGNITION)
|
|
|
|
videoIn := c.VideoInputSupported()
|
|
|
|
modalities[ModalityText] = modalities[ModalityText] || textIn
|
|
modalities[ModalityImage] = modalities[ModalityImage] || imageIn
|
|
modalities[ModalityAudio] = modalities[ModalityAudio] || audioIn
|
|
modalities[ModalityVideo] = modalities[ModalityVideo] || videoIn
|
|
return orderedModalities(modalities)
|
|
}
|
|
|
|
// OutputModalities returns the set of modalities (text, image, audio, video)
|
|
// the model produces, ordered text→image→audio→video.
|
|
func (c *ModelConfig) OutputModalities() []string {
|
|
modalities := declaredModalities(c.KnownOutputModalities)
|
|
textOut := c.HasUsecases(FLAG_CHAT) || c.HasUsecases(FLAG_COMPLETION) || c.HasUsecases(FLAG_EDIT) ||
|
|
c.HasUsecases(FLAG_TRANSCRIPT)
|
|
imageOut := c.HasUsecases(FLAG_IMAGE)
|
|
audioOut := c.HasUsecases(FLAG_TTS) || c.HasUsecases(FLAG_SOUND_GENERATION) ||
|
|
c.HasUsecases(FLAG_AUDIO_TRANSFORM) || c.HasUsecases(FLAG_REALTIME_AUDIO)
|
|
videoOut := c.HasUsecases(FLAG_VIDEO)
|
|
threeDOut := c.HasUsecases(FLAG_3D) || c.HasUsecases(FLAG_3D_ANIMATION)
|
|
|
|
modalities[ModalityText] = modalities[ModalityText] || textOut
|
|
modalities[ModalityImage] = modalities[ModalityImage] || imageOut
|
|
modalities[ModalityAudio] = modalities[ModalityAudio] || audioOut
|
|
modalities[ModalityVideo] = modalities[ModalityVideo] || videoOut
|
|
modalities[Modality3D] = modalities[Modality3D] || threeDOut
|
|
return orderedModalities(modalities)
|
|
}
|
|
|
|
// NativeDecisionsEligible excludes generation/NER heuristics and dispatchers.
|
|
func (c *ModelConfig) NativeDecisionsEligible() bool {
|
|
if c.IsDisabled() || c.HasRouter() || c.Router.Classifier != "" || c.IsAlias() || c.KnownUsecases == nil || (*c.KnownUsecases&FLAG_DECISIONS) == 0 {
|
|
return false
|
|
}
|
|
backend := GetBackendCapability(c.Backend)
|
|
if backend == nil {
|
|
return false
|
|
}
|
|
for _, method := range backend.GRPCMethods {
|
|
if method == MethodScore {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|