@@ -49,18 +49,31 @@ export async function initApi(key: KeyConfig, chatModel: CHATMODEL) {
4949 messageStore : undefined ,
5050 getMessageById,
5151 }
52- // increase max token limit if use gpt-4
53- if ( model . toLowerCase ( ) . includes ( 'gpt-4' ) ) {
54- // if use 32k model
55- if ( model . toLowerCase ( ) . includes ( '32k' ) ) {
56- options . maxModelTokens = 32768
57- options . maxResponseTokens = 8192
58- }
59- else {
60- options . maxModelTokens = 8192
61- options . maxResponseTokens = 2048
62- }
63- }
52+
53+ // Set the token limits based on the model's type. This is because different models have different token limits.
54+ // The token limit includes the token count from both the message array sent and the model response.
55+ // 'gpt-35-turbo' has a limit of 4096 tokens, 'gpt-4' and 'gpt-4-32k' have limits of 8192 and 32768 tokens respectively.
56+
57+ // Check if the model type includes '16k'
58+ if ( model . toLowerCase ( ) . includes ( '16k' ) ) {
59+ // If it's a '16k' model, set the maxModelTokens to 16384 and maxResponseTokens to 4096
60+ options . maxModelTokens = 16384 ;
61+ options . maxResponseTokens = 4096 ;
62+ } else if ( model . toLowerCase ( ) . includes ( '32k' ) ) {
63+ // If it's a '32k' model, set the maxModelTokens to 32768 and maxResponseTokens to 8192
64+ options . maxModelTokens = 32768 ;
65+ options . maxResponseTokens = 8192 ;
66+ } else if ( model . toLowerCase ( ) . includes ( 'gpt-4' ) ) {
67+ // If it's a 'gpt-4' model, set the maxModelTokens and maxResponseTokens to 8192 and 2048 respectively
68+ options . maxModelTokens = 8192 ;
69+ options . maxResponseTokens = 2048 ;
70+ } else {
71+ // If none of the above, use the default values, set the maxModelTokens and maxResponseTokens to 8192 and 2048 respectively
72+ options . maxModelTokens = 4096 ;
73+ options . maxResponseTokens = 1024 ;
74+ }
75+
76+
6477
6578 if ( isNotEmptyString ( OPENAI_API_BASE_URL ) )
6679 options . apiBaseUrl = `${ OPENAI_API_BASE_URL } /v1`
0 commit comments