Skip to content

Commit f67b12f

Browse files
committed
fix(cookbook): build serve commands for selected target
1 parent c669054 commit f67b12f

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

static/js/cookbook.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,11 @@ export function _buildServeCmd(f, modelName, backend) {
643643
// GPU list — read from gpus (button strip); fall back to gpu_id for
644644
// backward-compat with older saved presets that pre-date the removal.
645645
const gpuId = (f.gpus || f.gpu_id || '').toString().trim();
646-
const _isWin = _isWindows();
647-
const _localWindows = _isWin && !_envState.remoteHost;
646+
const _targetHost = Object.prototype.hasOwnProperty.call(f, 'host')
647+
? String(f.host || '').trim()
648+
: String(_envState.remoteHost || '').trim();
649+
const _isWin = _targetHost ? _isWindows(_targetHost) : _isWindows('local');
650+
const _localWindows = _isWin && !_targetHost;
648651
const py = _isWin ? 'python' : 'python3';
649652
// CPU-only serve (-ngl 0): drop the GPU-only flags, otherwise the command
650653
// mixes "zero GPU layers" with CUDA unified-memory + flash-attn and fails to
@@ -667,7 +670,7 @@ export function _buildServeCmd(f, modelName, backend) {
667670
// with misleading prefixes.
668671
const _sb = String(_hwfitCache?.system?.backend || '').toLowerCase();
669672
const _hwfitHost = String(_hwfitCache?._scannedHost || '');
670-
const _curHost = String(_envState.remoteHost || '');
673+
const _curHost = _targetHost;
671674
const _isCudaTarget = (_sb === 'cuda') && (_hwfitHost === _curHost);
672675
const lcPrefix = (() => {
673676
let p = '';

static/js/cookbookServe.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,11 @@ function _rerenderCachedModels() {
15311531
if (el.type === 'checkbox') f[el.dataset.field] = el.checked;
15321532
else f[el.dataset.field] = el.value;
15331533
});
1534+
const buildTarget = _selectedServeTarget(panel);
1535+
f.host = buildTarget.host || '';
1536+
f.platform = buildTarget.platform || '';
1537+
const hostField = panel.querySelector('[data-field="host"]');
1538+
if (hostField) hostField.value = f.host;
15341539
const backend = f.backend || 'vllm';
15351540
const serveModel = (f.model_path || '').trim() || (m.is_local_dir && m.path ? `${m.path}/${repo}` : repo);
15361541
if (backend === 'llamacpp') {

tests/test_cookbook_cpu_only_serve.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,29 @@ def test_local_windows_llamacpp_prefers_native_llama_server():
121121
text = SRC.read_text(encoding="utf-8")
122122
helpers = (ROOT / "routes/cookbook_helpers.py").read_text(encoding="utf-8")
123123

124-
assert "const _localWindows = _isWin && !_envState.remoteHost;" in text
124+
assert "Object.prototype.hasOwnProperty.call(f, 'host')" in text
125+
assert "const _isWin = _targetHost ? _isWindows(_targetHost) : _isWindows('local');" in text
126+
assert "const _localWindows = _isWin && !_targetHost;" in text
127+
assert "const _curHost = _targetHost;" in text
128+
assert "const _localWindows = _isWin && !_envState.remoteHost;" not in text
125129
assert "const gpuId = (f.gpus || f.gpu_id || '').toString().trim();" in text
126130
assert "const _lcServer = `${lcPrefix}llama-server --model" in text
127131
assert "if (_localWindows) {" in text
128132
assert "cmd += _lcServer;" in text
129133
assert '"llama-server.exe"' in helpers
130134

131135

136+
137+
def test_serve_command_preview_uses_selected_target_host():
138+
text = SERVE_SRC.read_text(encoding="utf-8")
139+
140+
assert "const buildTarget = _selectedServeTarget(panel);" in text
141+
assert "f.host = buildTarget.host || '';" in text
142+
assert "f.platform = buildTarget.platform || '';" in text
143+
assert "const hostField = panel.querySelector('[data-field=\"host\"]');" in text
144+
assert "if (hostField) hostField.value = f.host;" in text
145+
146+
132147
def test_local_windows_llama_server_skips_source_bootstrap():
133148
routes = ROUTES_SRC.read_text(encoding="utf-8")
134149

0 commit comments

Comments
 (0)