-
Notifications
You must be signed in to change notification settings - Fork 6
fix: prettifyModel variable reference bug #30
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,75 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { prettifyModel } from "@/components/app/feed/ActivityCard"; | ||
|
|
||
| describe("prettifyModel", () => { | ||
| describe("Claude models", () => { | ||
| it("prettifies claude-opus-4 variants", () => { | ||
| expect(prettifyModel("claude-opus-4-20260301")).toBe("Claude Opus"); | ||
| expect(prettifyModel("claude-opus-4")).toBe("Claude Opus"); | ||
| }); | ||
|
|
||
| it("prettifies claude-sonnet-4 variants", () => { | ||
| expect(prettifyModel("claude-sonnet-4-20260301")).toBe("Claude Sonnet"); | ||
| expect(prettifyModel("claude-sonnet-4")).toBe("Claude Sonnet"); | ||
| }); | ||
|
|
||
| it("prettifies claude-haiku-4 variants", () => { | ||
| expect(prettifyModel("claude-haiku-4-20260301")).toBe("Claude Haiku"); | ||
| expect(prettifyModel("claude-haiku-4")).toBe("Claude Haiku"); | ||
| }); | ||
|
|
||
| it("handles legacy Claude model names via .includes()", () => { | ||
| expect(prettifyModel("anthropic/claude-3-opus")).toBe("Claude Opus"); | ||
| expect(prettifyModel("anthropic/claude-3-sonnet")).toBe("Claude Sonnet"); | ||
| expect(prettifyModel("anthropic/claude-3-haiku")).toBe("Claude Haiku"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("OpenAI models", () => { | ||
| it("prettifies GPT models preserving full name", () => { | ||
| expect(prettifyModel("gpt-5.3-codex")).toBe("GPT-5.3-Codex"); | ||
| expect(prettifyModel("gpt-4o")).toBe("GPT-4o"); | ||
| expect(prettifyModel("gpt-5")).toBe("GPT-5"); | ||
| }); | ||
|
|
||
| it("prettifies o3/o4 models", () => { | ||
| expect(prettifyModel("o3-mini")).toBe("o3"); | ||
| expect(prettifyModel("o4-mini")).toBe("o4"); | ||
| expect(prettifyModel("o3")).toBe("o3"); | ||
| expect(prettifyModel("o4")).toBe("o4"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("whitespace handling (the bug fix)", () => { | ||
| it("trims leading/trailing whitespace before matching", () => { | ||
| expect(prettifyModel(" claude-opus-4 ")).toBe("Claude Opus"); | ||
| expect(prettifyModel("\tclaude-sonnet-4\n")).toBe("Claude Sonnet"); | ||
| }); | ||
|
|
||
| it("trims whitespace for anchor-dependent patterns (o3/o4)", () => { | ||
| expect(prettifyModel(" o3-mini")).toBe("o3"); | ||
| expect(prettifyModel(" o4-mini")).toBe("o4"); | ||
| }); | ||
|
|
||
| it("trims whitespace for GPT patterns", () => { | ||
| expect(prettifyModel(" gpt-5.3-codex ")).toBe("GPT-5.3-Codex"); | ||
| }); | ||
|
|
||
| it("returns trimmed string for unknown models", () => { | ||
| expect(prettifyModel(" some-unknown-model ")).toBe("some-unknown-model"); | ||
| }); | ||
|
|
||
| it("trims whitespace for legacy .includes() fallbacks", () => { | ||
| expect(prettifyModel(" some-opus-variant ")).toBe("Claude Opus"); | ||
| expect(prettifyModel(" some-sonnet-variant ")).toBe("Claude Sonnet"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("unknown models", () => { | ||
| it("returns the model name as-is for unrecognized models", () => { | ||
| expect(prettifyModel("gemini-2.0-flash")).toBe("gemini-2.0-flash"); | ||
| expect(prettifyModel("qwen-2.5-coder")).toBe("qwen-2.5-coder"); | ||
| expect(prettifyModel("mistral-large")).toBe("mistral-large"); | ||
| }); | ||
| }); | ||
| }); |
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
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
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.
Make the legacy Claude fallback case-insensitive.
Lines 52-54 use case-sensitive
includes(), so values likeAnthropic/Claude-3-Opuswill miss the fallback even though the regex branches above are case-insensitive. Lowercasing once before these checks keeps the behavior consistent.💡 Proposed fix
export function prettifyModel(model: string): string { const normalized = model.trim(); + const normalizedLower = normalized.toLowerCase(); if (/claude-opus-4/i.test(normalized)) return "Claude Opus"; if (/claude-sonnet-4/i.test(normalized)) return "Claude Sonnet"; if (/claude-haiku-4/i.test(normalized)) return "Claude Haiku"; // Preserve full OpenAI model names (e.g. gpt-5.3-codex -> GPT-5.3-Codex) if (/^gpt-/i.test(normalized)) { return normalized .replace(/^gpt/i, "GPT") .replace(/-codex$/i, "-Codex"); } if (/^o4/i.test(normalized)) return "o4"; if (/^o3/i.test(normalized)) return "o3"; // Legacy: broader Claude matching - if (normalized.includes("opus")) return "Claude Opus"; - if (normalized.includes("sonnet")) return "Claude Sonnet"; - if (normalized.includes("haiku")) return "Claude Haiku"; + if (normalizedLower.includes("opus")) return "Claude Opus"; + if (normalizedLower.includes("sonnet")) return "Claude Sonnet"; + if (normalizedLower.includes("haiku")) return "Claude Haiku"; return normalized; }🤖 Prompt for AI Agents