mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 02:33:43 +00:00
fix: use configured base URL for Ollama model discovery (#14131)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 2292d2de6d
Co-authored-by: shtse8 <8020099+shtse8@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
@@ -2,7 +2,27 @@ import { mkdtempSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveImplicitProviders } from "./models-config.providers.js";
|
||||
import { resolveImplicitProviders, resolveOllamaApiBase } from "./models-config.providers.js";
|
||||
|
||||
describe("resolveOllamaApiBase", () => {
|
||||
it("returns default localhost base when no configured URL is provided", () => {
|
||||
expect(resolveOllamaApiBase()).toBe("http://127.0.0.1:11434");
|
||||
});
|
||||
|
||||
it("strips /v1 suffix from OpenAI-compatible URLs", () => {
|
||||
expect(resolveOllamaApiBase("http://ollama-host:11434/v1")).toBe("http://ollama-host:11434");
|
||||
expect(resolveOllamaApiBase("http://ollama-host:11434/V1")).toBe("http://ollama-host:11434");
|
||||
});
|
||||
|
||||
it("keeps URLs without /v1 unchanged", () => {
|
||||
expect(resolveOllamaApiBase("http://ollama-host:11434")).toBe("http://ollama-host:11434");
|
||||
});
|
||||
|
||||
it("handles trailing slash before canonicalizing", () => {
|
||||
expect(resolveOllamaApiBase("http://ollama-host:11434/v1/")).toBe("http://ollama-host:11434");
|
||||
expect(resolveOllamaApiBase("http://ollama-host:11434/")).toBe("http://ollama-host:11434");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ollama provider", () => {
|
||||
it("should not include ollama when no API key is configured", async () => {
|
||||
@@ -33,6 +53,28 @@ describe("Ollama provider", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("should preserve explicit ollama baseUrl on implicit provider injection", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
process.env.OLLAMA_API_KEY = "test-key";
|
||||
|
||||
try {
|
||||
const providers = await resolveImplicitProviders({
|
||||
agentDir,
|
||||
explicitProviders: {
|
||||
ollama: {
|
||||
baseUrl: "http://192.168.20.14:11434/v1",
|
||||
api: "openai-completions",
|
||||
models: [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(providers?.ollama?.baseUrl).toBe("http://192.168.20.14:11434/v1");
|
||||
} finally {
|
||||
delete process.env.OLLAMA_API_KEY;
|
||||
}
|
||||
});
|
||||
|
||||
it("should have correct model structure with streaming disabled (unit test)", () => {
|
||||
// This test directly verifies the model configuration structure
|
||||
// since discoverOllamaModels() returns empty array in test mode
|
||||
|
||||
Reference in New Issue
Block a user