This commit is contained in:
nulone 2026-01-31 00:04:29 +08:00 committed by GitHub
commit e572bdd0e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 1 deletions

View File

@ -127,4 +127,40 @@ describe("resolveModel", () => {
expect(result.model?.provider).toBe("custom");
expect(result.model?.id).toBe("missing-model");
});
it("inherits provider api when registry model has no api (issue #1695)", async () => {
const { discoverModels } = await import("@mariozechner/pi-coding-agent");
const mockModel = {
id: "test-model",
name: "test-model",
provider: "lmstudio",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 4096,
maxTokens: 4096,
// No api field set
};
vi.mocked(discoverModels).mockReturnValue({
find: vi.fn(() => mockModel),
} as any);
const cfg = {
models: {
providers: {
lmstudio: {
api: "openai-responses",
baseUrl: "http://localhost:1234",
},
},
},
} as MoltbotConfig;
const result = resolveModel("lmstudio", "test-model", "/tmp/agent", cfg);
expect(result.model?.api).toBe("openai-responses");
expect(result.model?.id).toBe("test-model");
expect(result.model?.provider).toBe("lmstudio");
});
});

View File

@ -97,5 +97,7 @@ export function resolveModel(
modelRegistry,
};
}
return { model: normalizeModelCompat(model), authStorage, modelRegistry };
const providerCfg = cfg?.models?.providers?.[provider];
const merged = { ...model, api: model.api ?? providerCfg?.api };
return { model: normalizeModelCompat(merged), authStorage, modelRegistry };
}