feat: support comma-separated AI_MODEL for quick multi-model setup (#870)

Users expected setting AI_MODEL to a comma-separated list to expose
multiple models in the picker, but the value was used verbatim as a
single model id, leaving the picker with only the "Server Default"
fallback.

Add a third-priority fallback in loadEnvServerModelsConfig: when
AI_MODELS_CONFIG and ai-models.json are both absent, AI_MODEL contains
a comma, and AI_PROVIDER is set to a known provider, synthesize an
equivalent ServerModelsConfig with the provider's models trimmed,
deduplicated, and the first marked as default.

Also makes getAIModel and getValidationModel pick the first comma-split
value when falling back to AI_MODEL, so requests started before the
client picker hydrates still resolve to a real model id.

Docs (en/cn/ja) and env.example updated; tests cover the new fallback
plus the no-comma / no-AI_PROVIDER negative cases.
This commit is contained in:
Dayuan Jiang
2026-06-15 14:27:55 +09:00
committed by GitHub
parent 0f9699843f
commit 8e42dd9da8
10 changed files with 140 additions and 12 deletions

View File

@@ -159,6 +159,44 @@ describe("loadFlattenedServerModels", () => {
expect(defaultModel.modelId).toBe("gpt-4o") // First model of default provider
})
it("falls back to comma-separated AI_MODEL when no other config is set", async () => {
process.env.AI_MODELS_CONFIG = ""
process.env.AI_MODELS_CONFIG_PATH = `non-existent-config-${Date.now()}.json`
process.env.AI_PROVIDER = "openai"
process.env.AI_MODEL = "gpt-4o, gpt-4o-mini, gpt-4o"
const models = await loadFlattenedServerModels()
// Trims, deduplicates, and preserves order
expect(models.map((m) => m.modelId)).toEqual(["gpt-4o", "gpt-4o-mini"])
expect(models.every((m) => m.provider === "openai")).toBe(true)
// First model is marked default (provider has default: true)
const defaults = models.filter((m) => m.isDefault)
expect(defaults.length).toBe(1)
expect(defaults[0].modelId).toBe("gpt-4o")
})
it("does not synthesize when AI_MODEL has no comma", async () => {
process.env.AI_MODELS_CONFIG = ""
process.env.AI_MODELS_CONFIG_PATH = `non-existent-config-${Date.now()}.json`
process.env.AI_PROVIDER = "openai"
process.env.AI_MODEL = "gpt-4o"
const models = await loadFlattenedServerModels()
expect(models).toEqual([])
})
it("does not synthesize when AI_PROVIDER is unset", async () => {
process.env.AI_MODELS_CONFIG = ""
process.env.AI_MODELS_CONFIG_PATH = `non-existent-config-${Date.now()}.json`
delete process.env.AI_PROVIDER
process.env.AI_MODEL = "gpt-4o, gpt-4o-mini"
const models = await loadFlattenedServerModels()
expect(models).toEqual([])
})
it("preserves apiKeyEnv array in flattened models for load balancing", async () => {
const config: ServerModelsConfig = {
providers: [