mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-03 12:57:02 -04:00
Compare commits
12 Commits
worktree-i
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfd6c09d88 | ||
|
|
eb32cd9073 | ||
|
|
80ec22945a | ||
|
|
7a3583b52c | ||
|
|
715d4ed8e5 | ||
|
|
9fcc9c0d43 | ||
|
|
3c67b5b746 | ||
|
|
bea66fd84e | ||
|
|
f7a5dfd5ae | ||
|
|
6bcaf30c14 | ||
|
|
ef15b4bfda | ||
|
|
237bce48e8 |
@@ -1,5 +1,5 @@
|
||||
|
||||
IK_LLAMA_VERSION?=068b173649f2fd8dc96b35ada5a0b76d8985105d
|
||||
IK_LLAMA_VERSION?=87fc8701ff4da81a7d2a91ec0695f95eb3066a47
|
||||
LLAMA_REPO?=https://github.com/ikawrakow/ik_llama.cpp
|
||||
|
||||
CMAKE_ARGS?=
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
LLAMA_VERSION?=4fc4ec5541b243957ae5099edb67372f8f3b550e
|
||||
LLAMA_VERSION?=fdb1db877c526ec90f668eca1b858da5dba85560
|
||||
LLAMA_REPO?=https://github.com/ggerganov/llama.cpp
|
||||
|
||||
CMAKE_ARGS?=
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# Local development: point at a working checkout instead of cloning, e.g.
|
||||
# make PRIVACY_FILTER_SRC=$HOME/c/privacy-filter.cpp grpc-server
|
||||
|
||||
PRIVACY_FILTER_VERSION?=595f59630c69d361b5196f2aba2c71c873d0c13c
|
||||
PRIVACY_FILTER_VERSION?=735a6c28607ee82afc3a670383f41b55266a3b9a
|
||||
PRIVACY_FILTER_REPO?=https://github.com/localai-org/privacy-filter.cpp
|
||||
PRIVACY_FILTER_SRC?=
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ JOBS?=$(shell nproc --ignore=1)
|
||||
|
||||
# CrispASR version (release tag)
|
||||
CRISPASR_REPO?=https://github.com/CrispStrobe/CrispASR
|
||||
CRISPASR_VERSION?=fcbc8718e654995e3bd2d0c98bcb8e55e297d23c
|
||||
CRISPASR_VERSION?=9a26976a8c8cf5af0afcdd04463cf8ba91e96a54
|
||||
SO_TARGET?=libgocrispasr.so
|
||||
|
||||
CMAKE_ARGS+=-DBUILD_SHARED_LIBS=OFF
|
||||
|
||||
@@ -8,7 +8,7 @@ JOBS?=$(shell nproc --ignore=1)
|
||||
|
||||
# stablediffusion.cpp (ggml)
|
||||
STABLEDIFFUSION_GGML_REPO?=https://github.com/leejet/stable-diffusion.cpp
|
||||
STABLEDIFFUSION_GGML_VERSION?=3590aa8d626e671a1b1dc84506ea2932a243a480
|
||||
STABLEDIFFUSION_GGML_VERSION?=2574f5936571645f784b77623e1f09bad97d948a
|
||||
|
||||
CMAKE_ARGS+=-DGGML_MAX_NAME=128
|
||||
|
||||
|
||||
@@ -20,7 +20,15 @@ def split_reasoning(text, think_start, think_end):
|
||||
Returns ``(reasoning_content, remaining_text)``. When ``think_start`` is
|
||||
empty or not found, returns ``("", text)`` unchanged.
|
||||
"""
|
||||
if not think_start or not text or think_start not in text:
|
||||
if not think_start or not text:
|
||||
return "", text
|
||||
if think_start not in text:
|
||||
# Models like Qwen3.5 open assistant turns already INSIDE thinking, so
|
||||
# the generated text carries only the closing tag. Everything before it
|
||||
# is reasoning that would otherwise leak into the content.
|
||||
if think_end and think_end in text:
|
||||
head, _, tail = text.partition(think_end)
|
||||
return head.strip(), tail.strip()
|
||||
return "", text
|
||||
pattern = re.compile(
|
||||
re.escape(think_start) + r"(.*?)" + re.escape(think_end or ""),
|
||||
|
||||
75
backend/python/common/mlx_utils_test.py
Normal file
75
backend/python/common/mlx_utils_test.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""Unit tests for the mlx/mlx-vlm shared helpers (mlx_utils.py).
|
||||
|
||||
Run standalone (Python standard library only, no backend venv needed):
|
||||
python3 -m unittest mlx_utils_test
|
||||
|
||||
These mirror the server-less helper tests in backend/python/mlx/test.py
|
||||
(TestSharedHelpers), but live here so they run on any platform: the mlx
|
||||
test module imports grpc/backend_pb2 at import time and needs the MLX venv,
|
||||
whereas mlx_utils only needs the standard library.
|
||||
"""
|
||||
|
||||
import types
|
||||
import unittest
|
||||
|
||||
from mlx_utils import parse_tool_calls, split_reasoning
|
||||
|
||||
|
||||
class TestSplitReasoning(unittest.TestCase):
|
||||
def test_both_tags(self):
|
||||
r, c = split_reasoning(
|
||||
"<think>step 1\nstep 2</think>The answer is 42.", "<think>", "</think>"
|
||||
)
|
||||
self.assertEqual(r, "step 1\nstep 2")
|
||||
self.assertEqual(c, "The answer is 42.")
|
||||
|
||||
def test_implicit_opener_only_closing_tag(self):
|
||||
# Qwen3.5 opens the assistant turn already inside thinking, so the
|
||||
# output carries only the closing tag; everything before it is reasoning.
|
||||
r, c = split_reasoning(
|
||||
"The user is asking about the weather.\n</think>\n\nThe weather in Rome is sunny.",
|
||||
"<think>",
|
||||
"</think>",
|
||||
)
|
||||
self.assertEqual(r, "The user is asking about the weather.")
|
||||
self.assertEqual(c, "The weather in Rome is sunny.")
|
||||
|
||||
def test_no_tags_at_all(self):
|
||||
r, c = split_reasoning("just text", "<think>", "</think>")
|
||||
self.assertEqual(r, "")
|
||||
self.assertEqual(c, "just text")
|
||||
|
||||
def test_empty_think_end_and_no_opener_match(self):
|
||||
# No think_end to anchor on, and the opener is absent → return unchanged.
|
||||
r, c = split_reasoning("no opener here", "<think>", "")
|
||||
self.assertEqual(r, "")
|
||||
self.assertEqual(c, "no opener here")
|
||||
|
||||
def test_empty_text(self):
|
||||
r, c = split_reasoning("", "<think>", "</think>")
|
||||
self.assertEqual(r, "")
|
||||
self.assertEqual(c, "")
|
||||
|
||||
|
||||
class TestParseToolCalls(unittest.TestCase):
|
||||
def test_with_shim(self):
|
||||
tm = types.SimpleNamespace(
|
||||
tool_call_start="<tool_call>",
|
||||
tool_call_end="</tool_call>",
|
||||
parse_tool_call=lambda body, tools: {
|
||||
"name": "get_weather",
|
||||
"arguments": {"location": body.strip()},
|
||||
},
|
||||
)
|
||||
calls, remaining = parse_tool_calls(
|
||||
"Sure: <tool_call>Paris</tool_call>", tm, tools=None
|
||||
)
|
||||
self.assertEqual(len(calls), 1)
|
||||
self.assertEqual(calls[0]["name"], "get_weather")
|
||||
self.assertEqual(calls[0]["arguments"], '{"location": "Paris"}')
|
||||
self.assertEqual(calls[0]["index"], 0)
|
||||
self.assertNotIn("<tool_call>", remaining)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -58,7 +58,18 @@ def messages_to_dicts(proto_messages):
|
||||
d["reasoning_content"] = msg.reasoning_content
|
||||
if msg.tool_calls:
|
||||
try:
|
||||
d["tool_calls"] = json.loads(msg.tool_calls)
|
||||
tool_calls = json.loads(msg.tool_calls)
|
||||
# Chat templates (e.g. Qwen) iterate function.arguments as a
|
||||
# mapping, but the OpenAI wire format carries it as a JSON
|
||||
# string — decode it back so the template's .items() works.
|
||||
for tc in tool_calls:
|
||||
fn = tc.get("function") if isinstance(tc, dict) else None
|
||||
if isinstance(fn, dict) and isinstance(fn.get("arguments"), str):
|
||||
try:
|
||||
fn["arguments"] = json.loads(fn["arguments"])
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
d["tool_calls"] = tool_calls
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
result.append(d)
|
||||
|
||||
122
backend/python/common/python_utils_test.py
Normal file
122
backend/python/common/python_utils_test.py
Normal file
@@ -0,0 +1,122 @@
|
||||
"""Unit tests for the shared python backend helpers (python_utils.py).
|
||||
|
||||
Run standalone (Python standard library only, no backend venv needed):
|
||||
python3 -m unittest python_utils_test
|
||||
|
||||
These mirror the server-less helper tests in backend/python/mlx/test.py
|
||||
(TestSharedHelpers), but live here so they run on any platform: the mlx
|
||||
test module imports grpc/backend_pb2 at import time and needs the MLX venv,
|
||||
whereas python_utils has no third-party dependency. Proto Message objects
|
||||
are faked with types.SimpleNamespace (real proto fields default to "").
|
||||
"""
|
||||
|
||||
import json
|
||||
import types
|
||||
import unittest
|
||||
|
||||
from python_utils import messages_to_dicts, parse_options
|
||||
|
||||
|
||||
def _msg(**fields):
|
||||
"""Fake a proto Message: every unset field is the empty string, as protobuf."""
|
||||
defaults = {
|
||||
"role": "",
|
||||
"content": "",
|
||||
"name": "",
|
||||
"tool_call_id": "",
|
||||
"reasoning_content": "",
|
||||
"tool_calls": "",
|
||||
}
|
||||
defaults.update(fields)
|
||||
return types.SimpleNamespace(**defaults)
|
||||
|
||||
|
||||
class TestParseOptions(unittest.TestCase):
|
||||
def test_type_inference(self):
|
||||
opts = parse_options(
|
||||
["temperature:0.7", "max_tokens:128", "trust:true", "name:hello", "no_colon_skipped"]
|
||||
)
|
||||
self.assertEqual(opts["temperature"], 0.7)
|
||||
self.assertEqual(opts["max_tokens"], 128)
|
||||
self.assertIs(opts["trust"], True)
|
||||
self.assertEqual(opts["name"], "hello")
|
||||
self.assertNotIn("no_colon_skipped", opts)
|
||||
|
||||
|
||||
class TestMessagesToDicts(unittest.TestCase):
|
||||
def test_basic_fields(self):
|
||||
out = messages_to_dicts(
|
||||
[
|
||||
_msg(role="user", content="hi"),
|
||||
_msg(role="tool", content="42", tool_call_id="call_1", name="f"),
|
||||
]
|
||||
)
|
||||
self.assertEqual(out[0], {"role": "user", "content": "hi"})
|
||||
self.assertEqual(out[1]["tool_call_id"], "call_1")
|
||||
self.assertEqual(out[1]["name"], "f")
|
||||
|
||||
def test_tool_call_arguments_string_decoded_to_mapping(self):
|
||||
# OpenAI wire format ships function.arguments as a JSON *string*; chat
|
||||
# templates iterate it as a mapping, so it must come back as a dict.
|
||||
out = messages_to_dicts(
|
||||
[
|
||||
_msg(
|
||||
role="assistant",
|
||||
tool_calls=json.dumps(
|
||||
[
|
||||
{
|
||||
"id": "call_1",
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "get_weather",
|
||||
"arguments": '{"location": "Rome"}',
|
||||
},
|
||||
}
|
||||
]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
args = out[0]["tool_calls"][0]["function"]["arguments"]
|
||||
self.assertEqual(args, {"location": "Rome"})
|
||||
self.assertEqual(dict(args.items()), {"location": "Rome"})
|
||||
|
||||
def test_tool_call_arguments_already_mapping_is_idempotent(self):
|
||||
out = messages_to_dicts(
|
||||
[
|
||||
_msg(
|
||||
role="assistant",
|
||||
tool_calls=json.dumps(
|
||||
[{"function": {"name": "f", "arguments": {"a": 1}}}]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
self.assertEqual(out[0]["tool_calls"][0]["function"]["arguments"], {"a": 1})
|
||||
|
||||
def test_tool_call_arguments_invalid_json_left_as_string(self):
|
||||
out = messages_to_dicts(
|
||||
[
|
||||
_msg(
|
||||
role="assistant",
|
||||
tool_calls=json.dumps(
|
||||
[{"function": {"name": "f", "arguments": "not-json"}}]
|
||||
),
|
||||
)
|
||||
]
|
||||
)
|
||||
self.assertEqual(out[0]["tool_calls"][0]["function"]["arguments"], "not-json")
|
||||
|
||||
def test_tool_call_without_function_key(self):
|
||||
out = messages_to_dicts(
|
||||
[_msg(role="assistant", tool_calls=json.dumps([{"id": "call_1"}]))]
|
||||
)
|
||||
self.assertEqual(out[0]["tool_calls"], [{"id": "call_1"}])
|
||||
|
||||
def test_tool_calls_invalid_json_dropped(self):
|
||||
out = messages_to_dicts([_msg(role="assistant", tool_calls="{not json")])
|
||||
self.assertNotIn("tool_calls", out[0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -35,6 +35,21 @@ if [ "x${BUILD_PROFILE}" == "xcpu" ]; then
|
||||
EXTRA_PIP_INSTALL_FLAGS+=" --index-strategy=unsafe-best-match"
|
||||
fi
|
||||
|
||||
# AMD ROCm: vLLM ships prebuilt ROCm wheels, but on a DEDICATED index
|
||||
# (https://wheels.vllm.ai/rocm/), NOT PyPI, and ONLY for CPython 3.12. On any
|
||||
# other Python the installer silently falls back to the CUDA-only PyPI wheel,
|
||||
# which is unusable on an AMD GPU (import fails, so the backend never finds the
|
||||
# vllm module). Force Python 3.12 before the venv is created (matches the
|
||||
# intel/l4t13 cp312 bump); the hipblas branch below pulls vllm from the ROCm
|
||||
# wheel index. unsafe-best-match lets uv consult that index and PyPI together.
|
||||
# https://docs.vllm.ai/en/latest/getting_started/installation/gpu.html?device=rocm
|
||||
if [ "x${BUILD_TYPE}" == "xhipblas" ]; then
|
||||
PYTHON_VERSION="3.12"
|
||||
PYTHON_PATCH="12"
|
||||
PY_STANDALONE_TAG="20251120"
|
||||
EXTRA_PIP_INSTALL_FLAGS+=" --index-strategy=unsafe-best-match"
|
||||
fi
|
||||
|
||||
# cublas13 pulls the vLLM wheel from a per-tag cu130 index (PyPI's vllm wheel
|
||||
# is built against CUDA 12 and won't load on cu130). uv's default per-package
|
||||
# first-match strategy would still pick the PyPI wheel, so allow it to consult
|
||||
@@ -104,7 +119,7 @@ if [ "$(uname -s)" = "Darwin" ]; then
|
||||
# can rewrite it. Darwin therefore follows vllm-metal and can lag the Linux
|
||||
# vllm pin (requirements-cublas13-after.txt, bumped independently against
|
||||
# vllm/vllm) until vllm-metal supports a newer vLLM.
|
||||
VLLM_METAL_VERSION="v0.3.0.dev20260701132215"
|
||||
VLLM_METAL_VERSION="v0.3.0.dev20260701212152"
|
||||
|
||||
# The coupled vLLM source version is whatever this vllm-metal release builds
|
||||
# against -- it declares it in its own installer as `vllm_v=`. Derive it from
|
||||
@@ -194,6 +209,22 @@ elif [ "x${BUILD_TYPE}" == "xintel" ]; then
|
||||
export CMAKE_PREFIX_PATH="$(python -c 'import site; print(site.getsitepackages()[0])'):${CMAKE_PREFIX_PATH:-}"
|
||||
VLLM_TARGET_DEVICE=xpu uv pip install ${EXTRA_PIP_INSTALL_FLAGS:-} --no-deps .
|
||||
popd
|
||||
# AMD ROCm: install vllm from its dedicated ROCm wheel index instead of the
|
||||
# CUDA-only PyPI wheel. installRequirements brings the base ROCm
|
||||
# torch/transformers (requirements-hipblas.txt), then we pull vllm (plus the
|
||||
# matching ROCm torch, via --upgrade) from wheels.vllm.ai/rocm. This is the
|
||||
# method upstream prescribes for AMD; the Python-3.12 pin is set above.
|
||||
# There is intentionally no requirements-hipblas-after.txt: a bare `vllm`
|
||||
# there would resolve to the CUDA wheel, and installRequirements never loads
|
||||
# a ${BUILD_TYPE}-after file for hipblas anyway (BUILD_TYPE == BUILD_PROFILE).
|
||||
# https://docs.vllm.ai/en/latest/getting_started/installation/gpu.html?device=rocm
|
||||
elif [ "x${BUILD_TYPE}" == "xhipblas" ]; then
|
||||
installRequirements
|
||||
|
||||
# --upgrade reconciles the base ROCm torch to whatever the vllm ROCm wheel
|
||||
# pins; --extra-index-url adds the ROCm wheel repository on top of PyPI.
|
||||
uv pip install ${EXTRA_PIP_INSTALL_FLAGS:-} \
|
||||
--extra-index-url https://wheels.vllm.ai/rocm/ --upgrade vllm
|
||||
# FROM_SOURCE=true on a CPU build skips the prebuilt vllm wheel in
|
||||
# requirements-cpu-after.txt and compiles vllm locally against the host's
|
||||
# actual CPU. Not used by default because it takes ~30-40 minutes, but
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
vllm
|
||||
@@ -473,20 +473,13 @@ func New(opts ...config.AppOption) (*Application, error) {
|
||||
|
||||
if options.LoadToMemory != nil && !options.SingleBackend {
|
||||
for _, m := range options.LoadToMemory {
|
||||
cfg, err := application.ModelConfigLoader().LoadModelConfigFileByNameDefaultOptions(m, options)
|
||||
if err != nil {
|
||||
xlog.Debug("Auto loading model into memory from file", "model", m)
|
||||
// Same path as POST /backend/load: a realtime pipeline model expands
|
||||
// to its sub-models, and load failures are recorded as model_load
|
||||
// traces.
|
||||
if _, err := backend.PreloadModelByName(options.Context, application.ModelConfigLoader(), application.ModelLoader(), options, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
xlog.Debug("Auto loading model into memory from file", "model", m, "file", cfg.Model)
|
||||
|
||||
o := backend.ModelOptions(*cfg, options)
|
||||
|
||||
var backendErr error
|
||||
_, backendErr = application.ModelLoader().Load(o...)
|
||||
if backendErr != nil {
|
||||
return nil, backendErr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,22 @@ func ModelLoadTraceObserver(appConfig *config.ApplicationConfig) func(model.Back
|
||||
}
|
||||
}
|
||||
|
||||
// PreloadModel warms a model into memory without running any inference, so the
|
||||
// first real request doesn't pay the backend's cold-start load cost. It uses
|
||||
// the same ModelOptions + ml.Load path the modality functions use, so a
|
||||
// subsequent inference call hits the loader cache instead of reloading. Load
|
||||
// failures are recorded and returned; callers that warm models opportunistically
|
||||
// (e.g. realtime session warm-up) typically log and continue, since the lazy
|
||||
// path will retry on first use.
|
||||
func PreloadModel(ctx context.Context, ml *model.ModelLoader, modelConfig config.ModelConfig, appConfig *config.ApplicationConfig) error {
|
||||
opts := ModelOptions(modelConfig, appConfig, model.WithContext(ctx))
|
||||
if _, err := ml.Load(opts...); err != nil {
|
||||
recordModelLoadFailure(appConfig, modelConfig.Name, modelConfig.Backend, err, nil)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// recordModelLoadFailure records a backend trace when model loading fails.
|
||||
func recordModelLoadFailure(appConfig *config.ApplicationConfig, modelName, backend string, err error, data map[string]any) {
|
||||
if !appConfig.EnableTracing {
|
||||
|
||||
122
core/backend/preload.go
Normal file
122
core/backend/preload.go
Normal file
@@ -0,0 +1,122 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/mudler/LocalAI/core/config"
|
||||
"github.com/mudler/LocalAI/pkg/model"
|
||||
"github.com/mudler/xlog"
|
||||
)
|
||||
|
||||
// PreloadModelByName loads the named model into memory so the first request
|
||||
// that uses it pays no cold-start load cost — the inverse of shutting a model
|
||||
// down. If the model is a realtime pipeline (its config declares a `pipeline:`
|
||||
// block), each configured sub-model (VAD, transcription, LLM, TTS,
|
||||
// sound_detection, voice_recognition) is loaded concurrently instead of the
|
||||
// pipeline stub, which has no backend of its own. It returns the model names
|
||||
// actually loaded and a joined error naming each sub-model that failed (nil on
|
||||
// full success); a partial pipeline load reports both the loaded names and the
|
||||
// failures so the caller can surface exactly what is and isn't resident.
|
||||
// Compaction's summary_model is deliberately left cold: it is only invoked off
|
||||
// the response path, so it can stay lazy.
|
||||
func PreloadModelByName(ctx context.Context, cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig, name string) ([]string, error) {
|
||||
cfg, err := cl.LoadModelConfigFileByNameDefaultOptions(name, appConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stages, err := pipelineStages(cl, &cfg.Pipeline, ml.ModelPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(stages) == 0 {
|
||||
// Not a pipeline: load the model's own backend directly.
|
||||
if err := PreloadModel(ctx, ml, *cfg, appConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []string{cfg.Name}, nil
|
||||
}
|
||||
return PreloadStages(ctx, ml, appConfig, stages)
|
||||
}
|
||||
|
||||
// PreloadStage names one pipeline sub-model to preload and the resolved config
|
||||
// to load it from (nil = stage absent, skipped). Role labels the pipeline slot
|
||||
// in errors and logs.
|
||||
type PreloadStage struct {
|
||||
Role string
|
||||
Cfg *config.ModelConfig
|
||||
}
|
||||
|
||||
// loadStage is PreloadModel behind a seam so PreloadStages can be unit-tested
|
||||
// without spawning real backends.
|
||||
var loadStage = PreloadModel
|
||||
|
||||
// pipelineStages resolves each populated pipeline stage to its concrete model
|
||||
// config, following a single alias hop — the same resolution the realtime
|
||||
// pipeline itself uses. A stage that fails to resolve is a misconfiguration,
|
||||
// so it fails fast rather than being deferred to load. A pipeline with no
|
||||
// stages set returns nil, which callers treat as "not a pipeline".
|
||||
func pipelineStages(cl *config.ModelConfigLoader, p *config.Pipeline, modelPath string) ([]PreloadStage, error) {
|
||||
voiceRec := ""
|
||||
if p.VoiceRecognition != nil {
|
||||
voiceRec = p.VoiceRecognition.Model
|
||||
}
|
||||
var stages []PreloadStage
|
||||
for _, s := range []struct{ role, name string }{
|
||||
{"vad", p.VAD},
|
||||
{"transcription", p.Transcription},
|
||||
{"llm", p.LLM},
|
||||
{"tts", p.TTS},
|
||||
{"sound_detection", p.SoundDetection},
|
||||
{"voice_recognition", voiceRec},
|
||||
} {
|
||||
if s.name == "" {
|
||||
continue
|
||||
}
|
||||
cfg, err := cl.LoadResolvedModelConfig(s.name, modelPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s (%s): %w", s.role, s.name, err)
|
||||
}
|
||||
stages = append(stages, PreloadStage{Role: s.role, Cfg: cfg})
|
||||
}
|
||||
return stages, nil
|
||||
}
|
||||
|
||||
// PreloadStages loads every present stage at once and waits for all of them, so
|
||||
// a pipeline warms in the time of its slowest stage rather than the sum. Absent
|
||||
// (nil-config) stages are skipped. A failed stage does not cancel the others —
|
||||
// they all run to completion so the joined error names every broken stage at
|
||||
// once, alongside the names that did load.
|
||||
func PreloadStages(ctx context.Context, ml *model.ModelLoader, appConfig *config.ApplicationConfig, stages []PreloadStage) ([]string, error) {
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
mu sync.Mutex
|
||||
loaded []string
|
||||
errs []error
|
||||
)
|
||||
for _, s := range stages {
|
||||
if s.Cfg == nil {
|
||||
continue
|
||||
}
|
||||
wg.Add(1)
|
||||
go func(s PreloadStage) {
|
||||
defer wg.Done()
|
||||
if err := loadStage(ctx, ml, *s.Cfg, appConfig); err != nil {
|
||||
xlog.Warn("preload: failed to load pipeline sub-model", "stage", s.Role, "model", s.Cfg.Name, "error", err)
|
||||
mu.Lock()
|
||||
errs = append(errs, fmt.Errorf("%s (%s): %w", s.Role, s.Cfg.Name, err))
|
||||
mu.Unlock()
|
||||
return
|
||||
}
|
||||
xlog.Debug("preload: loaded pipeline sub-model", "stage", s.Role, "model", s.Cfg.Name)
|
||||
mu.Lock()
|
||||
loaded = append(loaded, s.Cfg.Name)
|
||||
mu.Unlock()
|
||||
}(s)
|
||||
}
|
||||
wg.Wait()
|
||||
return loaded, errors.Join(errs...)
|
||||
}
|
||||
146
core/backend/preload_internal_test.go
Normal file
146
core/backend/preload_internal_test.go
Normal file
@@ -0,0 +1,146 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/mudler/LocalAI/core/config"
|
||||
"github.com/mudler/LocalAI/pkg/model"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("pipelineStages", func() {
|
||||
seed := func(dir string, names ...string) *config.ModelConfigLoader {
|
||||
for _, n := range names {
|
||||
yaml := "name: " + n + "\nbackend: fake-backend\n"
|
||||
Expect(os.WriteFile(filepath.Join(dir, n+".yaml"), []byte(yaml), 0o644)).To(Succeed())
|
||||
}
|
||||
cl := config.NewModelConfigLoader(dir)
|
||||
Expect(cl.LoadModelConfigsFromPath(dir)).To(Succeed())
|
||||
return cl
|
||||
}
|
||||
|
||||
It("resolves only the populated stages, in load order", func() {
|
||||
dir := GinkgoT().TempDir()
|
||||
cl := seed(dir, "vad-m", "stt-m", "llm-m", "tts-m")
|
||||
|
||||
stages, err := pipelineStages(cl, &config.Pipeline{
|
||||
VAD: "vad-m",
|
||||
Transcription: "stt-m",
|
||||
LLM: "llm-m",
|
||||
TTS: "tts-m",
|
||||
}, dir)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
roles := make([]string, len(stages))
|
||||
names := make([]string, len(stages))
|
||||
for i, s := range stages {
|
||||
roles[i] = s.Role
|
||||
names[i] = s.Cfg.Name
|
||||
}
|
||||
Expect(roles).To(Equal([]string{"vad", "transcription", "llm", "tts"}))
|
||||
Expect(names).To(Equal([]string{"vad-m", "stt-m", "llm-m", "tts-m"}))
|
||||
})
|
||||
|
||||
It("skips unset stages and includes sound_detection and voice_recognition when set", func() {
|
||||
dir := GinkgoT().TempDir()
|
||||
cl := seed(dir, "stt-m", "ced", "spk")
|
||||
|
||||
stages, err := pipelineStages(cl, &config.Pipeline{
|
||||
Transcription: "stt-m",
|
||||
SoundDetection: "ced",
|
||||
VoiceRecognition: &config.PipelineVoiceRecognition{Model: "spk"},
|
||||
}, dir)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
roles := make([]string, len(stages))
|
||||
for i, s := range stages {
|
||||
roles[i] = s.Role
|
||||
}
|
||||
Expect(roles).To(ConsistOf("transcription", "sound_detection", "voice_recognition"))
|
||||
})
|
||||
|
||||
It("returns nil for a pipeline with no stages (not a pipeline)", func() {
|
||||
dir := GinkgoT().TempDir()
|
||||
cl := seed(dir)
|
||||
|
||||
stages, err := pipelineStages(cl, &config.Pipeline{}, dir)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(stages).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("PreloadStages", func() {
|
||||
var (
|
||||
mu sync.Mutex
|
||||
seen []string
|
||||
)
|
||||
|
||||
// stubLoader swaps the loadStage seam for a recorder so no real backends
|
||||
// are spawned; errFor injects per-model failures.
|
||||
stubLoader := func(errFor map[string]error) {
|
||||
loadStage = func(_ context.Context, _ *model.ModelLoader, cfg config.ModelConfig, _ *config.ApplicationConfig) error {
|
||||
mu.Lock()
|
||||
seen = append(seen, cfg.Name)
|
||||
mu.Unlock()
|
||||
return errFor[cfg.Name]
|
||||
}
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
seen = nil
|
||||
})
|
||||
AfterEach(func() {
|
||||
loadStage = PreloadModel
|
||||
})
|
||||
|
||||
mkStage := func(role, name string) PreloadStage {
|
||||
return PreloadStage{Role: role, Cfg: &config.ModelConfig{Name: name}}
|
||||
}
|
||||
|
||||
It("loads every present stage, skips absent (nil-config) ones, and returns the loaded names", func() {
|
||||
stubLoader(nil)
|
||||
|
||||
loaded, err := PreloadStages(context.Background(), nil, nil, []PreloadStage{
|
||||
mkStage("vad", "vad-m"),
|
||||
{Role: "transcription"}, // absent stage
|
||||
mkStage("llm", "llm-m"),
|
||||
})
|
||||
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(loaded).To(ConsistOf("vad-m", "llm-m"))
|
||||
// Barrier: every stage has run by the time PreloadStages returns, so
|
||||
// reading seen without the lock here is safe.
|
||||
Expect(seen).To(ConsistOf("vad-m", "llm-m"))
|
||||
})
|
||||
|
||||
It("reports a joined error naming each failed stage while still loading the rest", func() {
|
||||
stubLoader(map[string]error{
|
||||
"vad-m": errors.New("vad boom"),
|
||||
"tts-m": errors.New("tts boom"),
|
||||
})
|
||||
|
||||
loaded, err := PreloadStages(context.Background(), nil, nil, []PreloadStage{
|
||||
mkStage("vad", "vad-m"),
|
||||
mkStage("llm", "llm-m"),
|
||||
mkStage("tts", "tts-m"),
|
||||
})
|
||||
|
||||
// Every stage ran (a failure does not cancel the others)...
|
||||
Expect(seen).To(ConsistOf("vad-m", "llm-m", "tts-m"))
|
||||
// ...the stage that loaded fine is reported as loaded...
|
||||
Expect(loaded).To(ConsistOf("llm-m"))
|
||||
// ...and the joined error names every broken stage and its cause.
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("vad (vad-m)"))
|
||||
Expect(err.Error()).To(ContainSubstring("vad boom"))
|
||||
Expect(err.Error()).To(ContainSubstring("tts (tts-m)"))
|
||||
Expect(err.Error()).To(ContainSubstring("tts boom"))
|
||||
Expect(err.Error()).ToNot(ContainSubstring("llm"))
|
||||
})
|
||||
})
|
||||
@@ -599,6 +599,13 @@ func DefaultRegistry() map[string]FieldMetaOverride {
|
||||
Component: "toggle",
|
||||
Order: 89,
|
||||
},
|
||||
"pipeline.disable_warmup": {
|
||||
Section: "pipeline",
|
||||
Label: "Disable Warmup",
|
||||
Description: "Turn off eager pre-loading of the pipeline's sub-models at realtime session start. By default LocalAI loads every configured sub-model backend (VAD, transcription, LLM, TTS, sound detection, voice recognition) before the session starts and blocks until they are ready, so the first turn pays no cold-start cost and a model that fails to load is reported at session start instead of mid-call. Enable this to restore the lazy 'load on first use' behavior — session start no longer waits on loading and load errors surface on the first turn instead. Useful to keep idle sessions from holding model memory they may never use.",
|
||||
Component: "toggle",
|
||||
Order: 90,
|
||||
},
|
||||
|
||||
// --- Functions ---
|
||||
"function.grammar.parallel_calls": {
|
||||
|
||||
@@ -656,6 +656,18 @@ type Pipeline struct {
|
||||
// to benefit. A client session.update still overrides type and eagerness
|
||||
// per session; retranscribe is server-side only. Unset keeps server_vad.
|
||||
TurnDetection PipelineTurnDetection `yaml:"turn_detection,omitempty" json:"turn_detection,omitempty"`
|
||||
|
||||
// DisableWarmup turns off eager pre-loading of the pipeline's sub-models at
|
||||
// realtime session start. By default (false) LocalAI loads every configured
|
||||
// sub-model backend (VAD, transcription, LLM, TTS, sound detection, voice
|
||||
// recognition) into memory (concurrently) before the
|
||||
// session is announced and blocks until they are ready, so the first turn
|
||||
// pays no cold-start cost and a model that fails to load surfaces as an error
|
||||
// at session start rather than mid-call. Set true to restore the lazy "load
|
||||
// on first use" behavior — session start no longer blocks on loading and
|
||||
// load errors surface on first use instead (e.g. to keep idle sessions from
|
||||
// holding model memory they may never use).
|
||||
DisableWarmup bool `yaml:"disable_warmup,omitempty" json:"disable_warmup,omitempty"`
|
||||
}
|
||||
|
||||
// PipelineCompaction configures summarize-then-drop for a realtime pipeline.
|
||||
|
||||
@@ -155,6 +155,25 @@ func (bcl *ModelConfigLoader) LoadModelConfigFileByNameDefaultOptions(modelName
|
||||
ModelPath(appConfig.SystemState.Model.ModelsPath))
|
||||
}
|
||||
|
||||
// LoadResolvedModelConfig loads a model config by name and follows a single
|
||||
// alias hop, so a caller that references an alias (e.g. a pipeline with
|
||||
// `llm: default`) gets the alias target's full config (Backend, Model, ...)
|
||||
// rather than the alias stub with an empty Backend. Without this the alias
|
||||
// survives unresolved into model loading and fails downstream — notably in
|
||||
// distributed mode with "backend name is empty". Mirrors the top-level alias
|
||||
// resolution in core/http/middleware/request.go.
|
||||
func (bcl *ModelConfigLoader) LoadResolvedModelConfig(modelName, modelPath string) (*ModelConfig, error) {
|
||||
cfg, err := bcl.LoadModelConfigFileByName(modelName, modelPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolved, _, err := bcl.ResolveAlias(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
|
||||
// This format is currently only used when reading a single file at startup, passed in via ApplicationConfig.ConfigFile
|
||||
func (bcl *ModelConfigLoader) LoadMultipleModelConfigsSingleFile(file string, opts ...ConfigLoaderOption) error {
|
||||
bcl.Lock()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package openai
|
||||
package config_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"github.com/mudler/LocalAI/core/config"
|
||||
)
|
||||
|
||||
// loadPipelineSubModel must resolve a pipeline sub-model that references an
|
||||
// alias (e.g. `llm: default`) one hop to the alias target's full config — so
|
||||
// the effective backend is the target's backend, not the empty backend of the
|
||||
// alias stub. This mirrors the top-level alias resolution done in
|
||||
// core/http/middleware/request.go, which the realtime pipeline previously
|
||||
// LoadResolvedModelConfig must resolve a model that references an alias
|
||||
// (e.g. a pipeline with `llm: default`) one hop to the alias target's full
|
||||
// config — so the effective backend is the target's backend, not the empty
|
||||
// backend of the alias stub. This mirrors the top-level alias resolution done
|
||||
// in core/http/middleware/request.go, which the realtime pipeline previously
|
||||
// skipped (failing in distributed mode with "backend name is empty").
|
||||
var _ = Describe("loadPipelineSubModel", func() {
|
||||
It("resolves a sub-model alias one hop to the target's config", func() {
|
||||
var _ = Describe("LoadResolvedModelConfig", func() {
|
||||
It("resolves an alias one hop to the target's config", func() {
|
||||
tmpDir := GinkgoT().TempDir()
|
||||
|
||||
// A real model config with a concrete backend.
|
||||
@@ -38,13 +38,13 @@ alias: real-llm
|
||||
Expect(cl.LoadModelConfigsFromPath(tmpDir)).To(Succeed())
|
||||
|
||||
// Resolving the alias must follow the hop to the target's full config.
|
||||
resolved, err := loadPipelineSubModel(cl, "default", tmpDir)
|
||||
resolved, err := cl.LoadResolvedModelConfig("default", tmpDir)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(resolved.IsAlias()).To(BeFalse())
|
||||
Expect(resolved.Backend).To(Equal("llama-cpp"))
|
||||
|
||||
// A non-alias name must load unchanged.
|
||||
direct, err := loadPipelineSubModel(cl, "real-llm", tmpDir)
|
||||
direct, err := cl.LoadResolvedModelConfig("real-llm", tmpDir)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(direct.Backend).To(Equal("llama-cpp"))
|
||||
Expect(direct.Name).To(Equal("real-llm"))
|
||||
54
core/http/endpoints/localai/backend_load.go
Normal file
54
core/http/endpoints/localai/backend_load.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package localai
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/mudler/LocalAI/core/backend"
|
||||
"github.com/mudler/LocalAI/core/config"
|
||||
"github.com/mudler/LocalAI/core/schema"
|
||||
"github.com/mudler/LocalAI/pkg/model"
|
||||
"github.com/mudler/xlog"
|
||||
)
|
||||
|
||||
// LoadModelEndpoint pre-loads a model into memory by name — the inverse of
|
||||
// /backend/shutdown. For a realtime pipeline model every configured sub-model
|
||||
// (VAD, transcription, LLM, TTS, sound_detection, voice_recognition) is loaded; for a regular
|
||||
// model its own backend is loaded. The call blocks until loading finishes so
|
||||
// clients can drive warm-up explicitly and learn up front whether a model
|
||||
// fails to load.
|
||||
// @Summary Pre-load a model into memory
|
||||
// @Description Loads the named model (or, for a realtime pipeline, all of its sub-models) into memory so subsequent requests pay no cold-start cost. The inverse of /backend/shutdown.
|
||||
// @Tags monitoring
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body schema.ModelLoadRequest true "Model to load"
|
||||
// @Success 200 {object} schema.ModelLoadResponse "Model loaded"
|
||||
// @Failure 400 {object} schema.ModelLoadResponse "Missing model name"
|
||||
// @Failure 500 {object} schema.ModelLoadResponse "Load failed (Loaded lists any sub-models that did load)"
|
||||
// @Router /backend/load [post]
|
||||
func LoadModelEndpoint(cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
input := new(schema.ModelLoadRequest)
|
||||
if err := c.Bind(input); err != nil {
|
||||
return err
|
||||
}
|
||||
if input.Model == "" {
|
||||
return c.JSON(http.StatusBadRequest, schema.ModelLoadResponse{Message: "model is required"})
|
||||
}
|
||||
|
||||
loaded, err := backend.PreloadModelByName(c.Request().Context(), cl, ml, appConfig, input.Model)
|
||||
if err != nil {
|
||||
xlog.Error("failed to pre-load model", "model", input.Model, "loaded", loaded, "error", err)
|
||||
return c.JSON(http.StatusInternalServerError, schema.ModelLoadResponse{
|
||||
Loaded: loaded,
|
||||
Message: "failed to load model: " + err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, schema.ModelLoadResponse{
|
||||
Loaded: loaded,
|
||||
Message: "model loaded",
|
||||
})
|
||||
}
|
||||
}
|
||||
102
core/http/endpoints/localai/backend_load_test.go
Normal file
102
core/http/endpoints/localai/backend_load_test.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package localai_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/mudler/LocalAI/core/config"
|
||||
. "github.com/mudler/LocalAI/core/http/endpoints/localai"
|
||||
"github.com/mudler/LocalAI/core/schema"
|
||||
"github.com/mudler/LocalAI/pkg/model"
|
||||
"github.com/mudler/LocalAI/pkg/system"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("LoadModelEndpoint (/backend/load)", func() {
|
||||
var (
|
||||
app *echo.Echo
|
||||
tempDir string
|
||||
configLoader *config.ModelConfigLoader
|
||||
modelLoader *model.ModelLoader
|
||||
appConfig *config.ApplicationConfig
|
||||
)
|
||||
|
||||
post := func(body string) *httptest.ResponseRecorder {
|
||||
req := httptest.NewRequest(http.MethodPost, "/backend/load", bytes.NewBufferString(body))
|
||||
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||
rec := httptest.NewRecorder()
|
||||
app.ServeHTTP(rec, req)
|
||||
return rec
|
||||
}
|
||||
|
||||
decode := func(rec *httptest.ResponseRecorder) schema.ModelLoadResponse {
|
||||
var resp schema.ModelLoadResponse
|
||||
Expect(json.Unmarshal(rec.Body.Bytes(), &resp)).To(Succeed())
|
||||
return resp
|
||||
}
|
||||
|
||||
writeConfig := func(name, contents string) {
|
||||
Expect(os.WriteFile(filepath.Join(tempDir, name+".yaml"), []byte(contents), 0o600)).To(Succeed())
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
tempDir, err = os.MkdirTemp("", "backend-load-test-*")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
systemState, err := system.GetSystemState(system.WithModelPath(tempDir))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
appConfig = config.NewApplicationConfig(config.WithSystemState(systemState))
|
||||
configLoader = config.NewModelConfigLoader(tempDir)
|
||||
modelLoader = model.NewModelLoader(systemState) // no backends installed
|
||||
|
||||
app = echo.New()
|
||||
app.POST("/backend/load", LoadModelEndpoint(configLoader, modelLoader, appConfig))
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
_ = os.RemoveAll(tempDir)
|
||||
})
|
||||
|
||||
It("rejects a request with no model name", func() {
|
||||
rec := post(`{}`)
|
||||
Expect(rec.Code).To(Equal(http.StatusBadRequest))
|
||||
Expect(decode(rec).Message).To(ContainSubstring("model is required"))
|
||||
})
|
||||
|
||||
It("reports a load failure for a regular model with nothing loaded", func() {
|
||||
writeConfig("solo", "name: solo\n")
|
||||
|
||||
rec := post(`{"model":"solo"}`)
|
||||
Expect(rec.Code).To(Equal(http.StatusInternalServerError))
|
||||
|
||||
resp := decode(rec)
|
||||
Expect(resp.Loaded).To(BeEmpty())
|
||||
Expect(resp.Message).To(ContainSubstring("failed to load model"))
|
||||
})
|
||||
|
||||
It("expands a pipeline model and reports each sub-model that failed to load", func() {
|
||||
writeConfig("voicebot", "name: voicebot\npipeline:\n vad: vad-m\n transcription: stt-m\n llm: llm-m\n tts: tts-m\n")
|
||||
writeConfig("vad-m", "name: vad-m\n")
|
||||
writeConfig("stt-m", "name: stt-m\n")
|
||||
writeConfig("llm-m", "name: llm-m\n")
|
||||
writeConfig("tts-m", "name: tts-m\n")
|
||||
|
||||
rec := post(`{"model":"voicebot"}`)
|
||||
Expect(rec.Code).To(Equal(http.StatusInternalServerError))
|
||||
|
||||
resp := decode(rec)
|
||||
Expect(resp.Message).To(ContainSubstring("failed to load model"))
|
||||
// The pipeline stub itself is never loaded; its sub-models are what the
|
||||
// endpoint tries, so the error names them rather than "voicebot".
|
||||
Expect(resp.Message).To(ContainSubstring("vad-m"))
|
||||
Expect(resp.Message).ToNot(ContainSubstring("voicebot"))
|
||||
})
|
||||
})
|
||||
@@ -51,6 +51,9 @@ func (stubClient) EditModelConfig(_ context.Context, _ string, _ map[string]any)
|
||||
return nil
|
||||
}
|
||||
func (stubClient) ReloadModels(_ context.Context) error { return nil }
|
||||
func (stubClient) LoadModel(_ context.Context, model string) ([]string, error) {
|
||||
return []string{model}, nil
|
||||
}
|
||||
func (stubClient) SetAlias(_ context.Context, _, _ string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
@@ -266,6 +267,12 @@ type Model interface {
|
||||
// grpcerrors.IsLiveTranscriptionUnsupported.
|
||||
TranscribeLive(ctx context.Context, language string, onEvent func(backend.LiveTranscriptionEvent)) (backend.LiveTranscriptionSession, error)
|
||||
PredictConfig() *config.ModelConfig
|
||||
// Warmup eagerly loads the pipeline's sub-model backends into memory so the
|
||||
// first realtime turn doesn't pay each backend's cold-start load cost. Loads
|
||||
// run concurrently; Warmup blocks until they all finish and returns a joined
|
||||
// error naming every stage that failed to load (nil if all succeeded), so a
|
||||
// caller can surface model-load failures at session start instead of mid-call.
|
||||
Warmup(ctx context.Context) error
|
||||
}
|
||||
|
||||
var upgrader = websocket.Upgrader{
|
||||
@@ -583,18 +590,8 @@ func runRealtimeSession(application *application.Application, t Transport, model
|
||||
}
|
||||
session.ModelInterface = m
|
||||
|
||||
if session.SummaryModel != "" {
|
||||
summaryModelName := session.SummaryModel
|
||||
sid := sessionID
|
||||
session.summarizerFactory = func() (Model, error) {
|
||||
summaryCfg, lerr := application.ModelConfigLoader().LoadModelConfigFileByNameDefaultOptions(summaryModelName, application.ApplicationConfig())
|
||||
if lerr != nil {
|
||||
return nil, fmt.Errorf("load summary model config %q: %w", summaryModelName, lerr)
|
||||
}
|
||||
return newModel(&summaryCfg.Pipeline, application.ModelConfigLoader(), application.ModelLoader(), application.ApplicationConfig(), evaluator, buildRealtimeRoutingContext(application, sid))
|
||||
}
|
||||
}
|
||||
|
||||
// The voice gate is built before the warm-up below so its
|
||||
// speaker-recognition model can warm alongside the pipeline stages.
|
||||
if cfg.Pipeline.VoiceGateEnabled() {
|
||||
gate, gerr := newVoiceGate(
|
||||
*cfg.Pipeline.VoiceRecognition,
|
||||
@@ -612,6 +609,47 @@ func runRealtimeSession(application *application.Application, t Transport, model
|
||||
xlog.Info("realtime voice recognition gate enabled", "mode", gate.cfg.Mode, "when", gate.cfg.When)
|
||||
}
|
||||
|
||||
// Warm the pipeline's sub-model backends before announcing the session.
|
||||
// Loads run concurrently but we block here until they all finish, so a model
|
||||
// that fails to load (missing weights, bad backend, OOM) surfaces as an error
|
||||
// at session start rather than stalling — or failing — mid-call on the first
|
||||
// turn (VAD on the first audio chunk, STT at end-of-speech, LLM on the first
|
||||
// reply, TTS on the first spoken output). On success the backends are already
|
||||
// resident, so the first turn pays no cold-start cost. Opt out per pipeline
|
||||
// with `pipeline.disable_warmup: true` to restore lazy load-on-first-use
|
||||
// (errors then surface on first use instead of at session start).
|
||||
if !cfg.Pipeline.DisableWarmup {
|
||||
warmErr := make(chan error, 1)
|
||||
go func() { warmErr <- m.Warmup(context.Background()) }()
|
||||
// The voice-gate model warms concurrently with the pipeline stages: an
|
||||
// enforced gate blocks each utterance on speaker resolution, so its
|
||||
// cold-start would otherwise land on the first turn too. (Compaction's
|
||||
// summary_model stays lazy — it only runs off the response path.)
|
||||
var gateErr error
|
||||
if session.voiceGate != nil {
|
||||
_, gateErr = backend.PreloadStages(context.Background(), application.ModelLoader(), application.ApplicationConfig(), []backend.PreloadStage{
|
||||
{Role: "voice_recognition", Cfg: session.voiceGate.recCfg},
|
||||
})
|
||||
}
|
||||
if err := errors.Join(<-warmErr, gateErr); err != nil {
|
||||
xlog.Error("realtime warmup failed", "model", model, "error", err)
|
||||
sendError(t, "model_load_error", "Failed to load pipeline models: "+err.Error(), "", "")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if session.SummaryModel != "" {
|
||||
summaryModelName := session.SummaryModel
|
||||
sid := sessionID
|
||||
session.summarizerFactory = func() (Model, error) {
|
||||
summaryCfg, lerr := application.ModelConfigLoader().LoadModelConfigFileByNameDefaultOptions(summaryModelName, application.ApplicationConfig())
|
||||
if lerr != nil {
|
||||
return nil, fmt.Errorf("load summary model config %q: %w", summaryModelName, lerr)
|
||||
}
|
||||
return newModel(&summaryCfg.Pipeline, application.ModelConfigLoader(), application.ModelLoader(), application.ApplicationConfig(), evaluator, buildRealtimeRoutingContext(application, sid))
|
||||
}
|
||||
}
|
||||
|
||||
// Store the session and notify the transport (for WebRTC audio track handling)
|
||||
sessionLock.Lock()
|
||||
sessions[sessionID] = session
|
||||
@@ -1125,6 +1163,21 @@ func updateSession(session *Session, update *types.SessionUnion, cl *config.Mode
|
||||
return err
|
||||
}
|
||||
session.ModelInterface = m
|
||||
// A session.update that swaps the model/voice rebuilds the pipeline, so
|
||||
// warm the new backends too (unless opted out) — otherwise the next turn
|
||||
// pays the cold-start load the original session warm-up already avoided.
|
||||
// Unlike session start this stays non-blocking: updateSession runs under
|
||||
// the global sessionLock, so blocking on a multi-second load here would
|
||||
// stall every other session. Load errors are logged (and still surface on
|
||||
// first use); per-stage failures are already warned inside
|
||||
// backend.PreloadStages.
|
||||
if !session.ModelConfig.Pipeline.DisableWarmup {
|
||||
go func() {
|
||||
if err := m.Warmup(context.Background()); err != nil {
|
||||
xlog.Error("realtime warmup failed after session.update", "error", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
if rt.Audio != nil && rt.Audio.Input != nil && rt.Audio.Input.TurnDetectionSet {
|
||||
|
||||
@@ -174,6 +174,8 @@ func (m *fakeModel) TranscribeLive(_ context.Context, _ string, onEvent func(bac
|
||||
|
||||
func (m *fakeModel) PredictConfig() *config.ModelConfig { return m.cfg }
|
||||
|
||||
func (m *fakeModel) Warmup(ctx context.Context) error { return nil }
|
||||
|
||||
// fakeLiveSession records what semantic_vad fed and closed; closeEvents are
|
||||
// replayed through onEvent during Close, mimicking the backend's finalize
|
||||
// flush (trailing delta + Final) landing before Close returns.
|
||||
|
||||
@@ -110,6 +110,15 @@ func (m *transcriptOnlyModel) PredictConfig() *config.ModelConfig {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *transcriptOnlyModel) Warmup(ctx context.Context) error {
|
||||
_, err := backend.PreloadStages(ctx, m.modelLoader, m.appConfig, []backend.PreloadStage{
|
||||
{Role: "vad", Cfg: m.VADConfig},
|
||||
{Role: "transcription", Cfg: m.TranscriptionConfig},
|
||||
{Role: "sound_detection", Cfg: m.SoundDetectionConfig},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *wrappedModel) VAD(ctx context.Context, request *schema.VADRequest) (*schema.VADResponse, error) {
|
||||
return backend.VAD(request, ctx, m.modelLoader, m.appConfig, *m.VADConfig)
|
||||
}
|
||||
@@ -360,6 +369,17 @@ func (m *wrappedModel) PredictConfig() *config.ModelConfig {
|
||||
return m.LLMConfig
|
||||
}
|
||||
|
||||
func (m *wrappedModel) Warmup(ctx context.Context) error {
|
||||
_, err := backend.PreloadStages(ctx, m.modelLoader, m.appConfig, []backend.PreloadStage{
|
||||
{Role: "vad", Cfg: m.VADConfig},
|
||||
{Role: "transcription", Cfg: m.TranscriptionConfig},
|
||||
{Role: "llm", Cfg: m.LLMConfig},
|
||||
{Role: "tts", Cfg: m.TTSConfig},
|
||||
{Role: "sound_detection", Cfg: m.SoundDetectionConfig},
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// wavStreamHeaderBytes is the size of the WAV header that backend.ModelTTSStream
|
||||
// emits as its first audio callback; the sample rate lives at byte offset 24.
|
||||
const wavStreamHeaderBytes = 44
|
||||
@@ -440,7 +460,7 @@ func loadSoundDetectionConfig(pipeline *config.Pipeline, cl *config.ModelConfigL
|
||||
if pipeline.SoundDetection == "" {
|
||||
return nil, nil
|
||||
}
|
||||
cfg, err := loadPipelineSubModel(cl, pipeline.SoundDetection, ml.ModelPath)
|
||||
cfg, err := cl.LoadResolvedModelConfig(pipeline.SoundDetection, ml.ModelPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load sound detection config: %w", err)
|
||||
}
|
||||
@@ -451,7 +471,7 @@ func loadSoundDetectionConfig(pipeline *config.Pipeline, cl *config.ModelConfigL
|
||||
}
|
||||
|
||||
func newTranscriptionOnlyModel(pipeline *config.Pipeline, cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig) (Model, *config.ModelConfig, error) {
|
||||
cfgVAD, err := loadPipelineSubModel(cl, pipeline.VAD, ml.ModelPath)
|
||||
cfgVAD, err := cl.LoadResolvedModelConfig(pipeline.VAD, ml.ModelPath)
|
||||
if err != nil {
|
||||
|
||||
return nil, nil, fmt.Errorf("failed to load backend config: %w", err)
|
||||
@@ -461,7 +481,7 @@ func newTranscriptionOnlyModel(pipeline *config.Pipeline, cl *config.ModelConfig
|
||||
return nil, nil, fmt.Errorf("failed to validate config: %w", err)
|
||||
}
|
||||
|
||||
cfgSST, err := loadPipelineSubModel(cl, pipeline.Transcription, ml.ModelPath)
|
||||
cfgSST, err := cl.LoadResolvedModelConfig(pipeline.Transcription, ml.ModelPath)
|
||||
if err != nil {
|
||||
|
||||
return nil, nil, fmt.Errorf("failed to load backend config: %w", err)
|
||||
@@ -550,30 +570,11 @@ func buildRealtimeRoutingContext(a *application.Application, sessionID string) *
|
||||
}
|
||||
}
|
||||
|
||||
// loadPipelineSubModel loads a pipeline sub-model config by name and follows a
|
||||
// single alias hop, so a pipeline that references an alias (e.g. `llm: default`)
|
||||
// gets the alias target's full config (Backend, Model, ...) rather than the
|
||||
// alias stub with an empty Backend. Without this the alias survives unresolved
|
||||
// into model loading and fails downstream — notably in distributed mode with
|
||||
// "backend name is empty". Mirrors the top-level alias resolution in
|
||||
// core/http/middleware/request.go.
|
||||
func loadPipelineSubModel(cl *config.ModelConfigLoader, name, modelPath string) (*config.ModelConfig, error) {
|
||||
cfg, err := cl.LoadModelConfigFileByName(name, modelPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolved, _, err := cl.ResolveAlias(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
|
||||
// returns and loads either a wrapped model or a model that support audio-to-audio
|
||||
func newModel(pipeline *config.Pipeline, cl *config.ModelConfigLoader, ml *model.ModelLoader, appConfig *config.ApplicationConfig, evaluator *templates.Evaluator, routing *RealtimeRoutingContext) (Model, error) {
|
||||
xlog.Debug("Creating new model pipeline model", "pipeline", pipeline)
|
||||
|
||||
cfgVAD, err := loadPipelineSubModel(cl, pipeline.VAD, ml.ModelPath)
|
||||
cfgVAD, err := cl.LoadResolvedModelConfig(pipeline.VAD, ml.ModelPath)
|
||||
if err != nil {
|
||||
|
||||
return nil, fmt.Errorf("failed to load backend config: %w", err)
|
||||
@@ -584,7 +585,7 @@ func newModel(pipeline *config.Pipeline, cl *config.ModelConfigLoader, ml *model
|
||||
}
|
||||
|
||||
// TODO: Do we always need a transcription model? It can be disabled. Note that any-to-any instruction following models don't transcribe as such, so if transcription is required it is a separate process
|
||||
cfgSST, err := loadPipelineSubModel(cl, pipeline.Transcription, ml.ModelPath)
|
||||
cfgSST, err := cl.LoadResolvedModelConfig(pipeline.Transcription, ml.ModelPath)
|
||||
if err != nil {
|
||||
|
||||
return nil, fmt.Errorf("failed to load backend config: %w", err)
|
||||
@@ -616,7 +617,7 @@ func newModel(pipeline *config.Pipeline, cl *config.ModelConfigLoader, ml *model
|
||||
xlog.Debug("Loading a wrapped model")
|
||||
|
||||
// Otherwise we want to return a wrapped model, which is a "virtual" model that re-uses other models to perform operations
|
||||
cfgLLM, err := loadPipelineSubModel(cl, pipeline.LLM, ml.ModelPath)
|
||||
cfgLLM, err := cl.LoadResolvedModelConfig(pipeline.LLM, ml.ModelPath)
|
||||
if err != nil {
|
||||
|
||||
return nil, fmt.Errorf("failed to load backend config: %w", err)
|
||||
@@ -631,7 +632,7 @@ func newModel(pipeline *config.Pipeline, cl *config.ModelConfigLoader, ml *model
|
||||
applyPipelineReasoning(cfgLLM, *pipeline)
|
||||
applyPipelineThinking(cfgLLM, *pipeline)
|
||||
|
||||
cfgTTS, err := loadPipelineSubModel(cl, pipeline.TTS, ml.ModelPath)
|
||||
cfgTTS, err := cl.LoadResolvedModelConfig(pipeline.TTS, ml.ModelPath)
|
||||
if err != nil {
|
||||
|
||||
return nil, fmt.Errorf("failed to load backend config: %w", err)
|
||||
|
||||
@@ -21,6 +21,7 @@ type namedEmbedding struct {
|
||||
// drive the realtime pipeline.
|
||||
type voiceGate struct {
|
||||
cfg config.PipelineVoiceRecognition // normalized
|
||||
recCfg *config.ModelConfig // resolved speaker-recognition model, for warm-up
|
||||
registry voicerecognition.Registry // identify mode (nil otherwise)
|
||||
refEmbeds []namedEmbedding // verify mode, pre-embedded refs
|
||||
refAudios []config.VoiceReference // verify + anti-spoofing: ref paths
|
||||
@@ -72,7 +73,9 @@ func newVoiceGate(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
recCfg, err := cl.LoadModelConfigFileByName(cfg.Model, ml.ModelPath)
|
||||
// Resolved like every other pipeline sub-model (one alias hop), so an
|
||||
// aliased voice_recognition model gets its target's backend.
|
||||
recCfg, err := cl.LoadResolvedModelConfig(cfg.Model, ml.ModelPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("voice_recognition: failed to load model %q: %w", cfg.Model, err)
|
||||
}
|
||||
@@ -82,6 +85,7 @@ func newVoiceGate(
|
||||
|
||||
g := &voiceGate{
|
||||
cfg: cfg,
|
||||
recCfg: recCfg,
|
||||
registry: registry,
|
||||
embedFn: func(ctx context.Context, wavPath string) ([]float32, error) {
|
||||
res, err := backend.VoiceEmbed(ctx, wavPath, ml, appConfig, *recCfg)
|
||||
|
||||
64
core/http/endpoints/openai/realtime_warmup_test.go
Normal file
64
core/http/endpoints/openai/realtime_warmup_test.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package openai
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/mudler/LocalAI/core/config"
|
||||
"github.com/mudler/LocalAI/pkg/model"
|
||||
"github.com/mudler/LocalAI/pkg/system"
|
||||
)
|
||||
|
||||
// Warmup delegates to backend.PreloadStages (its concurrency, nil-skipping and
|
||||
// error-joining semantics are pinned in core/backend). These specs pin the
|
||||
// wiring instead: each realtime model type must warm exactly its configured
|
||||
// stages under the right pipeline-role labels. No backends are installed, so
|
||||
// every attempted stage fails to load — the joined error is the proof of which
|
||||
// stages were attempted and how they were labeled.
|
||||
var _ = Describe("realtime model Warmup wiring", func() {
|
||||
newLoader := func() (*model.ModelLoader, *config.ApplicationConfig) {
|
||||
systemState, err := system.GetSystemState(system.WithModelPath(GinkgoT().TempDir()))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
appConfig := config.NewApplicationConfig(config.WithSystemState(systemState))
|
||||
return model.NewModelLoader(systemState), appConfig
|
||||
}
|
||||
|
||||
It("wrappedModel warms every configured stage under its pipeline role", func() {
|
||||
ml, appConfig := newLoader()
|
||||
m := &wrappedModel{
|
||||
VADConfig: &config.ModelConfig{Name: "vad-m"},
|
||||
TranscriptionConfig: &config.ModelConfig{Name: "stt-m"},
|
||||
LLMConfig: &config.ModelConfig{Name: "llm-m"},
|
||||
TTSConfig: &config.ModelConfig{Name: "tts-m"},
|
||||
SoundDetectionConfig: &config.ModelConfig{Name: "ced-m"},
|
||||
modelLoader: ml,
|
||||
appConfig: appConfig,
|
||||
}
|
||||
|
||||
err := m.Warmup(context.Background())
|
||||
Expect(err).To(HaveOccurred())
|
||||
for _, stage := range []string{"vad (vad-m)", "transcription (stt-m)", "llm (llm-m)", "tts (tts-m)", "sound_detection (ced-m)"} {
|
||||
Expect(err.Error()).To(ContainSubstring(stage))
|
||||
}
|
||||
})
|
||||
|
||||
It("transcriptOnlyModel warms its stages and skips absent ones", func() {
|
||||
ml, appConfig := newLoader()
|
||||
m := &transcriptOnlyModel{
|
||||
VADConfig: &config.ModelConfig{Name: "vad-m"},
|
||||
TranscriptionConfig: &config.ModelConfig{Name: "stt-m"},
|
||||
// SoundDetectionConfig nil: an absent stage must be skipped, not
|
||||
// fail the warm-up.
|
||||
modelLoader: ml,
|
||||
appConfig: appConfig,
|
||||
}
|
||||
|
||||
err := m.Warmup(context.Background())
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("vad (vad-m)"))
|
||||
Expect(err.Error()).To(ContainSubstring("transcription (stt-m)"))
|
||||
Expect(err.Error()).ToNot(ContainSubstring("sound_detection"))
|
||||
})
|
||||
})
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -29,6 +30,8 @@ const testModel = "Qwen3-VL-2B-Instruct-Q4_K_M"
|
||||
|
||||
var _ = Describe("Open Responses API", func() {
|
||||
var app *echo.Echo
|
||||
var localApp *application.Application
|
||||
var localModelDir string
|
||||
var c context.Context
|
||||
var cancel context.CancelFunc
|
||||
|
||||
@@ -38,28 +41,47 @@ var _ = Describe("Open Responses API", func() {
|
||||
|
||||
Context("API with ephemeral models", func() {
|
||||
BeforeEach(func(sc SpecContext) {
|
||||
var err error
|
||||
// This suite exercises the /v1/responses HTTP/protocol contract
|
||||
// (Content-Type, SSE framing, response envelope, error shapes),
|
||||
// not real inference — so it runs against the same prebuilt
|
||||
// mock-backend the rest of the http suite uses instead of
|
||||
// downloading a real model. Skip cleanly when it isn't built.
|
||||
if mockBackendPath == "" {
|
||||
Skip("mock-backend binary not built; run 'make build-mock-backend'")
|
||||
}
|
||||
|
||||
backendPath := os.Getenv("BACKENDS_PATH")
|
||||
var err error
|
||||
|
||||
c, cancel = context.WithCancel(context.Background())
|
||||
|
||||
// Isolated model dir carrying a single config named after testModel
|
||||
// but served by the mock backend, so the responses endpoint can
|
||||
// resolve and load the model without any real backend build.
|
||||
localModelDir, err = os.MkdirTemp("", "openresponses-models-")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
mockModelYAML := "name: " + testModel + "\n" +
|
||||
"backend: mock-backend\n" +
|
||||
"parameters:\n" +
|
||||
" model: mock-model.bin\n"
|
||||
Expect(os.WriteFile(filepath.Join(localModelDir, testModel+".yaml"), []byte(mockModelYAML), 0644)).To(Succeed())
|
||||
|
||||
systemState, err := system.GetSystemState(
|
||||
system.WithBackendPath(backendPath),
|
||||
system.WithModelPath(modelDir),
|
||||
system.WithBackendPath(backendDir),
|
||||
system.WithModelPath(localModelDir),
|
||||
)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
application, err := application.New(
|
||||
localApp, err = application.New(
|
||||
append(commonOpts,
|
||||
config.WithContext(c),
|
||||
config.WithSystemState(systemState),
|
||||
config.WithApiKeys([]string{apiKey}),
|
||||
config.WithModelsURL("https://huggingface.co/unsloth/Qwen3-VL-2B-Instruct-GGUF"),
|
||||
)...)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
localApp.ModelLoader().SetExternalBackend("mock-backend", mockBackendPath)
|
||||
|
||||
app, err = API(application)
|
||||
app, err = API(localApp)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
go func() {
|
||||
@@ -80,14 +102,24 @@ var _ = Describe("Open Responses API", func() {
|
||||
})
|
||||
|
||||
AfterEach(func(sc SpecContext) {
|
||||
// Synchronous app shutdown first — context-cancel cleanup is async
|
||||
// and races test-binary exit, orphaning mock-backend children.
|
||||
if localApp != nil {
|
||||
_ = localApp.Shutdown()
|
||||
localApp = nil
|
||||
}
|
||||
cancel()
|
||||
if app != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
err := app.Shutdown(ctx)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
app = nil
|
||||
}
|
||||
if localModelDir != "" {
|
||||
_ = os.RemoveAll(localModelDir)
|
||||
localModelDir = ""
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Context("HTTP Protocol Compliance", func() {
|
||||
@@ -969,13 +1001,16 @@ var _ = Describe("Open Responses API", func() {
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(itemID).ToNot(BeEmpty())
|
||||
|
||||
// Now create a new response with item_reference
|
||||
// Now create a new response with item_reference. Per the OpenAI
|
||||
// Responses spec (and this server's parser in
|
||||
// endpoints/openresponses/responses.go) an item_reference carries
|
||||
// the referenced item in the "id" field, not "item_id".
|
||||
reqBody2 := map[string]any{
|
||||
"model": testModel,
|
||||
"input": []any{
|
||||
map[string]any{
|
||||
"type": "item_reference",
|
||||
"item_id": itemID,
|
||||
"type": "item_reference",
|
||||
"id": itemID,
|
||||
},
|
||||
map[string]any{
|
||||
"type": "message",
|
||||
@@ -1005,8 +1040,8 @@ var _ = Describe("Open Responses API", func() {
|
||||
"model": testModel,
|
||||
"input": []any{
|
||||
map[string]any{
|
||||
"type": "item_reference",
|
||||
"item_id": "nonexistent_item_id",
|
||||
"type": "item_reference",
|
||||
"id": "nonexistent_item_id",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
133
core/http/react-ui/e2e/forking-chat.spec.js
Normal file
133
core/http/react-ui/e2e/forking-chat.spec.js
Normal file
@@ -0,0 +1,133 @@
|
||||
import { test, expect } from './coverage-fixtures.js'
|
||||
|
||||
// Seeds two-message chat into localStorage so we don't need a live model.
|
||||
async function seedChat(page, history) {
|
||||
await page.addInitScript((h) => {
|
||||
const chat = {
|
||||
id: 'seed1', name: 'Seeded Chat', model: 'test-model',
|
||||
history: h, systemPrompt: '', mcpMode: false, mcpServers: [],
|
||||
clientMCPServers: [], temperature: null, topP: null, topK: null,
|
||||
tokenUsage: { prompt: 0, completion: 0, total: 0 },
|
||||
contextSize: null, createdAt: Date.now(), updatedAt: Date.now(),
|
||||
}
|
||||
localStorage.setItem('localai_chats_data', JSON.stringify({
|
||||
chats: [chat], activeChatId: 'seed1', lastSaved: Date.now(),
|
||||
}))
|
||||
}, history)
|
||||
}
|
||||
|
||||
async function mockModels(page) {
|
||||
await page.route('**/api/models/capabilities', (route) => route.fulfill({
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ data: [{ id: 'test-model', capabilities: ['FLAG_CHAT'] }] }),
|
||||
}))
|
||||
await page.route('**/api/operations', (route) => route.fulfill({
|
||||
contentType: 'application/json', body: JSON.stringify({ operations: [] }),
|
||||
}))
|
||||
}
|
||||
|
||||
const TWO_TURNS = [
|
||||
{ role: 'user', content: 'first question' },
|
||||
{ role: 'assistant', content: 'first answer' },
|
||||
{ role: 'user', content: 'second question' },
|
||||
{ role: 'assistant', content: 'second answer' },
|
||||
]
|
||||
|
||||
test('duplicate creates an independent copy and switches to it', async ({ page }) => {
|
||||
await mockModels(page)
|
||||
await seedChat(page, TWO_TURNS)
|
||||
await page.goto('/app/chat')
|
||||
|
||||
// Open the chats menu (Ctrl/Cmd+K) and duplicate the seeded chat.
|
||||
// Wait for the menu trigger to mount so its global keydown listener is armed
|
||||
// before we dispatch the shortcut.
|
||||
await page.getByTitle('Conversations (Ctrl/Cmd+K)').waitFor()
|
||||
await page.keyboard.press('Control+k')
|
||||
await page.getByTitle('Duplicate chat').first().click()
|
||||
|
||||
// A new active chat named "Seeded Chat (fork)" with the same 4 messages.
|
||||
await expect(page.locator('.chat-header-title')).toHaveText('Seeded Chat (fork)')
|
||||
await expect(page.locator('.chat-message-user')).toHaveCount(2)
|
||||
await expect(page.locator('.chat-message-assistant')).toHaveCount(2)
|
||||
})
|
||||
|
||||
async function mockCompletion(page, replyText) {
|
||||
await page.route('**/v1/chat/completions', (route) => {
|
||||
const sse =
|
||||
`data: ${JSON.stringify({ choices: [{ delta: { content: replyText } }] })}\n\n` +
|
||||
`data: ${JSON.stringify({ choices: [{ delta: {}, finish_reason: 'stop' }], usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 } })}\n\n` +
|
||||
`data: [DONE]\n\n`
|
||||
route.fulfill({ status: 200, contentType: 'text/event-stream', body: sse })
|
||||
})
|
||||
}
|
||||
|
||||
test('retry regenerates the first answer and drops the later turn', async ({ page }) => {
|
||||
await mockModels(page)
|
||||
// Capture the outbound request body so we can assert the model receives the
|
||||
// truncated history (not the stale downstream turns).
|
||||
let sentMessages = null
|
||||
await page.route('**/v1/chat/completions', (route) => {
|
||||
sentMessages = route.request().postDataJSON()?.messages || []
|
||||
const sse =
|
||||
`data: ${JSON.stringify({ choices: [{ delta: { content: 'REGENERATED first answer' } }] })}\n\n` +
|
||||
`data: ${JSON.stringify({ choices: [{ delta: {}, finish_reason: 'stop' }], usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 } })}\n\n` +
|
||||
`data: [DONE]\n\n`
|
||||
route.fulfill({ status: 200, contentType: 'text/event-stream', body: sse })
|
||||
})
|
||||
await seedChat(page, TWO_TURNS)
|
||||
await page.goto('/app/chat')
|
||||
|
||||
// Hover the FIRST assistant message and click its retry button.
|
||||
const firstAssistant = page.locator('.chat-message-assistant').first()
|
||||
await firstAssistant.hover()
|
||||
await firstAssistant.getByTitle('Regenerate').click()
|
||||
|
||||
// History is truncated to the first user turn, then the new answer streams in;
|
||||
// the second Q/A turn is gone.
|
||||
await expect(page.locator('.chat-message-assistant')).toContainText(['REGENERATED first answer'])
|
||||
await expect(page.locator('.chat-message-user')).toHaveCount(1)
|
||||
await expect(page.locator('.chat-message-assistant')).toHaveCount(1)
|
||||
|
||||
// The OUTBOUND payload must also be truncated: the resent user turn is present,
|
||||
// but the downstream turn and the stale first answer must be gone.
|
||||
const contents = (sentMessages || []).map(m =>
|
||||
typeof m.content === 'string' ? m.content : JSON.stringify(m.content)
|
||||
)
|
||||
expect(contents.join('\n')).toContain('first question')
|
||||
expect(contents.join('\n')).not.toContain('second question')
|
||||
expect(contents.join('\n')).not.toContain('first answer')
|
||||
})
|
||||
|
||||
test('copy chat puts the whole conversation on the clipboard', async ({ page, context }) => {
|
||||
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
|
||||
await mockModels(page)
|
||||
await seedChat(page, TWO_TURNS)
|
||||
await page.goto('/app/chat')
|
||||
|
||||
// Wait for the menu trigger to mount so its global keydown listener is armed
|
||||
// before we dispatch the shortcut (same mount-race guard as the duplicate test).
|
||||
await page.getByTitle('Conversations (Ctrl/Cmd+K)').waitFor()
|
||||
await page.keyboard.press('Control+k')
|
||||
await page.getByTitle('Copy chat').first().click()
|
||||
|
||||
const clip = await page.evaluate(() => navigator.clipboard.readText())
|
||||
expect(clip).toContain('# Seeded Chat')
|
||||
expect(clip).toContain('first answer')
|
||||
expect(clip).toContain('second answer')
|
||||
})
|
||||
|
||||
test('branch from the first answer forks history up to that point', async ({ page }) => {
|
||||
await mockModels(page)
|
||||
await seedChat(page, TWO_TURNS)
|
||||
await page.goto('/app/chat')
|
||||
|
||||
const firstAssistant = page.locator('.chat-message-assistant').first()
|
||||
await firstAssistant.hover()
|
||||
await firstAssistant.getByTitle('Branch from here').click()
|
||||
|
||||
// New active chat "Seeded Chat (fork)" contains only the first Q/A turn.
|
||||
await expect(page.locator('.chat-header-title')).toHaveText('Seeded Chat (fork)')
|
||||
await expect(page.locator('.chat-message-user')).toHaveCount(1)
|
||||
await expect(page.locator('.chat-message-assistant')).toHaveCount(1)
|
||||
await expect(page.locator('.chat-message-assistant')).toContainText(['first answer'])
|
||||
})
|
||||
@@ -72,6 +72,7 @@
|
||||
"actions": {
|
||||
"copy": "Copy",
|
||||
"regenerate": "Regenerate",
|
||||
"branch": "Branch from here",
|
||||
"jumpToLatest": "Jump to latest"
|
||||
},
|
||||
"streaming": {
|
||||
@@ -100,7 +101,9 @@
|
||||
"toasts": {
|
||||
"selectModel": "Please select a model",
|
||||
"copied": "Copied to clipboard",
|
||||
"copyFailed": "Could not copy to clipboard"
|
||||
"copyFailed": "Could not copy to clipboard",
|
||||
"chatCopied": "Chat copied to clipboard",
|
||||
"forked": "Created a new chat"
|
||||
},
|
||||
"menu": {
|
||||
"trigger": "Chats",
|
||||
@@ -110,6 +113,8 @@
|
||||
"noMatch": "No conversations match your search",
|
||||
"noConversations": "No conversations yet",
|
||||
"rename": "Rename",
|
||||
"duplicate": "Duplicate chat",
|
||||
"copyChat": "Copy chat",
|
||||
"exportMarkdown": "Export as Markdown",
|
||||
"deleteChat": "Delete chat",
|
||||
"newChat": "New chat",
|
||||
|
||||
@@ -24,6 +24,8 @@ const ChatsMenu = forwardRef(function ChatsMenu({
|
||||
onDeleteAll,
|
||||
onRename,
|
||||
onExport,
|
||||
onCopyChat,
|
||||
onDuplicate,
|
||||
}, ref) {
|
||||
const { t } = useTranslation('chat')
|
||||
const [open, setOpen] = useState(false)
|
||||
@@ -230,6 +232,24 @@ const ChatsMenu = forwardRef(function ChatsMenu({
|
||||
>
|
||||
<i className="fas fa-pen" />
|
||||
</button>
|
||||
{onDuplicate && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => { e.stopPropagation(); onDuplicate(chat); setOpen(false) }}
|
||||
title={t('menu.duplicate')}
|
||||
>
|
||||
<i className="fas fa-clone" />
|
||||
</button>
|
||||
)}
|
||||
{(chat.history?.length || 0) > 0 && onCopyChat && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => { e.stopPropagation(); onCopyChat(chat) }}
|
||||
title={t('menu.copyChat')}
|
||||
>
|
||||
<i className="fas fa-clipboard" />
|
||||
</button>
|
||||
)}
|
||||
{(chat.history?.length || 0) > 0 && onExport && (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
27
core/http/react-ui/src/hooks/useChat.js
vendored
27
core/http/react-ui/src/hooks/useChat.js
vendored
@@ -141,6 +141,24 @@ export function useChat(initialModel = '') {
|
||||
return chat
|
||||
}, [])
|
||||
|
||||
const forkChat = useCallback((chatId, uptoIndex) => {
|
||||
const src = chats.find(c => c.id === chatId)
|
||||
if (!src) return null
|
||||
const end = typeof uptoIndex === 'number' ? uptoIndex : src.history.length
|
||||
const forked = {
|
||||
...src,
|
||||
id: generateId(),
|
||||
name: `${src.name} (fork)`,
|
||||
history: structuredClone(src.history.slice(0, end)),
|
||||
tokenUsage: { prompt: 0, completion: 0, total: 0 },
|
||||
createdAt: Date.now(),
|
||||
updatedAt: Date.now(),
|
||||
}
|
||||
setChats(prev => [forked, ...prev])
|
||||
setActiveChatId(forked.id)
|
||||
return forked
|
||||
}, [chats])
|
||||
|
||||
const switchChat = useCallback((chatId) => {
|
||||
setActiveChatId(chatId)
|
||||
setStreamingContent('')
|
||||
@@ -260,8 +278,12 @@ export function useChat(initialModel = '') {
|
||||
if (chat?.systemPrompt) {
|
||||
messages.push({ role: 'system', content: chat.systemPrompt })
|
||||
}
|
||||
// Filter out thinking/reasoning/tool_call/tool_result messages
|
||||
const historyForApi = (chat?.history || []).filter(m =>
|
||||
// Filter out thinking/reasoning/tool_call/tool_result messages.
|
||||
// options.baseHistory lets callers (e.g. mid-conversation retry) pass the
|
||||
// intended truncated history synchronously; the closure `chat` still holds
|
||||
// the stale pre-truncation state because setChats only schedules an update.
|
||||
const baseHistory = options.baseHistory || chat?.history || []
|
||||
const historyForApi = baseHistory.filter(m =>
|
||||
m.role !== 'thinking' && m.role !== 'reasoning' && m.role !== 'tool_call' && m.role !== 'tool_result'
|
||||
)
|
||||
messages.push(...historyForApi, { role: 'user', content: messageContent })
|
||||
@@ -793,6 +815,7 @@ export function useChat(initialModel = '') {
|
||||
tokensPerSecond,
|
||||
maxTokensPerSecond,
|
||||
addChat,
|
||||
forkChat,
|
||||
switchChat,
|
||||
deleteChat,
|
||||
deleteAllChats,
|
||||
|
||||
@@ -33,7 +33,7 @@ function getLastMessagePreview(chat) {
|
||||
return ''
|
||||
}
|
||||
|
||||
function exportChatAsMarkdown(chat) {
|
||||
function serializeChatAsMarkdown(chat) {
|
||||
let md = `# ${chat.name}\n\n`
|
||||
md += `Model: ${chat.model || 'Unknown'}\n`
|
||||
md += `Date: ${new Date(chat.createdAt).toLocaleString()}\n\n---\n\n`
|
||||
@@ -47,7 +47,11 @@ function exportChatAsMarkdown(chat) {
|
||||
md += `<details><summary>Thinking</summary>\n\n${msg.content}\n\n</details>\n\n`
|
||||
}
|
||||
}
|
||||
const blob = new Blob([md], { type: 'text/markdown' })
|
||||
return md
|
||||
}
|
||||
|
||||
function downloadChatAsMarkdown(chat) {
|
||||
const blob = new Blob([serializeChatAsMarkdown(chat)], { type: 'text/markdown' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
@@ -294,7 +298,7 @@ export default function Chat() {
|
||||
const {
|
||||
chats, activeChat, activeChatId, isStreaming, streamingChatId, streamingContent,
|
||||
streamingReasoning, streamingToolCalls, tokensPerSecond, maxTokensPerSecond,
|
||||
addChat, switchChat, deleteChat, deleteAllChats, renameChat, updateChatSettings,
|
||||
addChat, forkChat, switchChat, deleteChat, deleteAllChats, renameChat, updateChatSettings,
|
||||
sendMessage, stopGeneration, clearHistory, getContextUsagePercent, addMessage,
|
||||
} = useChat(urlModel || '')
|
||||
|
||||
@@ -795,34 +799,27 @@ export default function Chat() {
|
||||
await sendMessage(msg, files, mcpOptions)
|
||||
}, [input, files, activeChat, sendMessage, addToast, getToolsForLLM, isClientTool, executeTool, hasAppUI, getAppResource, getToolDefinition])
|
||||
|
||||
const handleRegenerate = useCallback(async () => {
|
||||
const handleRegenerate = useCallback(async (targetIndex) => {
|
||||
if (!activeChat || isStreaming) return
|
||||
const history = activeChat.history
|
||||
let lastUserMsg = null
|
||||
let lastUserFiles = null
|
||||
for (let i = history.length - 1; i >= 0; i--) {
|
||||
if (history[i].role === 'user') {
|
||||
lastUserMsg = typeof history[i].content === 'string' ? history[i].content : history[i].content?.[0]?.text || ''
|
||||
lastUserFiles = history[i].files || []
|
||||
break
|
||||
}
|
||||
const end = typeof targetIndex === 'number' ? targetIndex : history.length
|
||||
// Nearest user message at or before the target answer.
|
||||
let userIdx = -1
|
||||
for (let i = Math.min(end, history.length) - 1; i >= 0; i--) {
|
||||
if (history[i].role === 'user') { userIdx = i; break }
|
||||
}
|
||||
if (!lastUserMsg) return
|
||||
|
||||
// Remove everything after and including the last user message
|
||||
const newHistory = []
|
||||
let foundLastUser = false
|
||||
for (let i = history.length - 1; i >= 0; i--) {
|
||||
if (!foundLastUser && history[i].role === 'user') {
|
||||
foundLastUser = true
|
||||
continue
|
||||
}
|
||||
if (foundLastUser) {
|
||||
newHistory.unshift(history[i])
|
||||
}
|
||||
}
|
||||
updateChatSettings(activeChat.id, { history: newHistory })
|
||||
await sendMessage(lastUserMsg, lastUserFiles)
|
||||
if (userIdx === -1) return
|
||||
const userMsg = typeof history[userIdx].content === 'string'
|
||||
? history[userIdx].content
|
||||
: history[userIdx].content?.[0]?.text || ''
|
||||
const userFiles = history[userIdx].files || []
|
||||
// Drop the user turn and everything after it; sendMessage re-appends it.
|
||||
// Thread the truncated history through explicitly: updateChatSettings only
|
||||
// schedules a state update, so sendMessage's closure would otherwise read
|
||||
// the stale pre-truncation history for the outbound API payload.
|
||||
const baseHistory = history.slice(0, userIdx)
|
||||
updateChatSettings(activeChat.id, { history: baseHistory })
|
||||
await sendMessage(userMsg, userFiles, { baseHistory })
|
||||
}, [activeChat, isStreaming, sendMessage, updateChatSettings])
|
||||
|
||||
const handleKeyDown = (e) => {
|
||||
@@ -852,6 +849,11 @@ export default function Chat() {
|
||||
}
|
||||
}
|
||||
|
||||
const copyChatAsMarkdown = async (chat) => {
|
||||
const ok = await copyToClipboard(serializeChatAsMarkdown(chat))
|
||||
addToast(ok ? t('toasts.chatCopied') : t('toasts.copyFailed'), ok ? 'success' : 'error', ok ? 2000 : 3000)
|
||||
}
|
||||
|
||||
const contextPercent = getContextUsagePercent()
|
||||
|
||||
// Recent chats for the empty state — exclude the current chat and any
|
||||
@@ -892,7 +894,9 @@ export default function Chat() {
|
||||
onDelete={deleteChat}
|
||||
onDeleteAll={promptDeleteAll}
|
||||
onRename={renameChat}
|
||||
onExport={(chat) => exportChatAsMarkdown(chat)}
|
||||
onExport={(chat) => downloadChatAsMarkdown(chat)}
|
||||
onCopyChat={(chat) => copyChatAsMarkdown(chat)}
|
||||
onDuplicate={(chat) => { if (forkChat(chat.id)) addToast(t('toasts.forked'), 'success', 2000) }}
|
||||
/>
|
||||
{activeChat.localaiAssistant && (
|
||||
<span
|
||||
@@ -1184,11 +1188,19 @@ export default function Chat() {
|
||||
<button onClick={() => copyMessage(msg.content)} title={t('actions.copy')}>
|
||||
<i className="fas fa-copy" />
|
||||
</button>
|
||||
{msg.role === 'assistant' && i === activeChat.history.length - 1 && !isStreaming && (
|
||||
<button onClick={handleRegenerate} title={t('actions.regenerate')}>
|
||||
{msg.role === 'assistant' && !isStreaming && (
|
||||
<button onClick={() => handleRegenerate(i)} title={t('actions.regenerate')}>
|
||||
<i className="fas fa-rotate" />
|
||||
</button>
|
||||
)}
|
||||
{msg.role === 'assistant' && !isStreaming && (
|
||||
<button
|
||||
onClick={() => { forkChat(activeChat.id, i + 1); addToast(t('toasts.forked'), 'success', 2000) }}
|
||||
title={t('actions.branch')}
|
||||
>
|
||||
<i className="fas fa-code-branch" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -146,6 +146,7 @@ export default function Manage() {
|
||||
const [distributedMode, setDistributedMode] = useState(false)
|
||||
const [togglingModels, setTogglingModels] = useState(new Set())
|
||||
const [pinningModels, setPinningModels] = useState(new Set())
|
||||
const [loadingModels, setLoadingModels] = useState(new Set())
|
||||
// Expanded row state — keyed by `${tab}:${id}` so switching tabs doesn't
|
||||
// collide and a single row is open at a time per tab.
|
||||
const [expandedKey, setExpandedKey] = useState(null)
|
||||
@@ -313,6 +314,26 @@ export default function Manage() {
|
||||
})
|
||||
}
|
||||
|
||||
// Pre-load a model (or all of a realtime pipeline's sub-models) into memory.
|
||||
// The /backend/load call blocks until loading finishes, so the menu item shows
|
||||
// a loading state while in flight and reports the outcome on completion.
|
||||
const handleLoadModel = async (modelName) => {
|
||||
setLoadingModels(prev => new Set(prev).add(modelName))
|
||||
try {
|
||||
await backendControlApi.load({ model: modelName })
|
||||
addToast(`Loaded ${modelName}`, 'success')
|
||||
setTimeout(fetchLoadedModels, 500)
|
||||
} catch (err) {
|
||||
addToast(`Failed to load: ${err.message}`, 'error')
|
||||
} finally {
|
||||
setLoadingModels(prev => {
|
||||
const next = new Set(prev)
|
||||
next.delete(modelName)
|
||||
return next
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const handleDeleteModel = (modelName) => {
|
||||
setConfirmDialog({
|
||||
title: 'Delete Model',
|
||||
@@ -687,6 +708,11 @@ export default function Manage() {
|
||||
label: model.disabled ? 'Enable model' : 'Disable model',
|
||||
onClick: () => handleToggleModel(model.id, model.disabled),
|
||||
disabled: togglingModels.has(model.id) },
|
||||
{ key: 'load', icon: 'fa-bolt',
|
||||
label: loadingModels.has(model.id) ? 'Loading…' : 'Load into memory',
|
||||
onClick: () => handleLoadModel(model.id),
|
||||
hidden: isRunning || !!model.disabled,
|
||||
disabled: loadingModels.has(model.id) },
|
||||
{ key: 'stop', icon: 'fa-stop', label: 'Stop model',
|
||||
onClick: () => handleStopModel(model.id), hidden: !isRunning },
|
||||
{ key: 'pin', icon: 'fa-thumbtack',
|
||||
|
||||
3
core/http/react-ui/src/utils/api.js
vendored
3
core/http/react-ui/src/utils/api.js
vendored
@@ -352,6 +352,9 @@ export const realtimeApi = {
|
||||
// Backend control
|
||||
export const backendControlApi = {
|
||||
shutdown: (body) => postJSON(API_CONFIG.endpoints.backendShutdown, body),
|
||||
// Pre-load a model (or all of a realtime pipeline's sub-models) into memory.
|
||||
// body: { model: "<name>" }. Inverse of shutdown.
|
||||
load: (body) => postJSON(API_CONFIG.endpoints.backendLoad, body),
|
||||
}
|
||||
|
||||
// System info
|
||||
|
||||
1
core/http/react-ui/src/utils/config.js
vendored
1
core/http/react-ui/src/utils/config.js
vendored
@@ -106,6 +106,7 @@ export const API_CONFIG = {
|
||||
video: '/video',
|
||||
backendMonitor: '/backend/monitor',
|
||||
backendShutdown: '/backend/shutdown',
|
||||
backendLoad: '/backend/load',
|
||||
modelsApply: '/models/apply',
|
||||
modelsDelete: (name) => `/models/delete/${name}`,
|
||||
modelsAvailable: '/models/available',
|
||||
|
||||
@@ -207,9 +207,14 @@ func RegisterLocalAIRoutes(router *echo.Echo,
|
||||
backendMonitorService := monitoring.NewBackendMonitorService(ml, cl, appConfig) // Split out for now
|
||||
router.GET("/backend/monitor", localai.BackendMonitorEndpoint(backendMonitorService), adminMiddleware)
|
||||
router.POST("/backend/shutdown", localai.BackendShutdownEndpoint(backendMonitorService), adminMiddleware)
|
||||
// /backend/load is the inverse of /backend/shutdown: pre-load a model (or all
|
||||
// of a realtime pipeline's sub-models) into memory so clients can drive
|
||||
// warm-up explicitly instead of paying the cold-start cost on first use.
|
||||
router.POST("/backend/load", localai.LoadModelEndpoint(cl, ml, appConfig), adminMiddleware)
|
||||
// The v1/* urls are exactly the same as above - makes local e2e testing easier if they are registered.
|
||||
router.GET("/v1/backend/monitor", localai.BackendMonitorEndpoint(backendMonitorService), adminMiddleware)
|
||||
router.POST("/v1/backend/shutdown", localai.BackendShutdownEndpoint(backendMonitorService), adminMiddleware)
|
||||
router.POST("/v1/backend/load", localai.LoadModelEndpoint(cl, ml, appConfig), adminMiddleware)
|
||||
|
||||
// Traces and backend logs (monitoring)
|
||||
router.GET("/api/traces", localai.GetAPITracesEndpoint(), adminMiddleware)
|
||||
@@ -245,6 +250,7 @@ func RegisterLocalAIRoutes(router *echo.Echo,
|
||||
"metrics": "/metrics",
|
||||
"backend_monitor": "/backend/monitor",
|
||||
"backend_shutdown": "/backend/shutdown",
|
||||
"backend_load": "/backend/load",
|
||||
"system": "/system",
|
||||
"version": "/version",
|
||||
"traces": "/api/traces",
|
||||
|
||||
@@ -11,6 +11,24 @@ type BackendMonitorRequest struct {
|
||||
BasicModelRequest
|
||||
}
|
||||
|
||||
// ModelLoadRequest asks LocalAI to pre-load a model into memory by name, so the
|
||||
// first request that uses it pays no cold-start load cost. For a realtime
|
||||
// pipeline model, every configured sub-model (VAD, transcription, LLM, TTS,
|
||||
// sound_detection, voice_recognition) is loaded instead of the pipeline stub.
|
||||
// It is the inverse of the /backend/shutdown request.
|
||||
type ModelLoadRequest struct {
|
||||
BasicModelRequest
|
||||
}
|
||||
|
||||
// ModelLoadResponse reports the outcome of a /backend/load call.
|
||||
type ModelLoadResponse struct {
|
||||
// Loaded lists the model names actually resident in memory after the call.
|
||||
// For a pipeline model these are its sub-models, not the pipeline name.
|
||||
Loaded []string `json:"loaded"`
|
||||
// Message is a short human-readable status ("model loaded", or an error).
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type TokenMetricsRequest struct {
|
||||
BasicModelRequest
|
||||
}
|
||||
|
||||
@@ -14,6 +14,16 @@ import (
|
||||
// MaxSnippetSeconds is the maximum number of seconds of audio captured per trace.
|
||||
const MaxSnippetSeconds = 30
|
||||
|
||||
// silenceFloorDBFS is the dBFS value reported for digital silence (RMS or peak
|
||||
// of zero). The true level is -∞ dBFS; reporting a finite floor keeps the
|
||||
// metric present and meaningful in the Traces UI (a scrubbed nil would read as
|
||||
// "missing" rather than "silent"). -120 dBFS sits well below 16-bit PCM's
|
||||
// ~-90 dBFS least-significant-bit floor, so it reads unambiguously as
|
||||
// "effectively silent". JSON-marshal safety for any non-finite float that does
|
||||
// reach a trace is owned centrally by RecordBackendTrace's sanitizer — this
|
||||
// floor is about presentation, not transport.
|
||||
const silenceFloorDBFS = -120.0
|
||||
|
||||
// AudioSnippet captures the first MaxSnippetSeconds of a WAV file and computes
|
||||
// quality metrics. The result is a map suitable for merging into a BackendTrace
|
||||
// Data field. maxBytes caps the embedded base64 waveform so a single TTS or
|
||||
@@ -63,7 +73,7 @@ func AudioSnippetFromPCM(pcm []byte, sampleRate, totalPCMBytes, maxBytes int) ma
|
||||
snippetDuration := float64(len(samples)) / float64(sampleRate)
|
||||
|
||||
rms := sound.CalculateRMS16(samples)
|
||||
rmsDBFS := -math.Inf(1)
|
||||
rmsDBFS := silenceFloorDBFS
|
||||
if rms > 0 {
|
||||
rmsDBFS = 20 * math.Log10(rms/32768.0)
|
||||
}
|
||||
@@ -78,7 +88,7 @@ func AudioSnippetFromPCM(pcm []byte, sampleRate, totalPCMBytes, maxBytes int) ma
|
||||
}
|
||||
dcSum += int64(s)
|
||||
}
|
||||
peakDBFS := -math.Inf(1)
|
||||
peakDBFS := silenceFloorDBFS
|
||||
if peak > 0 {
|
||||
peakDBFS = 20 * math.Log10(float64(peak)/32768.0)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package trace_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
@@ -47,3 +50,32 @@ var _ = Describe("AudioSnippetFromPCM byte cap", func() {
|
||||
Expect(out).To(HaveKey("audio_wav_base64"))
|
||||
})
|
||||
})
|
||||
|
||||
// Silent audio (RMS/peak of zero) has a true level of -∞ dBFS, but emitting
|
||||
// -Inf made the whole /api/backend-traces response fail to JSON-marshal and
|
||||
// blanked the Traces UI. The metrics must instead be finite and serializable.
|
||||
var _ = Describe("AudioSnippetFromPCM silent audio dBFS", func() {
|
||||
pcm := makePCM(snippetSeconds, snippetSampleRate) // all zeros == digital silence
|
||||
totalPCM := len(pcm)
|
||||
|
||||
It("reports finite dBFS for silence instead of -Inf", func() {
|
||||
out := trace.AudioSnippetFromPCM(pcm, snippetSampleRate, totalPCM, 0)
|
||||
|
||||
rms, ok := out["audio_rms_dbfs"].(float64)
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(math.IsInf(rms, 0)).To(BeFalse(), "silent RMS must not be ±Inf")
|
||||
Expect(math.IsNaN(rms)).To(BeFalse())
|
||||
|
||||
peak, ok := out["audio_peak_dbfs"].(float64)
|
||||
Expect(ok).To(BeTrue())
|
||||
Expect(math.IsInf(peak, 0)).To(BeFalse(), "silent peak must not be ±Inf")
|
||||
Expect(math.IsNaN(peak)).To(BeFalse())
|
||||
})
|
||||
|
||||
It("produces a snippet that round-trips through encoding/json", func() {
|
||||
out := trace.AudioSnippetFromPCM(pcm, snippetSampleRate, totalPCM, 0)
|
||||
|
||||
_, err := json.Marshal(out)
|
||||
Expect(err).ToNot(HaveOccurred(), "silent-audio metrics must be JSON-marshalable")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,6 +3,8 @@ package trace
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"maps"
|
||||
"math"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -116,8 +118,13 @@ func RecordBackendTrace(t BackendTrace) {
|
||||
backendMu.Lock()
|
||||
maxBody := backendMaxBodyBytes
|
||||
backendMu.Unlock()
|
||||
if t.Data != nil && maxBody > 0 {
|
||||
t.Data = capDataStrings(t.Data, maxBody)
|
||||
// Always walk Data, even with no body cap configured: besides capping
|
||||
// oversized strings (maxBody > 0), the walk replaces non-finite floats
|
||||
// (Inf/NaN) that encoding/json cannot marshal. A single such value — e.g. a
|
||||
// -Inf dBFS audio metric from a silent clip — would otherwise fail the whole
|
||||
// /api/backend-traces response and blank the Traces UI.
|
||||
if t.Data != nil {
|
||||
t.Data = sanitizeData(t.Data, maxBody)
|
||||
}
|
||||
select {
|
||||
case backendLogChan <- &t:
|
||||
@@ -126,32 +133,90 @@ func RecordBackendTrace(t BackendTrace) {
|
||||
}
|
||||
}
|
||||
|
||||
// capDataStrings walks a trace Data map and replaces any string value (at any
|
||||
// depth) that exceeds maxBytes with a fixed-size marker that names the
|
||||
// original byte count. The replacement is intentionally short and not valid
|
||||
// base64/JSON: the goal is to flag "this was dropped" cheaply, not to keep a
|
||||
// partial value that the UI might try to render. Non-string scalars and
|
||||
// non-map containers pass through untouched so structural fields like
|
||||
// total_deltas or audio_sample_rate remain useful.
|
||||
func capDataStrings(data map[string]any, maxBytes int) map[string]any {
|
||||
out := make(map[string]any, len(data))
|
||||
for k, v := range data {
|
||||
out[k] = capValue(v, maxBytes)
|
||||
}
|
||||
// sanitizeData walks a trace Data map (recursing into nested maps and slices)
|
||||
// and makes every value safe for the /api/backend-traces JSON response:
|
||||
//
|
||||
// - When maxBytes > 0, any string longer than maxBytes is replaced with a
|
||||
// fixed-size marker that names the original byte count. The replacement is
|
||||
// intentionally short and not valid base64/JSON: it flags "this was dropped"
|
||||
// cheaply rather than keeping a partial value the UI might try to render.
|
||||
// - Non-finite floats (Inf/NaN) are replaced with nil regardless of maxBytes,
|
||||
// because encoding/json refuses to marshal them and one bad value would fail
|
||||
// the entire response.
|
||||
//
|
||||
// Other scalars (ints, bools, finite floats) pass through untouched so
|
||||
// structural fields like total_deltas or audio_sample_rate remain useful.
|
||||
//
|
||||
// The walk is copy-on-write: it runs on every RecordBackendTrace call, and in
|
||||
// the common case nothing needs rewriting, so containers are only re-allocated
|
||||
// on the paths that actually changed and untouched values keep their original
|
||||
// interface boxes instead of paying a per-value re-boxing allocation.
|
||||
func sanitizeData(data map[string]any, maxBytes int) map[string]any {
|
||||
out, _ := sanitizeMap(data, maxBytes)
|
||||
return out
|
||||
}
|
||||
|
||||
func capValue(v any, maxBytes int) any {
|
||||
func sanitizeMap(m map[string]any, maxBytes int) (map[string]any, bool) {
|
||||
var out map[string]any
|
||||
for k, v := range m {
|
||||
nv, changed := sanitizeValue(v, maxBytes)
|
||||
if changed && out == nil {
|
||||
// First change: fork the map. Entries already visited were
|
||||
// unchanged, so a full copy then overwriting as we go is exact.
|
||||
out = make(map[string]any, len(m))
|
||||
maps.Copy(out, m)
|
||||
}
|
||||
if out != nil {
|
||||
out[k] = nv
|
||||
}
|
||||
}
|
||||
if out == nil {
|
||||
return m, false
|
||||
}
|
||||
return out, true
|
||||
}
|
||||
|
||||
func sanitizeSlice(s []any, maxBytes int) ([]any, bool) {
|
||||
var out []any
|
||||
for i, v := range s {
|
||||
nv, changed := sanitizeValue(v, maxBytes)
|
||||
if changed && out == nil {
|
||||
out = make([]any, len(s))
|
||||
copy(out, s)
|
||||
}
|
||||
if out != nil {
|
||||
out[i] = nv
|
||||
}
|
||||
}
|
||||
if out == nil {
|
||||
return s, false
|
||||
}
|
||||
return out, true
|
||||
}
|
||||
|
||||
func sanitizeValue(v any, maxBytes int) (any, bool) {
|
||||
switch val := v.(type) {
|
||||
case string:
|
||||
if len(val) > maxBytes {
|
||||
return fmt.Sprintf("<truncated: %d bytes>", len(val))
|
||||
if maxBytes > 0 && len(val) > maxBytes {
|
||||
return fmt.Sprintf("<truncated: %d bytes>", len(val)), true
|
||||
}
|
||||
return val
|
||||
return v, false
|
||||
case float64:
|
||||
if math.IsInf(val, 0) || math.IsNaN(val) {
|
||||
return nil, true
|
||||
}
|
||||
return v, false
|
||||
case float32:
|
||||
if f := float64(val); math.IsInf(f, 0) || math.IsNaN(f) {
|
||||
return nil, true
|
||||
}
|
||||
return v, false
|
||||
case map[string]any:
|
||||
return capDataStrings(val, maxBytes)
|
||||
return sanitizeMap(val, maxBytes)
|
||||
case []any:
|
||||
return sanitizeSlice(val, maxBytes)
|
||||
default:
|
||||
return v
|
||||
return v, false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
80
core/trace/backend_trace_sanitize_test.go
Normal file
80
core/trace/backend_trace_sanitize_test.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package trace_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/mudler/LocalAI/core/trace"
|
||||
)
|
||||
|
||||
// encoding/json cannot marshal ±Inf or NaN. The /api/backend-traces endpoint
|
||||
// serializes the whole buffer with one json call, so a single non-finite float
|
||||
// in any trace's Data map (e.g. a -Inf dBFS audio metric from a silent clip)
|
||||
// would fail the entire response and blank the Traces UI. RecordBackendTrace
|
||||
// must scrub those values regardless of whether a body cap is configured.
|
||||
var _ = Describe("RecordBackendTrace non-finite float sanitization", func() {
|
||||
BeforeEach(func() {
|
||||
// maxBodyBytes 0 == no body cap: float sanitization must still run.
|
||||
trace.InitBackendTracingIfEnabled(64, 0)
|
||||
trace.ClearBackendTraces()
|
||||
})
|
||||
|
||||
It("replaces ±Inf and NaN with nil so the response stays JSON-marshalable", func() {
|
||||
trace.RecordBackendTrace(trace.BackendTrace{
|
||||
Timestamp: time.Now(),
|
||||
Type: trace.BackendTraceTranscription,
|
||||
ModelName: "m",
|
||||
Data: map[string]any{
|
||||
"audio_rms_dbfs": math.Inf(-1),
|
||||
"audio_peak_dbfs": math.Inf(1),
|
||||
"weird": math.NaN(),
|
||||
"audio_duration_s": 1.5, // finite siblings must survive
|
||||
},
|
||||
})
|
||||
|
||||
Eventually(trace.GetBackendTraces).Should(HaveLen(1))
|
||||
got := trace.GetBackendTraces()[0]
|
||||
|
||||
Expect(got.Data["audio_rms_dbfs"]).To(BeNil())
|
||||
Expect(got.Data["audio_peak_dbfs"]).To(BeNil())
|
||||
Expect(got.Data["weird"]).To(BeNil())
|
||||
Expect(got.Data["audio_duration_s"]).To(Equal(1.5), "finite floats must pass through untouched")
|
||||
|
||||
_, err := json.Marshal(trace.GetBackendTraces())
|
||||
Expect(err).ToNot(HaveOccurred(), "the whole trace buffer must marshal even with non-finite inputs")
|
||||
})
|
||||
|
||||
It("scrubs non-finite floats nested in maps and slices", func() {
|
||||
trace.RecordBackendTrace(trace.BackendTrace{
|
||||
Timestamp: time.Now(),
|
||||
Type: trace.BackendTraceLLM,
|
||||
ModelName: "m",
|
||||
Data: map[string]any{
|
||||
"nested": map[string]any{
|
||||
"logprob": math.Inf(-1),
|
||||
"ok": 0.25,
|
||||
},
|
||||
"scores": []any{1.0, math.Inf(1), math.NaN()},
|
||||
},
|
||||
})
|
||||
|
||||
Eventually(trace.GetBackendTraces).Should(HaveLen(1))
|
||||
got := trace.GetBackendTraces()[0]
|
||||
|
||||
nested := got.Data["nested"].(map[string]any)
|
||||
Expect(nested["logprob"]).To(BeNil())
|
||||
Expect(nested["ok"]).To(Equal(0.25))
|
||||
|
||||
scores := got.Data["scores"].([]any)
|
||||
Expect(scores[0]).To(Equal(1.0))
|
||||
Expect(scores[1]).To(BeNil())
|
||||
Expect(scores[2]).To(BeNil())
|
||||
|
||||
_, err := json.Marshal(trace.GetBackendTraces())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
@@ -381,6 +381,8 @@ curl -X POST http://localhost:8080/backend/shutdown \
|
||||
|
||||
To stop all models, you'll need to call the endpoint for each loaded model individually, or use the web UI to stop all models at once.
|
||||
|
||||
Conversely, you can pre-load a model into memory ahead of its first request with `POST /backend/load` (the inverse of shutdown) — see [Backend Monitor]({{%relref "features/backend-monitor" %}}).
|
||||
|
||||
### Best Practices
|
||||
|
||||
1. **Monitor VRAM usage**: Use `nvidia-smi` (for NVIDIA GPUs) or similar tools to monitor actual VRAM usage
|
||||
|
||||
@@ -166,7 +166,7 @@ When authentication is enabled, the following endpoints require admin role:
|
||||
- `GET /api/backend-traces`, `POST /api/backend-traces/clear`
|
||||
- `GET /api/backend-logs/*`, `POST /api/backend-logs/*/clear`
|
||||
- `GET /api/resources`, `GET /api/settings`, `POST /api/settings`
|
||||
- `GET /system`, `GET /backend/monitor`, `POST /backend/shutdown`
|
||||
- `GET /system`, `GET /backend/monitor`, `POST /backend/shutdown`, `POST /backend/load`
|
||||
|
||||
**P2P:**
|
||||
- `GET /api/p2p/*`
|
||||
|
||||
@@ -5,7 +5,9 @@ weight = 20
|
||||
url = "/features/backend-monitor/"
|
||||
+++
|
||||
|
||||
LocalAI provides endpoints to monitor and manage running backends. The `/backend/monitor` endpoint reports the status and resource usage of loaded models, and `/backend/shutdown` allows stopping a model's backend process.
|
||||
LocalAI provides endpoints to monitor and manage running backends. The `/backend/monitor` endpoint reports the status and resource usage of loaded models, `/backend/load` pre-loads a model into memory, and `/backend/shutdown` allows stopping a model's backend process.
|
||||
|
||||
All three are admin-only.
|
||||
|
||||
## Monitor API
|
||||
|
||||
@@ -62,6 +64,42 @@ curl "http://localhost:8080/backend/monitor?model=my-model"
|
||||
}
|
||||
```
|
||||
|
||||
## Load API
|
||||
|
||||
Pre-loads a model into memory ahead of its first request, so that request pays no cold-start load cost. It is the inverse of the Shutdown API and works for any model, not just realtime pipelines.
|
||||
|
||||
- **Method:** `POST`
|
||||
- **Endpoints:** `/backend/load`, `/v1/backend/load`
|
||||
|
||||
### Request
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|----------|----------|------------------------------|
|
||||
| `model` | `string` | Yes | Name of the model to load |
|
||||
|
||||
### Behavior
|
||||
|
||||
- For a regular model, its own backend is loaded.
|
||||
- For a **realtime pipeline** model (a config with a `pipeline:` block), every configured sub-model (VAD, transcription, LLM, TTS, sound_detection, voice_recognition) is loaded concurrently instead of the pipeline stub, which has no backend of its own.
|
||||
|
||||
The call blocks until loading finishes and reports which model names became resident, so partial failures are visible.
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/backend/load \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model": "my-model"}'
|
||||
```
|
||||
|
||||
### Example response
|
||||
|
||||
```json
|
||||
{ "loaded": ["my-model"], "message": "model loaded" }
|
||||
```
|
||||
|
||||
On failure the call returns `500` with `loaded` listing whichever sub-models did load and `message` naming the failures.
|
||||
|
||||
## Shutdown API
|
||||
|
||||
- **Method:** `POST`
|
||||
|
||||
@@ -56,6 +56,39 @@ pipeline:
|
||||
|
||||
All streaming flags are off by default, so existing pipelines are unaffected.
|
||||
|
||||
### Model warm-up (cold start)
|
||||
|
||||
Without warm-up the pipeline's models are loaded into memory only on first use *within* a session: the VAD on the first audio chunk, transcription at the first end-of-speech, the LLM on the first reply, and TTS on the first spoken output. On a cold session this staggers a load delay across those first few interactions — and a model that fails to load (missing weights, wrong backend, out of memory) only fails part-way through the first turn.
|
||||
|
||||
To avoid that, LocalAI **warms the pipeline by default**: it loads the VAD, transcription, LLM and TTS backends into memory *before* the session is announced, and the session start **blocks until they are all ready**. The loads run concurrently, so the wait is the slowest single model, not the sum. This means:
|
||||
|
||||
- The first turn pays no cold-start cost — every backend is already resident.
|
||||
- **Model-load errors surface at session start.** If any stage fails to load, the session is not started and the client receives a `model_load_error` instead of `session.created`, so a broken pipeline fails fast and visibly rather than mid-call.
|
||||
|
||||
Set `disable_warmup: true` to restore the lazy "load on first use" behavior — session start no longer waits on loading and load errors surface on the first turn instead. Useful if you want idle sessions to avoid holding model memory they may never use:
|
||||
|
||||
```yaml
|
||||
name: gpt-realtime
|
||||
pipeline:
|
||||
vad: silero-vad-ggml
|
||||
transcription: whisper-large-turbo
|
||||
llm: qwen3-4b
|
||||
tts: tts-1
|
||||
disable_warmup: true # lazily load each model on first use instead of at session start
|
||||
```
|
||||
|
||||
#### Pre-loading a pipeline on demand
|
||||
|
||||
Warm-up only fires when a realtime session opens. To load a pipeline into memory ahead of time — e.g. to warm it right after boot, or when running with `disable_warmup: true` — POST the model name to the admin-only `/backend/load` endpoint. For a pipeline model it loads every configured sub-model (VAD, transcription, LLM, TTS, sound_detection, voice_recognition) concurrently:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/backend/load \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model": "gpt-realtime"}'
|
||||
```
|
||||
|
||||
The endpoint is not realtime-specific — it pre-loads any model. See [Backend Monitor]({{%relref "features/backend-monitor" %}}) for the full request/response reference (it is the inverse of `/backend/shutdown`).
|
||||
|
||||
### Turn detection
|
||||
|
||||
Turn detection decides when the user has finished speaking and the pipeline should respond. Two modes are supported, matching the OpenAI session schema:
|
||||
|
||||
@@ -1,4 +1,56 @@
|
||||
---
|
||||
- name: "qwopus3.6-35b-a3b-coder-mtp"
|
||||
url: "github:mudler/LocalAI/gallery/virtual.yaml@master"
|
||||
urls:
|
||||
- https://huggingface.co/Jackrong/Qwopus3.6-35B-A3B-Coder-MTP-GGUF
|
||||
description: |
|
||||
# 🌟 Qwopus3.6-35B-A3B-v1
|
||||
|
||||
## 💡 Base Model Overview
|
||||
|
||||
**Qwen3.6-35B-A3B** is an advanced hybrid sparse MoE (Mixture-of-Experts) model developed by Alibaba Cloud. It features 35B total parameters with only 3B active parameters per token, ensuring high inference efficiency. Architecturally, it combines Gated DeltaNet linear attention with standard gated attention layers, routing tokens across **256 experts**. It natively supports a massive **262k context window** and is specifically designed for high-performance agentic coding, deep reasoning, and multimodal tasks.
|
||||
|
||||
## 🚀 Model Refinement & Logic Tuning (Qwopus3.6-35B-A3B-v1)
|
||||
|
||||
🪐**Qwopus3.6-35B-A3B-v1** is a reasoning-enhanced MoE (Mixture of Experts) model fine-tuned on top of **Qwen3.6-35B-A3B**.
|
||||
|
||||
### 🛠 Training Strategy
|
||||
|
||||
The fine-tuning process for this model is structured into **three distinct stages of distributed SFT (Supervised Fine-Tuning)**, progressively scaling reasoning complexity and data diversity. This systematic approach ensures the model inherits the base MoE capabilities while sharpening its logic-handling depth.
|
||||
|
||||
...
|
||||
license: "apache-2.0"
|
||||
tags:
|
||||
- llm
|
||||
- gguf
|
||||
- vision
|
||||
- multimodal
|
||||
icon: https://cdn-uploads.huggingface.co/production/uploads/66309bd090589b7c65950665/ztbyGV_zGhzcLuTCSVyq3.png
|
||||
overrides:
|
||||
backend: llama-cpp
|
||||
function:
|
||||
automatic_tool_parsing_fallback: true
|
||||
grammar:
|
||||
disable: true
|
||||
known_usecases:
|
||||
- chat
|
||||
mmproj: llama-cpp/mmproj/Qwopus3.6-35B-A3B-Coder-MTP-Q4_K_M/mmproj-F32.gguf
|
||||
options:
|
||||
- use_jinja:true
|
||||
- spec_type:draft-mtp
|
||||
- spec_n_max:6
|
||||
- spec_p_min:0.75
|
||||
parameters:
|
||||
model: llama-cpp/models/Qwopus3.6-35B-A3B-Coder-MTP-Q4_K_M/Qwopus3.6-35B-A3B-Coder-MTP-Q4_K_M.gguf
|
||||
template:
|
||||
use_tokenizer_template: true
|
||||
files:
|
||||
- filename: llama-cpp/models/Qwopus3.6-35B-A3B-Coder-MTP-Q4_K_M/Qwopus3.6-35B-A3B-Coder-MTP-Q4_K_M.gguf
|
||||
sha256: c283cd2321a3cb4c6e7faf9481ac7d946913e4f02e20172eb2872112f567d8d4
|
||||
uri: https://huggingface.co/Jackrong/Qwopus3.6-35B-A3B-Coder-MTP-GGUF/resolve/main/Qwopus3.6-35B-A3B-Coder-MTP-Q4_K_M.gguf
|
||||
- filename: llama-cpp/mmproj/Qwopus3.6-35B-A3B-Coder-MTP-Q4_K_M/mmproj-F32.gguf
|
||||
sha256: 5c82c8095717b39f29c88ebfec3607a10307785b1e14a87744603d6c582cd497
|
||||
uri: https://huggingface.co/Jackrong/Qwopus3.6-35B-A3B-Coder-MTP-GGUF/resolve/main/mmproj-F32.gguf
|
||||
- name: "ornith-1.0-9b-mtp"
|
||||
url: "github:mudler/LocalAI/gallery/virtual.yaml@master"
|
||||
urls:
|
||||
|
||||
@@ -461,10 +461,7 @@ func (p *RuleParser) parse(arena *Arena, ctx *ParseContext, start int) ParseResu
|
||||
if result.Type != Fail {
|
||||
text := ""
|
||||
if result.Start < len(ctx.Input) {
|
||||
end := result.End
|
||||
if end > len(ctx.Input) {
|
||||
end = len(ctx.Input)
|
||||
}
|
||||
end := min(result.End, len(ctx.Input))
|
||||
text = ctx.Input[result.Start:end]
|
||||
}
|
||||
|
||||
@@ -514,10 +511,7 @@ func (p *TagParser) parse(arena *Arena, ctx *ParseContext, start int) ParseResul
|
||||
if result.Type != Fail {
|
||||
text := ""
|
||||
if result.Start < len(ctx.Input) {
|
||||
end := result.End
|
||||
if end > len(ctx.Input) {
|
||||
end = len(ctx.Input)
|
||||
}
|
||||
end := min(result.End, len(ctx.Input))
|
||||
text = ctx.Input[result.Start:end]
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,10 @@ type LocalAIClient interface {
|
||||
DeleteModel(ctx context.Context, name string) error
|
||||
EditModelConfig(ctx context.Context, name string, patch map[string]any) error
|
||||
ReloadModels(ctx context.Context) error
|
||||
// LoadModel pre-loads a model into memory by name (the inverse of shutting
|
||||
// it down). For a realtime pipeline model every configured sub-model is
|
||||
// loaded; it returns the model names that became resident.
|
||||
LoadModel(ctx context.Context, model string) ([]string, error)
|
||||
ImportModelURI(ctx context.Context, req ImportModelURIRequest) (*ImportModelURIResponse, error)
|
||||
|
||||
// ---- Model aliases ----
|
||||
|
||||
@@ -49,6 +49,7 @@ var toolToHTTPRoute = map[string]string{
|
||||
ToolDeleteModel: "POST /models/delete/:name",
|
||||
ToolEditModelConfig: "PATCH /api/models/config-json/:name",
|
||||
ToolReloadModels: "POST /models/reload",
|
||||
ToolLoadModel: "POST /backend/load",
|
||||
ToolInstallBackend: "POST /backends/apply",
|
||||
ToolUpgradeBackend: "POST /backends/upgrade/:name",
|
||||
ToolToggleModelState: "PUT /models/toggle-state/:name/:action",
|
||||
|
||||
@@ -35,6 +35,7 @@ type fakeClient struct {
|
||||
setAlias func(string, string) error
|
||||
listAliases func() ([]AliasInfo, error)
|
||||
reloadModels func() error
|
||||
loadModel func(string) ([]string, error)
|
||||
listBackends func() ([]Backend, error)
|
||||
listKnownBackends func() ([]schema.KnownBackend, error)
|
||||
installBackend func(InstallBackendRequest) (string, error)
|
||||
@@ -169,6 +170,14 @@ func (f *fakeClient) ReloadModels(_ context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeClient) LoadModel(_ context.Context, model string) ([]string, error) {
|
||||
f.record("LoadModel", model)
|
||||
if f.loadModel != nil {
|
||||
return f.loadModel(model)
|
||||
}
|
||||
return []string{model}, nil
|
||||
}
|
||||
|
||||
func (f *fakeClient) ListBackends(_ context.Context) ([]Backend, error) {
|
||||
f.record("ListBackends", nil)
|
||||
if f.listBackends != nil {
|
||||
|
||||
@@ -338,6 +338,16 @@ func (c *Client) ReloadModels(ctx context.Context) error {
|
||||
return c.do(ctx, http.MethodPost, routeModelsReload, nil, nil)
|
||||
}
|
||||
|
||||
func (c *Client) LoadModel(ctx context.Context, model string) ([]string, error) {
|
||||
// On a load failure the endpoint returns a non-2xx whose body (carrying the
|
||||
// per-sub-model failure detail) is folded into the HTTPError by c.do.
|
||||
var resp schema.ModelLoadResponse
|
||||
if err := c.do(ctx, http.MethodPost, routeBackendLoad, map[string]string{"model": model}, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Loaded, nil
|
||||
}
|
||||
|
||||
// ---- Model aliases ----
|
||||
|
||||
// SetAlias is swap-first: it PATCHes the alias config (a deep-merge that
|
||||
|
||||
@@ -19,6 +19,7 @@ const (
|
||||
routeModelImport = "/models/import"
|
||||
routeAliases = "/api/aliases"
|
||||
routeModelsReload = "/models/reload"
|
||||
routeBackendLoad = "/backend/load"
|
||||
routeBackends = "/backends"
|
||||
routeBackendsKnown = "/backends/known"
|
||||
routeBackendsApply = "/backends/apply"
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/mudler/LocalAI/core/backend"
|
||||
"github.com/mudler/LocalAI/core/config"
|
||||
"github.com/mudler/LocalAI/core/gallery"
|
||||
"github.com/mudler/LocalAI/core/gallery/importers"
|
||||
@@ -302,6 +303,16 @@ func (c *Client) ReloadModels(_ context.Context) error {
|
||||
return c.ConfigLoader.LoadModelConfigsFromPath(c.SystemState.Model.ModelsPath)
|
||||
}
|
||||
|
||||
func (c *Client) LoadModel(ctx context.Context, model string) ([]string, error) {
|
||||
if c.ConfigLoader == nil || c.ModelLoader == nil {
|
||||
return nil, errors.New("model loader not available")
|
||||
}
|
||||
// Reuse the same preload path the REST /backend/load endpoint uses, so a
|
||||
// pipeline model loads all its sub-models and the behaviour stays identical
|
||||
// across the in-process and HTTP clients.
|
||||
return backend.PreloadModelByName(ctx, c.ConfigLoader, c.ModelLoader, c.AppConfig, model)
|
||||
}
|
||||
|
||||
// ---- Model aliases ----
|
||||
|
||||
// SetAlias is swap-first to match the httpapi client: PatchConfig swaps an
|
||||
|
||||
71
pkg/mcp/localaitools/inproc/load_model_test.go
Normal file
71
pkg/mcp/localaitools/inproc/load_model_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package inproc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/mudler/LocalAI/core/config"
|
||||
"github.com/mudler/LocalAI/pkg/model"
|
||||
"github.com/mudler/LocalAI/pkg/system"
|
||||
)
|
||||
|
||||
var _ = Describe("inproc.Client LoadModel", func() {
|
||||
var (
|
||||
ctx context.Context
|
||||
tempDir string
|
||||
cl *config.ModelConfigLoader
|
||||
ml *model.ModelLoader
|
||||
c *Client
|
||||
seedModel func(name, body string)
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
ctx = context.Background()
|
||||
tempDir = GinkgoT().TempDir()
|
||||
systemState, err := system.GetSystemState(system.WithModelPath(tempDir))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
appConfig := config.NewApplicationConfig(config.WithSystemState(systemState))
|
||||
cl = config.NewModelConfigLoader(tempDir)
|
||||
ml = model.NewModelLoader(systemState) // no backends installed
|
||||
c = New(appConfig, systemState, cl, ml, nil)
|
||||
|
||||
seedModel = func(name, body string) {
|
||||
Expect(os.WriteFile(filepath.Join(tempDir, name+".yaml"), []byte(body), 0o644)).To(Succeed())
|
||||
Expect(cl.LoadModelConfigsFromPath(tempDir)).To(Succeed())
|
||||
}
|
||||
})
|
||||
|
||||
It("errors when the model loader is unavailable", func() {
|
||||
noLoader := New(c.AppConfig, c.SystemState, cl, nil, nil)
|
||||
_, err := noLoader.LoadModel(ctx, "anything")
|
||||
Expect(err).To(MatchError(ContainSubstring("model loader not available")))
|
||||
})
|
||||
|
||||
It("loads a regular model through the model loader", func() {
|
||||
seedModel("solo", "name: solo\n")
|
||||
// No backend is installed in the test env, so the load itself fails — but
|
||||
// the call must exercise the single-model path and surface that error
|
||||
// rather than panicking or silently succeeding.
|
||||
loaded, err := c.LoadModel(ctx, "solo")
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(loaded).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("expands a pipeline model into its sub-models", func() {
|
||||
seedModel("voicebot", "name: voicebot\npipeline:\n vad: vad-m\n llm: llm-m\n")
|
||||
seedModel("vad-m", "name: vad-m\n")
|
||||
seedModel("llm-m", "name: llm-m\n")
|
||||
|
||||
loaded, err := c.LoadModel(ctx, "voicebot")
|
||||
// Sub-models can't load without backends, so the joined error names them
|
||||
// — proving the pipeline stub was expanded rather than loaded directly.
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("vad-m"))
|
||||
Expect(err.Error()).ToNot(ContainSubstring("voicebot"))
|
||||
Expect(loaded).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
These rules are non-negotiable. The user trusts you to operate their server without unintended changes.
|
||||
|
||||
1. **Confirm before mutating.** Before calling any of these tools — `install_model`, `import_model_uri`, `delete_model`, `install_backend`, `upgrade_backend`, `edit_model_config`, `reload_models`, `toggle_model_state`, `toggle_model_pinned` — first state in plain language what you are about to do (which tool, which target, which arguments) and wait for the user's explicit confirmation in the next turn. "Yes", "do it", "go ahead", "proceed" all count as confirmation. Anything else does not.
|
||||
1. **Confirm before mutating.** Before calling any of these tools — `install_model`, `import_model_uri`, `delete_model`, `install_backend`, `upgrade_backend`, `edit_model_config`, `reload_models`, `load_model`, `toggle_model_state`, `toggle_model_pinned` — first state in plain language what you are about to do (which tool, which target, which arguments) and wait for the user's explicit confirmation in the next turn. "Yes", "do it", "go ahead", "proceed" all count as confirmation. Anything else does not.
|
||||
|
||||
2. **Disambiguate before mutating.** If the user's request is ambiguous (several gallery candidates match, the model name has multiple installed versions, the backend has variants), present the candidates as a numbered list and ask the user to pick before calling any mutating tool.
|
||||
|
||||
|
||||
@@ -24,5 +24,6 @@ The MCP `tools/list` endpoint also exposes the full input schema for each of the
|
||||
- `upgrade_backend` — Upgrade an installed backend by name.
|
||||
- `edit_model_config` — Patch (deep-merge) JSON into an installed model's config.
|
||||
- `reload_models` — Reload all model configs from disk.
|
||||
- `load_model` — Pre-load a model into memory so the first request pays no cold-start cost. For a realtime pipeline model, every sub-model (VAD, transcription, LLM, TTS, sound_detection, voice_recognition) is loaded. Inverse of stopping a model.
|
||||
- `toggle_model_state` — Enable or disable a model (`action`: `enable` or `disable`).
|
||||
- `toggle_model_pinned` — Pin or unpin a model (`action`: `pin` or `unpin`).
|
||||
|
||||
@@ -92,6 +92,7 @@ var expectedFullCatalog = sortedStrings(
|
||||
ToolListInstalledModels,
|
||||
ToolListKnownBackends,
|
||||
ToolListNodes,
|
||||
ToolLoadModel,
|
||||
ToolReloadModels,
|
||||
ToolSetAlias,
|
||||
ToolSetBranding,
|
||||
@@ -166,6 +167,7 @@ var _ = Describe("Tool dispatch", func() {
|
||||
{ToolUpgradeBackend, map[string]any{"name": "llama-cpp"}, "UpgradeBackend"},
|
||||
{ToolEditModelConfig, map[string]any{"name": "foo", "patch": map[string]any{"context_size": 4096}}, "EditModelConfig"},
|
||||
{ToolReloadModels, struct{}{}, "ReloadModels"},
|
||||
{ToolLoadModel, map[string]any{"model": "test-model"}, "LoadModel"},
|
||||
{ToolToggleModelState, map[string]any{"name": "foo", "action": "enable"}, "ToggleModelState"},
|
||||
{ToolToggleModelPinned, map[string]any{"name": "foo", "action": "pin"}, "ToggleModelPinned"},
|
||||
{ToolSetAlias, map[string]any{"name": "gpt-4", "target": "real"}, "SetAlias"},
|
||||
|
||||
@@ -31,6 +31,7 @@ const (
|
||||
ToolDeleteModel = "delete_model"
|
||||
ToolEditModelConfig = "edit_model_config"
|
||||
ToolReloadModels = "reload_models"
|
||||
ToolLoadModel = "load_model"
|
||||
ToolInstallBackend = "install_backend"
|
||||
ToolUpgradeBackend = "upgrade_backend"
|
||||
ToolToggleModelState = "toggle_model_state"
|
||||
|
||||
@@ -65,6 +65,22 @@ func registerModelTools(s *mcp.Server, client LocalAIClient, opts Options) {
|
||||
return
|
||||
}
|
||||
|
||||
mcp.AddTool(s, &mcp.Tool{
|
||||
Name: ToolLoadModel,
|
||||
Description: "Pre-load a model into memory by name so the first request pays no cold-start cost (the inverse of shutting a model down). For a realtime pipeline model every configured sub-model (VAD, transcription, LLM, TTS, sound_detection, voice_recognition) is loaded. Returns the model names that became resident. Requires user confirmation per safety rule 1.",
|
||||
}, func(ctx context.Context, _ *mcp.CallToolRequest, args struct {
|
||||
Model string `json:"model" jsonschema:"The installed model name to load into memory."`
|
||||
}) (*mcp.CallToolResult, any, error) {
|
||||
if args.Model == "" {
|
||||
return errorResultf("model is required"), nil, nil
|
||||
}
|
||||
loaded, err := client.LoadModel(ctx, args.Model)
|
||||
if err != nil {
|
||||
return errorResult(err), nil, nil
|
||||
}
|
||||
return jsonResult(map[string]any{"loaded": loaded}), nil, nil
|
||||
})
|
||||
|
||||
mcp.AddTool(s, &mcp.Tool{
|
||||
Name: ToolInstallModel,
|
||||
Description: "Install a model from a gallery. Requires explicit user confirmation per safety rule 1. Returns a job id; poll with get_job_status.",
|
||||
|
||||
@@ -1443,6 +1443,52 @@ const docTemplate = `{
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/backend/load": {
|
||||
"post": {
|
||||
"description": "Loads the named model (or, for a realtime pipeline, all of its sub-models) into memory so subsequent requests pay no cold-start cost. The inverse of /backend/shutdown.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"monitoring"
|
||||
],
|
||||
"summary": "Pre-load a model into memory",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Model to load",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ModelLoadRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Model loaded",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ModelLoadResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Missing model name",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ModelLoadResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Load failed (Loaded lists any sub-models that did load)",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ModelLoadResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/backend/monitor": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@@ -5136,6 +5182,30 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.ModelLoadRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.ModelLoadResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"loaded": {
|
||||
"description": "Loaded lists the model names actually resident in memory after the call.\nFor a pipeline model these are its sub-models, not the pipeline name.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"message": {
|
||||
"description": "Message is a short human-readable status (\"model loaded\", or an error).",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.ModelsDataResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -1440,6 +1440,52 @@
|
||||
"responses": {}
|
||||
}
|
||||
},
|
||||
"/backend/load": {
|
||||
"post": {
|
||||
"description": "Loads the named model (or, for a realtime pipeline, all of its sub-models) into memory so subsequent requests pay no cold-start cost. The inverse of /backend/shutdown.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"monitoring"
|
||||
],
|
||||
"summary": "Pre-load a model into memory",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Model to load",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ModelLoadRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Model loaded",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ModelLoadResponse"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Missing model name",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ModelLoadResponse"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Load failed (Loaded lists any sub-models that did load)",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.ModelLoadResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/backend/monitor": {
|
||||
"get": {
|
||||
"tags": [
|
||||
@@ -5133,6 +5179,30 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.ModelLoadRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.ModelLoadResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"loaded": {
|
||||
"description": "Loaded lists the model names actually resident in memory after the call.\nFor a pipeline model these are its sub-models, not the pipeline name.",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"message": {
|
||||
"description": "Message is a short human-readable status (\"model loaded\", or an error).",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"schema.ModelsDataResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -1362,6 +1362,25 @@ definitions:
|
||||
$ref: '#/definitions/schema.ToolCall'
|
||||
type: array
|
||||
type: object
|
||||
schema.ModelLoadRequest:
|
||||
properties:
|
||||
model:
|
||||
type: string
|
||||
type: object
|
||||
schema.ModelLoadResponse:
|
||||
properties:
|
||||
loaded:
|
||||
description: |-
|
||||
Loaded lists the model names actually resident in memory after the call.
|
||||
For a pipeline model these are its sub-models, not the pipeline name.
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
message:
|
||||
description: Message is a short human-readable status ("model loaded", or
|
||||
an error).
|
||||
type: string
|
||||
type: object
|
||||
schema.ModelsDataResponse:
|
||||
properties:
|
||||
data:
|
||||
@@ -3510,6 +3529,38 @@ paths:
|
||||
summary: Bidirectional realtime audio transform over WebSocket.
|
||||
tags:
|
||||
- audio
|
||||
/backend/load:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Loads the named model (or, for a realtime pipeline, all of its
|
||||
sub-models) into memory so subsequent requests pay no cold-start cost. The
|
||||
inverse of /backend/shutdown.
|
||||
parameters:
|
||||
- description: Model to load
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/schema.ModelLoadRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Model loaded
|
||||
schema:
|
||||
$ref: '#/definitions/schema.ModelLoadResponse'
|
||||
"400":
|
||||
description: Missing model name
|
||||
schema:
|
||||
$ref: '#/definitions/schema.ModelLoadResponse'
|
||||
"500":
|
||||
description: Load failed (Loaded lists any sub-models that did load)
|
||||
schema:
|
||||
$ref: '#/definitions/schema.ModelLoadResponse'
|
||||
summary: Pre-load a model into memory
|
||||
tags:
|
||||
- monitoring
|
||||
/backend/monitor:
|
||||
get:
|
||||
parameters:
|
||||
|
||||
Reference in New Issue
Block a user