Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/inference/set-up-ollama.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,17 @@ The following settings control non-interactive selection:
|---|---|
| `NEMOCLAW_PROVIDER` | Set to `ollama`. |
| `NEMOCLAW_MODEL` | Optional Ollama model tag. |
| `NEMOCLAW_PROVIDER_MODEL` | Compatibility fallback for automation that cannot pass `NEMOCLAW_MODEL`. Ignored when `NEMOCLAW_MODEL` is set. |
| `NEMOCLAW_YES` | Optional model download authorization when set to `1`. |

Under `--non-interactive`, include `--yes` or set `NEMOCLAW_YES=1` to authorize a model download.
Onboarding exits when a download requires confirmation and the run cannot prompt.

## Understand Model Selection

When `NEMOCLAW_MODEL` is unset, NemoClaw selects a starter model based on currently available memory.
When `NEMOCLAW_MODEL` and the `NEMOCLAW_PROVIDER_MODEL` compatibility fallback are unset, NemoClaw selects a starter model based on currently available memory.
During interactive onboarding, if the requested model env contains a safe model tag that appears in the current Ollama menu, NemoClaw uses that menu entry as the default.
If the tag is absent from the rendered installed or starter list, the normal memory-based default remains.
If a known bootstrap model does not fit, NemoClaw warns and falls back to the largest known model that does fit.
Unknown or custom tags pass through to the Ollama runner for validation.

Expand Down
36 changes: 36 additions & 0 deletions src/lib/inference/ollama/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,42 @@ describe("promptOllamaModel installed-model fit filter", () => {
expect(result).toBe("qwen3.5:9b");
});

it("defaults to a requested model when it is shown in the installed model menu", async () => {
const setup = loadProxyWithMocks({
installed: ["qwen2.5:0.5b", "qwen3.6:35b"],
promptValues: [""],
});
active = setup;
const result = await setup.proxy.promptOllamaModel(
{
type: "nvidia",
totalMemoryMB: 131_072,
availableMemoryMB: 131_072,
},
{ defaultModel: "qwen3.6:35b" },
);
expect(result).toBe("qwen3.6:35b");
expect(setup.promptArgs).toEqual([" Choose model [2]: "]);
});

it("keeps the memory-based default when a requested model is not shown", async () => {
const setup = loadProxyWithMocks({
installed: ["qwen2.5:0.5b", "qwen3.5:9b"],
promptValues: [""],
});
active = setup;
const result = await setup.proxy.promptOllamaModel(
{
type: "nvidia",
totalMemoryMB: 131_072,
availableMemoryMB: 131_072,
},
{ defaultModel: "qwen3.6:35b" },
);
expect(result).toBe("qwen2.5:0.5b");
expect(setup.promptArgs).toEqual([" Choose model [1]: "]);
});

