-
Notifications
You must be signed in to change notification settings - Fork 6.9k
feat: add openai model info configuration #551
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
tibo-openai
merged 11 commits into
openai:main
from
chunterb:feat/model-info-handling-part-1
Apr 22, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9a20ed9
feat: dedicated file for supported model info
chunterb 85c669f
feat: use model info config to calculate max context length for model
chunterb e7e53df
test: make sure calcs are correct for model info config usage
chunterb 160e7a7
test: basic structure for model info config
chunterb f83e278
fix: eslint warnings
chunterb b12ef50
Merge branch 'main' into feat/model-info-handling-part-1
chunterb 585b045
chore: format code with prettier
chunterb 2405d66
Merge branch 'main' into feat/model-info-handling-part-1
chunterb be055fc
test: context window fallback for models not in registry
chunterb a424f2e
feat: keep fallback for models not in registry
chunterb e0f6ed1
fix: cleanup model labels
chunterb 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,198 @@ | ||
| export type ModelInfo = { | ||
| /** The human-readable label for this model */ | ||
| label: string; | ||
| /** The max context window size for this model */ | ||
| maxContextLength: number; | ||
| }; | ||
|
|
||
| export type SupportedModelId = keyof typeof openAiModelInfo; | ||
| export const openAiModelInfo = { | ||
| "o1-pro-2025-03-19": { | ||
| label: "o1 Pro (2025-03-19)", | ||
| maxContextLength: 200000, | ||
| }, | ||
| "o3": { | ||
| label: "o3", | ||
| maxContextLength: 200000, | ||
| }, | ||
| "o3-2025-04-16": { | ||
| label: "o3 (2025-04-16)", | ||
| maxContextLength: 200000, | ||
| }, | ||
| "o4-mini": { | ||
| label: "o4 Mini", | ||
| maxContextLength: 200000, | ||
| }, | ||
| "gpt-4.1-nano": { | ||
| label: "GPT-4.1 Nano", | ||
| maxContextLength: 1000000, | ||
| }, | ||
| "gpt-4.1-nano-2025-04-14": { | ||
| label: "GPT-4.1 Nano (2025-04-14)", | ||
| maxContextLength: 1000000, | ||
| }, | ||
| "o4-mini-2025-04-16": { | ||
| label: "o4 Mini (2025-04-16)", | ||
| maxContextLength: 200000, | ||
| }, | ||
| "gpt-4": { | ||
| label: "GPT-4", | ||
| maxContextLength: 8192, | ||
| }, | ||
| "o1-preview-2024-09-12": { | ||
| label: "o1 Preview (2024-09-12)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4.1-mini": { | ||
| label: "GPT-4.1 Mini", | ||
| maxContextLength: 1000000, | ||
| }, | ||
| "gpt-3.5-turbo-instruct-0914": { | ||
| label: "GPT-3.5 Turbo Instruct (0914)", | ||
| maxContextLength: 4096, | ||
| }, | ||
| "gpt-4o-mini-search-preview": { | ||
| label: "GPT-4o Mini Search Preview", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4.1-mini-2025-04-14": { | ||
| label: "GPT-4.1 Mini (2025-04-14)", | ||
| maxContextLength: 1000000, | ||
| }, | ||
| "chatgpt-4o-latest": { | ||
| label: "ChatGPT-4o Latest", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-3.5-turbo-1106": { | ||
| label: "GPT-3.5 Turbo (1106)", | ||
| maxContextLength: 16385, | ||
| }, | ||
| "gpt-4o-search-preview": { | ||
| label: "GPT-4o Search Preview", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4-turbo": { | ||
| label: "GPT-4 Turbo", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4o-realtime-preview-2024-12-17": { | ||
| label: "GPT-4o Realtime Preview (2024-12-17)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-3.5-turbo-instruct": { | ||
| label: "GPT-3.5 Turbo Instruct", | ||
| maxContextLength: 4096, | ||
| }, | ||
| "gpt-3.5-turbo": { | ||
| label: "GPT-3.5 Turbo", | ||
| maxContextLength: 16385, | ||
| }, | ||
| "gpt-4-turbo-preview": { | ||
| label: "GPT-4 Turbo Preview", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4o-mini-search-preview-2025-03-11": { | ||
| label: "GPT-4o Mini Search Preview (2025-03-11)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4-0125-preview": { | ||
| label: "GPT-4 (0125) Preview", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4o-2024-11-20": { | ||
| label: "GPT-4o (2024-11-20)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "o3-mini": { | ||
| label: "o3 Mini", | ||
| maxContextLength: 200000, | ||
| }, | ||
| "gpt-4o-2024-05-13": { | ||
| label: "GPT-4o (2024-05-13)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4-turbo-2024-04-09": { | ||
| label: "GPT-4 Turbo (2024-04-09)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-3.5-turbo-16k": { | ||
| label: "GPT-3.5 Turbo 16k", | ||
| maxContextLength: 16385, | ||
| }, | ||
| "o3-mini-2025-01-31": { | ||
| label: "o3 Mini (2025-01-31)", | ||
| maxContextLength: 200000, | ||
| }, | ||
| "o1-preview": { | ||
| label: "o1 Preview", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "o1-2024-12-17": { | ||
| label: "o1 (2024-12-17)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4-0613": { | ||
| label: "GPT-4 (0613)", | ||
| maxContextLength: 8192, | ||
| }, | ||
| "o1": { | ||
| label: "o1", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "o1-pro": { | ||
| label: "o1 Pro", | ||
| maxContextLength: 200000, | ||
| }, | ||
| "gpt-4.5-preview": { | ||
| label: "GPT-4.5 Preview", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4.5-preview-2025-02-27": { | ||
| label: "GPT-4.5 Preview (2025-02-27)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4o-search-preview-2025-03-11": { | ||
| label: "GPT-4o Search Preview (2025-03-11)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4o": { | ||
| label: "GPT-4o", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4o-mini": { | ||
| label: "GPT-4o Mini", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4o-2024-08-06": { | ||
| label: "GPT-4o (2024-08-06)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4.1": { | ||
| label: "GPT-4.1", | ||
| maxContextLength: 1000000, | ||
| }, | ||
| "gpt-4.1-2025-04-14": { | ||
| label: "GPT-4.1 (2025-04-14)", | ||
| maxContextLength: 1000000, | ||
| }, | ||
| "gpt-4o-mini-2024-07-18": { | ||
| label: "GPT-4o Mini (2024-07-18)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "o1-mini": { | ||
| label: "o1 Mini", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-3.5-turbo-0125": { | ||
| label: "GPT-3.5 Turbo (0125)", | ||
| maxContextLength: 16385, | ||
| }, | ||
| "o1-mini-2024-09-12": { | ||
| label: "o1 Mini (2024-09-12)", | ||
| maxContextLength: 128000, | ||
| }, | ||
| "gpt-4-1106-preview": { | ||
| label: "GPT-4 (1106) Preview", | ||
| maxContextLength: 128000, | ||
| }, | ||
| } as const satisfies Record<string, ModelInfo>; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import { openAiModelInfo } from "../src/utils/model-info"; | ||
|
|
||
| describe("Model Info", () => { | ||
| test("supportedModelInfo contains expected models", () => { | ||
| expect(openAiModelInfo).toHaveProperty("gpt-4o"); | ||
| expect(openAiModelInfo).toHaveProperty("gpt-4.1"); | ||
| expect(openAiModelInfo).toHaveProperty("o3"); | ||
| }); | ||
|
|
||
| test("model info entries have required properties", () => { | ||
| Object.entries(openAiModelInfo).forEach(([_, info]) => { | ||
| expect(info).toHaveProperty("label"); | ||
| expect(info).toHaveProperty("maxContextLength"); | ||
| expect(typeof info.label).toBe("string"); | ||
| expect(typeof info.maxContextLength).toBe("number"); | ||
| }); | ||
| }); | ||
| }); |
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,78 @@ | ||
| import { describe, test, expect } from "vitest"; | ||
| import { | ||
| calculateContextPercentRemaining, | ||
| maxTokensForModel, | ||
| } from "../src/utils/model-utils"; | ||
| import { openAiModelInfo } from "../src/utils/model-info"; | ||
| import type { ResponseItem } from "openai/resources/responses/responses.mjs"; | ||
|
|
||
| describe("Model Utils", () => { | ||
| describe("openAiModelInfo", () => { | ||
| test("model info entries have required properties", () => { | ||
| Object.entries(openAiModelInfo).forEach(([_, info]) => { | ||
| expect(info).toHaveProperty("label"); | ||
| expect(info).toHaveProperty("maxContextLength"); | ||
| expect(typeof info.label).toBe("string"); | ||
| expect(typeof info.maxContextLength).toBe("number"); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("maxTokensForModel", () => { | ||
| test("returns correct token limit for known models", () => { | ||
| const knownModel = "gpt-4o"; | ||
| const expectedTokens = openAiModelInfo[knownModel].maxContextLength; | ||
| expect(maxTokensForModel(knownModel)).toBe(expectedTokens); | ||
| }); | ||
|
|
||
| test("handles models with size indicators in their names", () => { | ||
| expect(maxTokensForModel("some-model-32k")).toBe(32000); | ||
| expect(maxTokensForModel("some-model-16k")).toBe(16000); | ||
| expect(maxTokensForModel("some-model-8k")).toBe(8000); | ||
| expect(maxTokensForModel("some-model-4k")).toBe(4000); | ||
| }); | ||
|
|
||
| test("defaults to 128k for unknown models not in the registry", () => { | ||
| expect(maxTokensForModel("completely-unknown-model")).toBe(128000); | ||
| }); | ||
| }); | ||
|
|
||
| describe("calculateContextPercentRemaining", () => { | ||
| test("returns 100% for empty items", () => { | ||
| const result = calculateContextPercentRemaining([], "gpt-4o"); | ||
| expect(result).toBe(100); | ||
| }); | ||
|
|
||
| test("calculates percentage correctly for non-empty items", () => { | ||
| const mockItems: Array<ResponseItem> = [ | ||
| { | ||
| id: "test-id", | ||
| type: "message", | ||
| role: "user", | ||
| status: "completed", | ||
| content: [ | ||
| { | ||
| type: "input_text", | ||
| text: "A".repeat( | ||
| openAiModelInfo["gpt-4o"].maxContextLength * 0.25 * 4, | ||
| ), | ||
| }, | ||
| ], | ||
| } as ResponseItem, | ||
| ]; | ||
|
|
||
| const result = calculateContextPercentRemaining(mockItems, "gpt-4o"); | ||
| expect(result).toBeCloseTo(75, 0); | ||
| }); | ||
|
|
||
| test("handles models that are not in the registry", () => { | ||
| const mockItems: Array<ResponseItem> = []; | ||
|
|
||
| const result = calculateContextPercentRemaining( | ||
| mockItems, | ||
| "unknown-model", | ||
| ); | ||
| expect(result).toBe(100); | ||
| }); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.