Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
37 changes: 37 additions & 0 deletions src/lib/inference/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,43 @@ describe("getSandboxInferenceConfig", () => {
});
});

// #2747 followup to #3678: Ollama's OpenAI-compat stream omits the usage
// chunk unless the request sets `stream_options.include_usage: true`.
// OpenClaw gates that on `model.compat.supportsUsageInStreaming`. The
// ollama-local path runs through `inference.local`, which OpenClaw's
// own Ollama detector doesn't recognise — so the compat flag has to
// travel into openclaw.json via `inferenceCompat`. The previous Python-
// side conditional in `generate-openclaw-config.py` could never fire
// because `providerKey` resolves to `MANAGED_PROVIDER_ID` ("inference")
// for ollama-local, not "ollama" / "ollama-local". Wiring it here is
// the right layer.
it("forces supportsUsageInStreaming for ollama-local (#2747)", () => {
expect(getSandboxInferenceConfig("qwen2.5:7b", "ollama-local")).toEqual({
providerKey: MANAGED_PROVIDER_ID,
primaryModelRef: `${MANAGED_PROVIDER_ID}/qwen2.5:7b`,
inferenceBaseUrl: INFERENCE_ROUTE_URL,
inferenceApi: "openai-completions",
inferenceCompat: {
supportsUsageInStreaming: true,
},
});
});

it("does not force supportsUsageInStreaming for non-ollama providers", () => {
for (const provider of [
"nvidia-prod",
"nvidia-nim",
"nvidia-router",
"openai-api",
"compatible-endpoint",
"anthropic-prod",
"gemini-api",
]) {
const compat = getSandboxInferenceConfig("model", provider).inferenceCompat;
expect(compat?.supportsUsageInStreaming).toBeUndefined();
}
});

it("uses a probed Responses API override when one is available", () => {
expect(getSandboxInferenceConfig("gpt-5.4", "openai-api", "openai-responses")).toEqual({
providerKey: "openai",
Expand Down
17 changes: 17 additions & 0 deletions src/lib/inference/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@
providerKey = MANAGED_PROVIDER_ID;
primaryModelRef = `${MANAGED_PROVIDER_ID}/${model}`;
break;
case "ollama-local":
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
// Ollama's OpenAI-compatible /v1/chat/completions stream omits the
// `usage` chunk unless the request sets `stream_options.include_usage:
// true`. OpenClaw gates that on `model.compat.supportsUsageInStreaming`
// (src/agents/openai-transport-stream.ts upstream); its own Ollama
// extension auto-detects the flag only when the endpoint reads as
// localhost:11434 or `model.provider === "ollama"` exactly, which
// doesn't match the standardised `inference.local` URL NemoClaw routes
// through. Pin the compat flag here so the TUI token counter updates
// after each turn instead of staying `?` (#2747). Mirrors the LM Studio
// extension's `withLmstudioUsageCompat` workaround.
providerKey = MANAGED_PROVIDER_ID;
primaryModelRef = `${MANAGED_PROVIDER_ID}/${model}`;
inferenceCompat = {
supportsUsageInStreaming: true,
};
break;
case "nvidia-prod":
case "nvidia-nim":
default:
Expand Down