Skip to content

Commit 054ad59

Browse files
committed
refactor: replace GPT-5 regex with simpler startsWith check
- Removed complex regex pattern for detecting GPT-5 models - Now using simple startsWith('gpt-5') check as requested - Updated tests to reflect the new behavior where any model starting with 'gpt-5' is treated as a GPT-5 model
1 parent 9b3baaa commit 054ad59

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/shared/__tests__/api.spec.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,22 +358,49 @@ describe("getModelMaxOutputTokens", () => {
358358
})
359359
})
360360

361-
test("should not match invalid GPT-5 model names", () => {
361+
test("should match any model starting with 'gpt-5'", () => {
362+
const gpt5Model: ModelInfo = {
363+
contextWindow: 400_000,
364+
maxTokens: 128_000,
365+
supportsPromptCache: true,
366+
}
367+
368+
// With startsWith, these will ALL be treated as GPT-5 models
369+
const gpt5ModelIds = [
370+
"gpt-5-turbo", // Now matches
371+
"gpt-5-", // Now matches
372+
"gpt-5-mini-turbo", // Now matches
373+
"gpt-5-anything", // Now matches
374+
]
375+
376+
gpt5ModelIds.forEach((modelId) => {
377+
const result = getModelMaxOutputTokens({
378+
modelId,
379+
model: gpt5Model,
380+
settings: {},
381+
format: "openai",
382+
})
383+
// Should be limited to GPT5_MAX_OUTPUT_TOKENS
384+
expect(result).toBe(GPT5_MAX_OUTPUT_TOKENS)
385+
})
386+
})
387+
388+
test("should not match models that don't start with 'gpt-5'", () => {
362389
const model: ModelInfo = {
363390
contextWindow: 128_000,
364391
maxTokens: 16_384,
365392
supportsPromptCache: true,
366393
}
367394

368395
// These should NOT be treated as GPT-5 models
369-
const invalidModelIds = [
370-
"gpt-5-turbo", // Invalid variant
371-
"gpt-50", // Different number
372-
"gpt-5-", // Incomplete
373-
"gpt-5-mini-turbo", // Invalid variant combination
396+
const nonGpt5ModelIds = [
397+
"gpt-4o", // GPT-4 model
398+
"gpt-6", // GPT-6 (hypothetical future model)
399+
"claude-3-5-sonnet", // Different model family
400+
"openai-gpt-5", // Doesn't start with "gpt-5"
374401
]
375402

376-
invalidModelIds.forEach((modelId) => {
403+
nonGpt5ModelIds.forEach((modelId) => {
377404
const result = getModelMaxOutputTokens({
378405
modelId,
379406
model,

src/shared/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const getModelMaxOutputTokens = ({
9898

9999
// Special handling for GPT-5 models to prevent context window overflow
100100
// GPT-5 models include: gpt-5, gpt-5-mini, gpt-5-nano, and dated variants
101-
const isGpt5Model = /^gpt-5(-mini|-nano)?(-\d{4}-\d{2}-\d{2})?$/i.test(modelId)
101+
const isGpt5Model = modelId.startsWith("gpt-5")
102102
if (isGpt5Model) {
103103
// Allow user override via settings, but cap at GPT5_MAX_OUTPUT_TOKENS
104104
const userMaxTokens = settings?.modelMaxTokens

0 commit comments

Comments
 (0)