Skip to content

Commit 17dedfc

Browse files
authored
fix: gpt-4.1 max model token (#588)
Signed-off-by: Bob Du <i@bobdu.cc>
1 parent 9b1aadd commit 17dedfc

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

service/src/chatgpt/index.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,20 @@ export async function initApi(key: KeyConfig, chatModel: string, maxContextCount
5858
// Set the token limits based on the model's type. This is because different models have different token limits.
5959
// The token limit includes the token count from both the message array sent and the model response.
6060

61-
// Check if the model type is GPT-4-turbo or newer
62-
if (model.toLowerCase().includes('gpt-4o-2024-08-06') || model.toLowerCase().includes('chatgpt-4o-latest')) {
63-
// 'gpt-4o-2024-08-06'/'chatgpt-4o-latest'
64-
options.maxModelTokens = 128000
65-
options.maxResponseTokens = 16384
61+
if (model.toLowerCase().includes('gpt-4.1')) {
62+
// https://platform.openai.com/docs/models/gpt-4.1
63+
options.maxModelTokens = 1047576
64+
options.maxResponseTokens = 32768
6665
}
67-
if (model.toLowerCase().includes('gpt-4o') || model.toLowerCase().includes('gpt-4-turbo') || model.toLowerCase().includes('-preview')) {
68-
// 'gpt-4o'/'gpt-4-turbo'/'xxxx-preview'
66+
else if (model.toLowerCase().includes('gpt-4o')) {
67+
// https://platform.openai.com/docs/models/gpt-4o
6968
options.maxModelTokens = 128000
70-
options.maxResponseTokens = 4096
71-
}
72-
else if (model.toLowerCase().includes('gpt-4')) {
73-
// 'gpt-4'
74-
options.maxModelTokens = 8192
75-
options.maxResponseTokens = 8192
76-
}
77-
else if (model.toLowerCase().includes('gpt-3.5-turbo-instruct')) {
78-
// 'gpt-3.5-turbo-instruct'
79-
options.maxModelTokens = 4096
80-
options.maxResponseTokens = 4096
81-
}
82-
else if (model.toLowerCase().includes('gpt-3.5-turbo')) {
83-
// 'gpt-3.5-turbo'
84-
options.maxModelTokens = 16385
85-
options.maxResponseTokens = 4096
69+
options.maxResponseTokens = 16384
8670
}
8771
// If none of the above, use the default values
8872
else {
89-
options.maxModelTokens = 4096
90-
options.maxResponseTokens = 1024
73+
options.maxModelTokens = 1047576
74+
options.maxResponseTokens = 32768
9175
}
9276

9377
if (isNotEmptyString(OPENAI_API_BASE_URL))

0 commit comments

Comments
 (0)