Skip to content

Commit d01fabe

Browse files
authored
fix maximum token count (#553)
* fix maximum token count * fix maximum token count 1 * fix maximum token count 2 原来补全最多只有4096啊... * fix maximum token count 3 重新梳理一下逻辑 --------- Signed-off-by: San <zhujunsan@gmail.com>
1 parent 63a0f44 commit d01fabe

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

service/src/chatgpt/index.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,31 +57,44 @@ export async function initApi(key: KeyConfig, chatModel: string, maxContextCount
5757

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.
60-
// 'gpt-35-turbo' has a limit of 4096 tokens, 'gpt-4' and 'gpt-4-32k' have limits of 8192 and 32768 tokens respectively.
61-
// Check if the model type is GPT-4-turbo
62-
if (model.toLowerCase().includes('gpt-4o') || model.toLowerCase().includes('gpt-4-turbo') || model.toLowerCase().includes('1106-preview') || model.toLowerCase().includes('0125-preview')) {
63-
// If it's a 'gpt-4o'/'gpt-4-turbo'/'1106-preview'/'0125-preview' model, set the maxModelTokens to 128000
60+
61+
// Check if the model type is GPT-4-turbo or newer
62+
if (model.toLowerCase().includes('gpt-4o') || model.toLowerCase().includes('gpt-4-turbo') || model.toLowerCase().includes('-preview')) {
63+
// If it's a 'gpt-4o'/'gpt-4-turbo'/'xxxx-preview' model, set the maxModelTokens to 128000
6464
options.maxModelTokens = 128000
65-
options.maxResponseTokens = 32768
65+
options.maxResponseTokens = 4096
6666
}
67-
// Check if the model type includes '16k'
68-
if (model.toLowerCase().includes('16k')) {
69-
// If it's a '16k' model, set the maxModelTokens to 16384 and maxResponseTokens to 4096
70-
options.maxModelTokens = 16384
67+
else if (model.toLowerCase().includes('gpt-4')) {
68+
// If it's a 'gpt-4' model, set the maxModelTokens and maxResponseTokens to 8192 and 2048 respectively
69+
options.maxModelTokens = 8192
70+
options.maxResponseTokens = 2048
71+
}
72+
// Check if the model type includes 'gpt-3.5-turbo'
73+
else if (model.toLowerCase().includes('gpt-3.5-turbo-instruct') || model.toLowerCase().includes('gpt-3.5-turbo-0613')) {
74+
// If it's a old 'gpt-3.5-turbo' model, set the maxModelTokens to 4096 and maxResponseTokens to 1024
75+
options.maxModelTokens = 4096
76+
options.maxResponseTokens = 1024
77+
}
78+
// Check if the model type includes 'gpt-3.5-turbo'
79+
else if (model.toLowerCase().includes('gpt-3.5-turbo')) {
80+
// If it's a 'gpt-3.5-turbo' model, set the maxModelTokens to 16385 and maxResponseTokens to 4096
81+
options.maxModelTokens = 16385
7182
options.maxResponseTokens = 4096
7283
}
84+
// Check if the model type includes '32k'
7385
else if (model.toLowerCase().includes('32k')) {
7486
// If it's a '32k' model, set the maxModelTokens to 32768 and maxResponseTokens to 8192
7587
options.maxModelTokens = 32768
7688
options.maxResponseTokens = 8192
7789
}
78-
else if (model.toLowerCase().includes('gpt-4')) {
79-
// If it's a 'gpt-4' model, set the maxModelTokens and maxResponseTokens to 8192 and 2048 respectively
80-
options.maxModelTokens = 8192
81-
options.maxResponseTokens = 2048
90+
// Check if the model type includes '16k'
91+
else if (model.toLowerCase().includes('16k')) {
92+
// If it's a '16k' model, set the maxModelTokens to 16385 and maxResponseTokens to 4096
93+
options.maxModelTokens = 16385
94+
options.maxResponseTokens = 4096
8295
}
96+
// If none of the above, use the default values
8397
else {
84-
// If none of the above, use the default values, set the maxModelTokens and maxResponseTokens to 8192 and 2048 respectively
8598
options.maxModelTokens = 4096
8699
options.maxResponseTokens = 1024
87100
}

0 commit comments

Comments
 (0)