Repository navigation
fix(playground): filter playground models by node prefix so custom-endpoint models appear (#3505) #3581
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
fix(playground): filter playground models by node prefix so custom-endpoint models appear (#3505) #3581
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { filterModelsByProvider } from "../../src/app/(dashboard)/dashboard/translator/hooks/useAvailableModels.tsx"; | ||
|
|
||
| // Regression for #3505: the playground model selector filtered the /v1/models list by the | ||
| // provider OPTION VALUE (a compatible provider's node id, e.g. "openai-compatible-<uuid>"), | ||
| // but the catalog emits compatible-provider models under the node's custom PREFIX | ||
| // (e.g. "myprefix/gpt-4o"). So `startsWith("openai-compatible-<uuid>/")` matched nothing and | ||
| // the selector showed "None"/"-". The fix passes the node prefix as the filter key. This locks | ||
| // the filter behaviour: given the right key (the prefix), the models surface. | ||
|
|
||
| test("#3505 filters models by a custom node prefix (the catalog's model namespace)", () => { | ||
| const all = ["myprefix/gpt-4o", "myprefix/llama-3", "openai/gpt-4o", "anthropic/claude-opus-4-8"]; | ||
| assert.deepEqual(filterModelsByProvider(all, "myprefix"), ["myprefix/gpt-4o", "myprefix/llama-3"]); | ||
| }); | ||
|
|
||
| test("#3505 a UUID-style node id (the old wrong key) matches nothing → empty (the bug)", () => { | ||
| const all = ["myprefix/gpt-4o", "openai/gpt-4o"]; | ||
| assert.deepEqual(filterModelsByProvider(all, "openai-compatible-1234-uuid"), []); | ||
| }); | ||
|
|
||
| test("#3505 built-in provider filtering still works", () => { | ||
| const all = ["openai/gpt-4o", "openai/gpt-4o-mini", "anthropic/claude-opus-4-8"]; | ||
| assert.deepEqual(filterModelsByProvider(all, "openai"), ["openai/gpt-4o", "openai/gpt-4o-mini"]); | ||
| }); | ||
|
|
||
| test("#3505 an exact bare match is included; no provider returns all", () => { | ||
| assert.deepEqual(filterModelsByProvider(["auto", "openai/gpt-4o"], "auto"), ["auto"]); | ||
| assert.deepEqual(filterModelsByProvider(["a", "b"], undefined), ["a", "b"]); | ||
| }); | ||
|
Comment on lines
+1
to
+30
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. Since the project standardizes on Vitest (as indicated by import { describe, it, expect } from "vitest";
import { filterModelsByProvider } from "../../src/app/(dashboard)/dashboard/translator/hooks/useAvailableModels";
// Regression for #3505: the playground model selector filtered the /v1/models list by the
// provider OPTION VALUE (a compatible provider's node id, e.g. "openai-compatible-<uuid>"),
// but the catalog emits compatible-provider models under the node's custom PREFIX
// (e.g. "myprefix/gpt-4o"). So `startsWith("openai-compatible-<uuid>/")` matched nothing and
// the selector showed "None"/"-". The fix passes the node prefix as the filter key. This locks
// the filter behaviour: given the right key (the prefix), the models surface.
describe("#3505 playground model filter", () => {
it("filters models by a custom node prefix (the catalog's model namespace)", () => {
const all = ["myprefix/gpt-4o", "myprefix/llama-3", "openai/gpt-4o", "anthropic/claude-opus-4-8"];
expect(filterModelsByProvider(all, "myprefix")).toEqual(["myprefix/gpt-4o", "myprefix/llama-3"]);
});
it("a UUID-style node id (the old wrong key) matches nothing → empty (the bug)", () => {
const all = ["myprefix/gpt-4o", "openai/gpt-4o"];
expect(filterModelsByProvider(all, "openai-compatible-1234-uuid")).toEqual([]);
});
it("built-in provider filtering still works", () => {
const all = ["openai/gpt-4o", "openai/gpt-4o-mini", "anthropic/claude-opus-4-8"];
expect(filterModelsByProvider(all, "openai")).toEqual(["openai/gpt-4o", "openai/gpt-4o-mini"]);
});
it("an exact bare match is included; no provider returns all", () => {
expect(filterModelsByProvider(["auto", "openai/gpt-4o"], "auto")).toEqual(["auto"]);
expect(filterModelsByProvider(["a", "b"], undefined)).toEqual(["a", "b"]);
});
}); |
||
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.
Use optional chaining (
providerOptions?.find) to safely handle cases whereproviderOptionsmight be null or undefined (e.g., during initial load or error states). This aligns with defensive programming practices to prevent runtimeTypeErrorcrashes.