Add support for generic OpenAI-compatible endpoint LLM provider (#253)
* initial * fix regressions * Fix OpenAI-compatible provider aliases * Normalize OpenAI-compatible settings aliases * Update shared/src/settings-registry.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot
parent
6454efd9a2
commit
faea61a249
@@ -117,4 +117,15 @@ describe("settingsRegistry helpers", () => {
|
||||
expect(settingsRegistry.rxresumeApiKey.envKey).toBe("RXRESUME_API_KEY");
|
||||
});
|
||||
});
|
||||
|
||||
describe("LLM provider parsing", () => {
|
||||
it("normalizes the documented openai-compatible alias", () => {
|
||||
expect(settingsRegistry.llmProvider.parse("openai-compatible")).toBe(
|
||||
"openai_compatible",
|
||||
);
|
||||
expect(settingsRegistry.llmProvider.parse("OPENAI-COMPATIBLE")).toBe(
|
||||
"openai_compatible",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,6 +26,12 @@ function parseBitBoolOrNull(raw: string | undefined): boolean | null {
|
||||
return raw === "true" || raw === "1";
|
||||
}
|
||||
|
||||
function normalizeLlmProviderOrNull(raw: string | undefined): string | null {
|
||||
if (raw === undefined) return null;
|
||||
const normalized = raw.trim().toLowerCase().replace(/-/g, "_");
|
||||
return normalized ? normalized : null;
|
||||
}
|
||||
|
||||
function serializeNullableNumber(
|
||||
value: number | null | undefined,
|
||||
): string | null {
|
||||
@@ -66,16 +72,23 @@ export const settingsRegistry = {
|
||||
kind: "typed" as const,
|
||||
envKey: "LLM_PROVIDER",
|
||||
schema: z.preprocess(
|
||||
(v) => (v === "" ? null : v),
|
||||
(v) => (typeof v === "string" ? normalizeLlmProviderOrNull(v) : v),
|
||||
z
|
||||
.enum(["openrouter", "lmstudio", "ollama", "openai", "gemini"])
|
||||
.enum([
|
||||
"openrouter",
|
||||
"lmstudio",
|
||||
"ollama",
|
||||
"openai",
|
||||
"openai_compatible",
|
||||
"gemini",
|
||||
])
|
||||
.nullable(),
|
||||
),
|
||||
default: (): string =>
|
||||
typeof process !== "undefined"
|
||||
? process.env.LLM_PROVIDER || "openrouter"
|
||||
? normalizeLlmProviderOrNull(process.env.LLM_PROVIDER) || "openrouter"
|
||||
: "openrouter",
|
||||
parse: parseNonEmptyStringOrNull,
|
||||
parse: normalizeLlmProviderOrNull,
|
||||
serialize: (value: string | null | undefined): string | null =>
|
||||
value ?? null,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user