it("respects unknown installed tags (not in the registry) even when nothing else fits", async () => {
const setup = loadProxyWithMocks({
installed: ["my-custom:model"],
Expand Down
21 changes: 16 additions & 5 deletions src/lib/inference/ollama/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const { isNonInteractiveEnv }: typeof import("../../core/non-interactive") =
const { waitForPort } = require("../../core/wait");
const { ensurePulledOllamaModel }: typeof import("./model-discovery") =
require("./model-discovery");
const { ollamaModelRefsMatch }: typeof import("./model-discovery") = require("./model-discovery");
const {
getDefaultOllamaModel,
getBootstrapOllamaModelOptions,
Expand Down Expand Up @@ -491,7 +492,7 @@ function probeOllamaAuthProxyHealth(): { ok: boolean; endpoint: string; detail:

async function promptOllamaModel(
gpu: GpuInfo | null = null,
promptOptions: { excludeModels?: ReadonlySet<string> } = {},
promptOptions: { defaultModel?: string | null; excludeModels?: ReadonlySet<string> } = {},
) {
const excludeModels = promptOptions.excludeModels;
const isExcluded = (tag: string): boolean =>
Expand All @@ -510,11 +511,21 @@ async function promptOllamaModel(
const usingInstalled = installedFitting.length > 0;
const bootstrap = getBootstrapOllamaModelOptions(gpu).filter((tag: string) => !isExcluded(tag));
const options = usingInstalled ? installedFitting : bootstrap;
const requestedDefaultModel =
typeof promptOptions.defaultModel === "string" ? promptOptions.defaultModel.trim() : "";
const requestedDefaultOption = requestedDefaultModel
? options.find((option: string) => ollamaModelRefsMatch(option, requestedDefaultModel))
: undefined;
const defaultModelCandidate = getDefaultOllamaModel(gpu);
const defaultModel = isExcluded(defaultModelCandidate)
? (options[0] ?? defaultModelCandidate)
: defaultModelCandidate;
const defaultIndex = Math.max(0, options.indexOf(defaultModel));
const defaultModel =
requestedDefaultOption ??
(isExcluded(defaultModelCandidate)
? (options[0] ?? defaultModelCandidate)
: defaultModelCandidate);
const defaultIndex = Math.max(
0,
options.findIndex((option: string) => ollamaModelRefsMatch(option, defaultModel)),
);

console.log("");
console.log(usingInstalled ? " Ollama models:" : " Ollama starter models:");
Expand Down
10 changes: 8 additions & 2 deletions src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3003,10 +3003,11 @@ async function selectAndValidateOllamaModel(
requestedModel: string | null;
recoveredModel: string | null;
lockedModel?: string | null;
promptDefaultModel?: string | null;
},
onModelSelected?: (model: string) => void,
): Promise<OllamaModelSelectionOutcome> {
const { requestedModel, recoveredModel, lockedModel } = defaults;
const { requestedModel, recoveredModel, lockedModel, promptDefaultModel } = defaults;
const probeFailures = new OllamaProbeFailureTracker();
const confirm = (question: string, defaultIsYes: boolean) =>
promptYesNoOrDefault(question, null, defaultIsYes);
Expand All @@ -3019,7 +3020,12 @@ async function selectAndValidateOllamaModel(
} else if (isNonInteractive()) {
model = localInference.resolveNonInteractiveOllamaModel(requestedModel, recoveredModel, gpu);
} else {
model = await promptOllamaModel(gpu, { excludeModels: probeFailures.excludedModels() });
const safePromptDefaultModel =
promptDefaultModel && isSafeModelId(promptDefaultModel) ? promptDefaultModel : null;
model = await promptOllamaModel(gpu, {
defaultModel: safePromptDefaultModel,
excludeModels: probeFailures.excludedModels(),
});
}
if (isBackToSelection(model)) {
console.log(" Returning to provider selection.");
Expand Down
26 changes: 26 additions & 0 deletions src/lib/onboard/providers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function withProviderEnv(next: Record<string, string | undefined>, testBody: ()
"NEMOCLAW_PROVIDER",
"NEMOCLAW_ENDPOINT_URL",
"NEMOCLAW_MODEL",
"NEMOCLAW_PROVIDER_MODEL",
"NEMOCLAW_COMPAT_MODEL",
"NEMOCLAW_PREFERRED_API",
"NEMOCLAW_CLOUD_EXPERIMENTAL_MODEL",
Expand Down Expand Up @@ -391,6 +392,31 @@ describe("onboard provider helpers", () => {
);
});

it("uses NEMOCLAW_PROVIDER_MODEL as a non-interactive model fallback", () => {
withProviderEnv(
{
NEMOCLAW_PROVIDER: "ollama",
NEMOCLAW_PROVIDER_MODEL: "qwen3.6:35b",
},
() => {
expect(getRequestedModelHint(true)).toBe("qwen3.6:35b");
},
);
});

it("keeps NEMOCLAW_MODEL ahead of NEMOCLAW_PROVIDER_MODEL", () => {
withProviderEnv(
{
NEMOCLAW_PROVIDER: "ollama",
NEMOCLAW_MODEL: "qwen2.5:0.5b",
NEMOCLAW_PROVIDER_MODEL: "qwen3.6:35b",
},
() => {
expect(getRequestedModelHint(true)).toBe("qwen2.5:0.5b");
},
);
});

it("stages Deep Agents NEMOCLAW_PROVIDER_KEY as hosted custom inference", () => {
withProviderEnv(
{
Expand Down
23 changes: 19 additions & 4 deletions src/lib/onboard/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const HOSTED_INFERENCE_SOURCE_ENV = "NVIDIA_INFERENCE_API_KEY";
const HOSTED_INFERENCE_PROVIDER_KEY_ENV = "NEMOCLAW_PROVIDER_KEY";
const HOSTED_INFERENCE_CREDENTIAL_ENV = "COMPATIBLE_API_KEY";
const HOSTED_INFERENCE_ENDPOINT_URL = "https://inference-api.nvidia.com/v1";
const MODEL_ENV = "NEMOCLAW_MODEL";
const PROVIDER_MODEL_ENV = "NEMOCLAW_PROVIDER_MODEL";
// Private CI-compatible Inference Hub endpoint model IDs use the
// provider/namespace/model convention. This endpoint is staged as a custom
// OpenAI-compatible provider, not as the public build.nvidia.com provider.
Expand Down Expand Up @@ -288,11 +290,11 @@ function stageHostedInferenceSourceSecretEnv() {
process.env.NEMOCLAW_ENDPOINT_URL =
(process.env.NEMOCLAW_ENDPOINT_URL || "").trim() || HOSTED_INFERENCE_ENDPOINT_URL;
const model =
(process.env.NEMOCLAW_MODEL || "").trim() ||
getRequestedModelFromEnv() ||
(process.env.NEMOCLAW_COMPAT_MODEL || "").trim() ||
(process.env.NEMOCLAW_CLOUD_EXPERIMENTAL_MODEL || "").trim() ||
HOSTED_INFERENCE_MODEL;
process.env.NEMOCLAW_MODEL = model;
process.env[MODEL_ENV] = model;
process.env.NEMOCLAW_COMPAT_MODEL = (process.env.NEMOCLAW_COMPAT_MODEL || "").trim() || model;
process.env.NEMOCLAW_PREFERRED_API =
(process.env.NEMOCLAW_PREFERRED_API || "").trim() || "openai-completions";
Expand All @@ -307,11 +309,23 @@ function isHostedInferenceProviderKeyCredentialCandidate(value) {

const isProviderKeyCredentialCandidate = isHostedInferenceProviderKeyCredentialCandidate;

function getRequestedModelEnv(env = process.env) {
const model = (env[MODEL_ENV] || "").trim();
if (model) return { value: model, source: MODEL_ENV };
const providerModel = (env[PROVIDER_MODEL_ENV] || "").trim();
if (providerModel) return { value: providerModel, source: PROVIDER_MODEL_ENV };
return { value: "", source: null };
}

function getRequestedModelFromEnv(env = process.env) {
return getRequestedModelEnv(env).value || null;
}

function getNonInteractiveModel(providerKey) {
const model = (process.env.NEMOCLAW_MODEL || "").trim();
const { value: model, source } = getRequestedModelEnv();
if (!model) return null;
if (!isSafeModelId(model)) {
console.error(` Invalid NEMOCLAW_MODEL for provider '${providerKey}': ${model}`);
console.error(` Invalid ${source || MODEL_ENV} for provider '${providerKey}': ${model}`);
console.error(" Model values may only contain letters, numbers, '.', '_', ':', '/', and '-'.");
process.exit(1);
}
Expand Down Expand Up @@ -510,6 +524,7 @@ module.exports = {
stageHostedInferenceSourceSecretEnv,
getNonInteractiveProvider,
getNonInteractiveModel,
getRequestedModelFromEnv,
getRequestedProviderHint,
getRequestedModelHint,
isProviderKeyCredentialCandidate,
Expand Down
51 changes: 51 additions & 0 deletions src/lib/onboard/setup-nim-ollama.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe("createSetupNimOllamaHandlers", () => {
},
selectAndValidateOllamaModel: async (_gpu, _provider, args, onModelSelected) => {
expect(args.lockedModel).toBe("required/model");
expect(args.promptDefaultModel).toBeNull();
events.push("prepare-model");
onModelSelected?.("required/model");
return { outcome: "selected", model: "required/model", allowToolsIncompatible: false };
Expand All @@ -97,6 +98,56 @@ describe("createSetupNimOllamaHandlers", () => {
]);
});

it("passes NEMOCLAW_MODEL as the interactive Ollama prompt default", async () => {
const state = makeState();
const selectModel = vi.fn(async (_gpu, _provider, args) => {
expect(args.requestedModel).toBeNull();
expect(args.lockedModel).toBeNull();
expect(args.promptDefaultModel).toBe("qwen3.6:35b");
return { outcome: "selected" as const, model: "qwen3.6:35b", allowToolsIncompatible: false };
});
const { handleRunningOllamaSelection } = createSetupNimOllamaHandlers(
makeDeps({
isNonInteractive: () => false,
process: {
...process,
env: { ...process.env, NEMOCLAW_MODEL: "qwen3.6:35b" },
} as NodeJS.Process,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
selectAndValidateOllamaModel: selectModel,
}),
);

const result = await handleRunningOllamaSelection(null, null, null, true, state);

expect(result).toBe("selected");
expect(selectModel).toHaveBeenCalledTimes(1);
});

it("passes NEMOCLAW_PROVIDER_MODEL as the interactive Ollama prompt default fallback", async () => {
const state = makeState();
const selectModel = vi.fn(async (_gpu, _provider, args) => {
expect(args.requestedModel).toBeNull();
expect(args.lockedModel).toBeNull();
expect(args.promptDefaultModel).toBe("qwen3.6:35b");
return { outcome: "selected" as const, model: "qwen3.6:35b", allowToolsIncompatible: false };
});
const { handleRunningOllamaSelection } = createSetupNimOllamaHandlers(
makeDeps({
isNonInteractive: () => false,
process: {
...process,
env: { ...process.env, NEMOCLAW_PROVIDER_MODEL: "qwen3.6:35b" },
} as NodeJS.Process,
selectAndValidateOllamaModel: selectModel,
}),
);

const result = await handleRunningOllamaSelection(null, null, null, true, state);

expect(result).toBe("selected");
expect(selectModel).toHaveBeenCalledTimes(1);
});

it("does not install Ollama when shared-gateway preflight rejects", async () => {
const state = makeState();
state.assertRouteCompatible = () => {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/onboard/setup-nim-ollama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import type { OllamaStartupOutcome } from "./ollama-startup";
import type { SetupNimSelectionState } from "./setup-nim-selection";

const {
getRequestedModelFromEnv,
}: {
getRequestedModelFromEnv: (env?: NodeJS.ProcessEnv) => string | null;
} = require("./providers");

type SetupNimSelectionResult = "selected" | "retry-selection";

type SetupNimOllamaDeps = {
Expand All @@ -30,6 +36,7 @@ type SetupNimOllamaDeps = {
requestedModel: string | null;
recoveredModel: string | null;
lockedModel?: string | null;
promptDefaultModel?: string | null;
},
onModelSelected?: (model: string) => void,
) => Promise<
Expand Down Expand Up @@ -91,13 +98,16 @@ export function createSetupNimOllamaHandlers(deps: SetupNimOllamaDeps): {
lockedModel: string | null,
): Promise<SetupNimSelectionResult> {
const constrainedModel = typeof state.model === "string" ? state.model : requestedModel;
const promptDefaultModel =
!lockedModel && !deps.isNonInteractive() ? getRequestedModelFromEnv(deps.process.env) : null;
const result = await deps.selectAndValidateOllamaModel(
gpu,
state.provider,
{
requestedModel: constrainedModel,
recoveredModel,
lockedModel,
promptDefaultModel,
},
(model) => {
state.model = model;
Expand Down
Loading