mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-09 01:22:52 +00:00
fix: validate lmstudio discovered context lengths
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
fetchLmstudioModels,
|
||||
} from "./models.fetch.js";
|
||||
import {
|
||||
mapLmstudioWireEntry,
|
||||
normalizeLmstudioConfiguredCatalogEntry,
|
||||
normalizeLmstudioProviderConfig,
|
||||
resolveLmstudioInferenceBase,
|
||||
@@ -160,6 +161,23 @@ describe("lmstudio-models", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("drops malformed discovered context metadata", () => {
|
||||
const model = mapLmstudioWireEntry({
|
||||
type: "llm",
|
||||
key: "bad-context",
|
||||
max_context_length: 32768.5,
|
||||
loaded_instances: [{ id: "loaded", config: { context_length: Number.POSITIVE_INFINITY } }],
|
||||
});
|
||||
|
||||
expect(model).toMatchObject({
|
||||
id: "bad-context",
|
||||
contextWindow: SELF_HOSTED_DEFAULT_CONTEXT_WINDOW,
|
||||
contextTokens: LMSTUDIO_DEFAULT_LOAD_CONTEXT_LENGTH,
|
||||
maxTokens: SELF_HOSTED_DEFAULT_MAX_TOKENS,
|
||||
loaded: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves reasoning capability for supported and unsupported options", () => {
|
||||
expect(resolveLmstudioReasoningCapability({ capabilities: undefined })).toBe(false);
|
||||
expect(
|
||||
@@ -499,6 +517,24 @@ describe("lmstudio-models", () => {
|
||||
expectLoadContextLength(fetchMock, 8192);
|
||||
});
|
||||
|
||||
it("omits malformed context lengths before loading models", async () => {
|
||||
const fetchMock = createModelLoadFetchMock({
|
||||
loadedContextLength: 4096.5,
|
||||
maxContextLength: 32768.5,
|
||||
});
|
||||
vi.stubGlobal("fetch", asFetch(fetchMock));
|
||||
|
||||
await expect(
|
||||
ensureLmstudioModelLoaded({
|
||||
baseUrl: "http://localhost:1234/v1",
|
||||
modelKey: "qwen3-8b-instruct",
|
||||
requestedContextLength: 8192.5,
|
||||
}),
|
||||
).resolves.toBeUndefined();
|
||||
|
||||
expectLoadContextLength(fetchMock, LMSTUDIO_DEFAULT_LOAD_CONTEXT_LENGTH);
|
||||
});
|
||||
|
||||
it("throws when model discovery fails", async () => {
|
||||
const fetchMock = vi.fn(async () => ({
|
||||
ok: false,
|
||||
|
||||
Reference in New Issue
Block a user