@@ -73,21 +73,22 @@ class OpenAIClient extends BaseClient {
73
73
this . useOpenRouter = true ;
74
74
}
75
75
76
+ const { model } = this . modelOptions ;
77
+
76
78
this . isChatCompletion =
77
79
this . useOpenRouter ||
78
80
this . options . reverseProxyUrl ||
79
81
this . options . localAI ||
80
- this . modelOptions . model . startsWith ( 'gpt-' ) ;
82
+ model . includes ( 'gpt-' ) ;
81
83
this . isChatGptModel = this . isChatCompletion ;
82
- if ( this . modelOptions . model === 'text-davinci-003' ) {
84
+ if ( model . includes ( 'text-davinci-003' ) || model . includes ( 'instruct' ) ) {
83
85
this . isChatCompletion = false ;
84
86
this . isChatGptModel = false ;
85
87
}
86
88
const { isChatGptModel } = this ;
87
89
this . isUnofficialChatGptModel =
88
- this . modelOptions . model . startsWith ( 'text-chat' ) ||
89
- this . modelOptions . model . startsWith ( 'text-davinci-002-render' ) ;
90
- this . maxContextTokens = maxTokensMap [ this . modelOptions . model ] ?? 4095 ; // 1 less than maximum
90
+ model . startsWith ( 'text-chat' ) || model . startsWith ( 'text-davinci-002-render' ) ;
91
+ this . maxContextTokens = maxTokensMap [ model ] ?? 4095 ; // 1 less than maximum
91
92
this . maxResponseTokens = this . modelOptions . max_tokens || 1024 ;
92
93
this . maxPromptTokens =
93
94
this . options . maxPromptTokens || this . maxContextTokens - this . maxResponseTokens ;
@@ -168,8 +169,9 @@ class OpenAIClient extends BaseClient {
168
169
tokenizer = this . constructor . getTokenizer ( this . encoding , true , extendSpecialTokens ) ;
169
170
} else {
170
171
try {
171
- this . encoding = this . modelOptions . model ;
172
- tokenizer = this . constructor . getTokenizer ( this . modelOptions . model , true ) ;
172
+ const { model } = this . modelOptions ;
173
+ this . encoding = model . includes ( 'instruct' ) ? 'text-davinci-003' : model ;
174
+ tokenizer = this . constructor . getTokenizer ( this . encoding , true ) ;
173
175
} catch {
174
176
tokenizer = this . constructor . getTokenizer ( this . encoding , true ) ;
175
177
}
@@ -354,6 +356,8 @@ class OpenAIClient extends BaseClient {
354
356
if ( this . isChatCompletion ) {
355
357
token =
356
358
progressMessage . choices ?. [ 0 ] ?. delta ?. content ?? progressMessage . choices ?. [ 0 ] ?. text ;
359
+ } else {
360
+ token = progressMessage . choices ?. [ 0 ] ?. text ;
357
361
}
358
362
359
363
if ( ! token && this . useOpenRouter ) {
0 commit comments