@@ -68,6 +68,8 @@ class OpenAIClient extends BaseClient {
68
68
69
69
/** @type {OpenAIUsageMetadata | undefined } */
70
70
this . usage ;
71
+ /** @type {boolean|undefined } */
72
+ this . isO1Model ;
71
73
}
72
74
73
75
// TODO: PluginsClient calls this 3x, unneeded
@@ -98,6 +100,8 @@ class OpenAIClient extends BaseClient {
98
100
this . options . modelOptions ,
99
101
) ;
100
102
103
+ this . isO1Model = / \b o 1 \b / i. test ( this . modelOptions . model ) ;
104
+
101
105
this . defaultVisionModel = this . options . visionModel ?? 'gpt-4-vision-preview' ;
102
106
if ( typeof this . options . attachments ?. then === 'function' ) {
103
107
this . options . attachments . then ( ( attachments ) => this . checkVisionRequest ( attachments ) ) ;
@@ -545,8 +549,7 @@ class OpenAIClient extends BaseClient {
545
549
promptPrefix = this . augmentedPrompt + promptPrefix ;
546
550
}
547
551
548
- const isO1Model = / \b o 1 \b / i. test ( this . modelOptions . model ) ;
549
- if ( promptPrefix && ! isO1Model ) {
552
+ if ( promptPrefix && this . isO1Model !== true ) {
550
553
promptPrefix = `Instructions:\n${ promptPrefix . trim ( ) } ` ;
551
554
instructions = {
552
555
role : 'system' ,
@@ -575,7 +578,7 @@ class OpenAIClient extends BaseClient {
575
578
} ;
576
579
577
580
/** EXPERIMENTAL */
578
- if ( promptPrefix && isO1Model ) {
581
+ if ( promptPrefix && this . isO1Model === true ) {
579
582
const lastUserMessageIndex = payload . findLastIndex ( ( message ) => message . role === 'user' ) ;
580
583
if ( lastUserMessageIndex !== - 1 ) {
581
584
payload [
@@ -1227,6 +1230,11 @@ ${convo}
1227
1230
opts . defaultHeaders = { ...opts . defaultHeaders , 'api-key' : this . apiKey } ;
1228
1231
}
1229
1232
1233
+ if ( this . isO1Model === true && modelOptions . max_tokens != null ) {
1234
+ modelOptions . max_completion_tokens = modelOptions . max_tokens ;
1235
+ delete modelOptions . max_tokens ;
1236
+ }
1237
+
1230
1238
if ( process . env . OPENAI_ORGANIZATION ) {
1231
1239
opts . organization = process . env . OPENAI_ORGANIZATION ;
1232
1240
}
0 commit comments