-
Notifications
You must be signed in to change notification settings - Fork 206
refactor(types): use canonical identifiers for default models #991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
WebMad
wants to merge
4
commits into
Zoo-Code-Org:main
Choose a base branch
from
WebMad:feat/954-provider-default-model-identifiers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−37
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0d88679
refactor(types): use canonical identifiers for default models
WebMad c1bcbd5
test(types): cover international ZAI default
WebMad a10d116
refactor(types): name absent provider default
WebMad 64a0508
test(types): cover defaults preserved during rebase
WebMad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
packages/types/src/__tests__/provider-default-model.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import type { ProviderName } from "../provider-settings.js" | ||
|
|
||
| vi.mock("../provider-identifiers.js", async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import("../provider-identifiers.js")>() | ||
|
|
||
| return { | ||
| ...actual, | ||
| providerIdentifiers: { | ||
| ...actual.providerIdentifiers, | ||
| openrouter: "canonical-openrouter-test-value", | ||
| }, | ||
| } | ||
| }) | ||
|
|
||
| import { providerIdentifiers } from "../provider-identifiers.js" | ||
| import { | ||
| anthropicDefaultModelId, | ||
| getProviderDefaultModelId, | ||
| internationalZAiDefaultModelId, | ||
| kimiCodeDefaultModelId, | ||
| mainlandZAiDefaultModelId, | ||
| openRouterDefaultModelId, | ||
| vscodeLlmDefaultModelId, | ||
| zooGatewayDefaultModelId, | ||
| } from "../providers/index.js" | ||
|
|
||
| describe("getProviderDefaultModelId", () => { | ||
| it("selects a static default through the canonical provider identifier", () => { | ||
| expect(getProviderDefaultModelId(providerIdentifiers.openrouter as ProviderName)).toBe(openRouterDefaultModelId) | ||
| }) | ||
|
|
||
| it("triangulates static selection with another provider category", () => { | ||
| expect(getProviderDefaultModelId(providerIdentifiers.vscodeLm)).toBe(vscodeLlmDefaultModelId) | ||
| }) | ||
|
|
||
| it.each([ | ||
| [providerIdentifiers.kimiCode, kimiCodeDefaultModelId], | ||
| [providerIdentifiers.zooGateway, zooGatewayDefaultModelId], | ||
| ])("preserves the %s default added on main", (provider, expectedModelId) => { | ||
| expect(getProviderDefaultModelId(provider)).toBe(expectedModelId) | ||
| }) | ||
|
|
||
| it("preserves region-dependent defaults", () => { | ||
| expect(getProviderDefaultModelId(providerIdentifiers.zai, { isChina: true })).toBe(mainlandZAiDefaultModelId) | ||
| expect(getProviderDefaultModelId(providerIdentifiers.zai)).toBe(internationalZAiDefaultModelId) | ||
| }) | ||
|
|
||
| it.each([providerIdentifiers.openai, providerIdentifiers.ollama, providerIdentifiers.lmstudio])( | ||
| "returns an empty default for custom or locally selected models from %s", | ||
| (provider) => { | ||
| expect(getProviderDefaultModelId(provider)).toBe("") | ||
| }, | ||
| ) | ||
|
|
||
| it.each([providerIdentifiers.anthropic, providerIdentifiers.geminiCli, providerIdentifiers.fakeAi])( | ||
| "preserves the Anthropic fallback for %s", | ||
| (provider) => { | ||
| expect(getProviderDefaultModelId(provider)).toBe(anthropicDefaultModelId) | ||
| }, | ||
| ) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,9 @@ import { zooGatewayDefaultModelId } from "./zoo-gateway.js" | |
|
|
||
| // Import the ProviderName type from provider-settings to avoid duplication | ||
| import type { ProviderName } from "../provider-settings.js" | ||
| import { providerIdentifiers } from "../provider-identifiers.js" | ||
|
|
||
| const NO_DEFAULT_MODEL_ID = "" | ||
|
|
||
| /** | ||
| * Get the default model ID for a given provider. | ||
|
|
@@ -73,71 +76,70 @@ export function getProviderDefaultModelId( | |
| options: { isChina?: boolean } = { isChina: false }, | ||
| ): string { | ||
| switch (provider) { | ||
| case "openrouter": | ||
| case providerIdentifiers.openrouter: | ||
| return openRouterDefaultModelId | ||
| case "requesty": | ||
| case providerIdentifiers.requesty: | ||
| return requestyDefaultModelId | ||
| case "litellm": | ||
| case providerIdentifiers.litellm: | ||
| return litellmDefaultModelId | ||
| case "xai": | ||
| case providerIdentifiers.xai: | ||
| return xaiDefaultModelId | ||
| case "baseten": | ||
| case providerIdentifiers.baseten: | ||
| return basetenDefaultModelId | ||
| case "bedrock": | ||
| case providerIdentifiers.bedrock: | ||
| return bedrockDefaultModelId | ||
| case "vertex": | ||
| case providerIdentifiers.vertex: | ||
| return vertexDefaultModelId | ||
| case "gemini": | ||
| case providerIdentifiers.gemini: | ||
| return geminiDefaultModelId | ||
| case "deepseek": | ||
| case providerIdentifiers.deepseek: | ||
| return deepSeekDefaultModelId | ||
| case "moonshot": | ||
| case providerIdentifiers.moonshot: | ||
| return moonshotDefaultModelId | ||
| case "minimax": | ||
| case providerIdentifiers.minimax: | ||
| return minimaxDefaultModelId | ||
| case "mimo": | ||
| case providerIdentifiers.mimo: | ||
| return mimoDefaultModelId | ||
| case "zai": | ||
| case providerIdentifiers.zai: | ||
| return options?.isChina ? mainlandZAiDefaultModelId : internationalZAiDefaultModelId | ||
| case "openai-native": | ||
| case providerIdentifiers.openaiNative: | ||
| // TODO(#992): Replace this stale fallback with openAiNativeDefaultModelId. | ||
| return "gpt-4o" // Based on openai-native patterns | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this use |
||
| case "openai-codex": | ||
| case providerIdentifiers.openaiCodex: | ||
| return openAiCodexDefaultModelId | ||
| case "mistral": | ||
| case providerIdentifiers.mistral: | ||
| return mistralDefaultModelId | ||
| case "openai": | ||
| return "" // OpenAI provider uses custom model configuration | ||
| case "ollama": | ||
| return "" // Ollama uses dynamic model selection | ||
| case "lmstudio": | ||
| return "" // LMStudio uses dynamic model selection | ||
| case "vscode-lm": | ||
| case providerIdentifiers.openai: | ||
| case providerIdentifiers.ollama: | ||
| case providerIdentifiers.lmstudio: | ||
| return NO_DEFAULT_MODEL_ID | ||
| case providerIdentifiers.vscodeLm: | ||
| return vscodeLlmDefaultModelId | ||
| case "sambanova": | ||
| case providerIdentifiers.sambanova: | ||
| return sambaNovaDefaultModelId | ||
| case "fireworks": | ||
| case providerIdentifiers.fireworks: | ||
| return fireworksDefaultModelId | ||
| case "friendli": | ||
| case providerIdentifiers.friendli: | ||
| return friendliDefaultModelId | ||
| case "qwen-code": | ||
| case providerIdentifiers.qwenCode: | ||
| return qwenCodeDefaultModelId | ||
| case "poe": | ||
| case providerIdentifiers.poe: | ||
| return poeDefaultModelId | ||
| case "unbound": | ||
| case providerIdentifiers.unbound: | ||
| return unboundDefaultModelId | ||
| case "vercel-ai-gateway": | ||
| case providerIdentifiers.vercelAiGateway: | ||
| return vercelAiGatewayDefaultModelId | ||
| case "opencode-go": | ||
| case providerIdentifiers.opencodeGo: | ||
| return opencodeGoDefaultModelId | ||
| case "kenari": | ||
| case providerIdentifiers.kenari: | ||
| return kenariDefaultModelId | ||
| case "kimi-code": | ||
| case providerIdentifiers.kimiCode: | ||
| return kimiCodeDefaultModelId | ||
| case "zoo-gateway": | ||
| case providerIdentifiers.zooGateway: | ||
| return zooGatewayDefaultModelId | ||
| case "anthropic": | ||
| case "gemini-cli": | ||
| case "fake-ai": | ||
| case providerIdentifiers.anthropic: | ||
| case providerIdentifiers.geminiCli: | ||
| case providerIdentifiers.fakeAi: | ||
| default: | ||
| return anthropicDefaultModelId | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both
mainlandZAiDefaultModelIdandinternationalZAiDefaultModelIdare currently"glm-4.7", so swapping the ternary arms in the source would still pass these assertions. Worth addingexpect(mainlandZAiDefaultModelId).not.toBe(internationalZAiDefaultModelId)as a guard — or a comment explaining that the branch is intentionally untestable until the values diverge?