@@ -57,31 +57,44 @@ export async function initApi(key: KeyConfig, chatModel: string, maxContextCount
57
57
58
58
// Set the token limits based on the model's type. This is because different models have different token limits.
59
59
// 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
64
64
options . maxModelTokens = 128000
65
- options . maxResponseTokens = 32768
65
+ options . maxResponseTokens = 4096
66
66
}
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
71
82
options . maxResponseTokens = 4096
72
83
}
84
+ // Check if the model type includes '32k'
73
85
else if ( model . toLowerCase ( ) . includes ( '32k' ) ) {
74
86
// If it's a '32k' model, set the maxModelTokens to 32768 and maxResponseTokens to 8192
75
87
options . maxModelTokens = 32768
76
88
options . maxResponseTokens = 8192
77
89
}
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
82
95
}
96
+ // If none of the above, use the default values
83
97
else {
84
- // If none of the above, use the default values, set the maxModelTokens and maxResponseTokens to 8192 and 2048 respectively
85
98
options . maxModelTokens = 4096
86
99
options . maxResponseTokens = 1024
87
100
}
0 commit comments