@@ -18,6 +18,7 @@ import {resolveChatWrapper} from "../../chatWrappers/utils/resolveChatWrapper.js
18
18
import { GeneralChatWrapper } from "../../chatWrappers/GeneralChatWrapper.js" ;
19
19
import { TokenBias } from "../TokenBias.js" ;
20
20
import { safeEventCallback } from "../../utils/safeEventCallback.js" ;
21
+ import { pushAll } from "../../utils/pushAll.js" ;
21
22
import {
22
23
eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy
23
24
} from "./utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js" ;
@@ -1491,7 +1492,7 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
1491
1492
} )
1492
1493
. flat ( 1 ) ;
1493
1494
this . pendingTokens . length = 0 ;
1494
- this . pendingTokens . push ( ... newPendingTokens ) ;
1495
+ pushAll ( this . pendingTokens , newPendingTokens ) ;
1495
1496
this . removedStartTextToIgnore = true ;
1496
1497
}
1497
1498
}
@@ -1975,7 +1976,7 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
1975
1976
1976
1977
this . stopGenerationDetector . clearInProgressStops ( ) ;
1977
1978
this . customStopGenerationTriggersDetector . clearInProgressStops ( ) ;
1978
- this . pendingTokens . push ( ... this . streamRegulator . popFreeChunkTokens ( ) ) ;
1979
+ pushAll ( this . pendingTokens , this . streamRegulator . popFreeChunkTokens ( ) ) ;
1979
1980
1980
1981
const triggeredStops = this . functionSyntaxStartDetector . getTriggeredStops ( ) ;
1981
1982
const partiallyFreeTokens = this . streamRegulator . getPartiallyFreeChunk ( this . llamaChat . model . tokenizer ) ;
@@ -1984,15 +1985,15 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
1984
1985
partiallyFreeTokens ,
1985
1986
this . llamaChat . model . tokenizer
1986
1987
) ;
1987
- this . pendingTokens . push ( ... queuedTokensBeforeStopTrigger ) ;
1988
+ pushAll ( this . pendingTokens , queuedTokensBeforeStopTrigger ) ;
1988
1989
1989
1990
this . removeFoundStartIgnoreTextsFromPendingTokens ( true ) ;
1990
1991
1991
1992
if ( this . pendingTokens . length > 0 )
1992
1993
this . onToken ?.( this . pendingTokens . slice ( ) ) ;
1993
1994
1994
- this . res . push ( ... this . pendingTokens ) ;
1995
- this . contextWindowsRes . push ( ... this . pendingTokens ) ;
1995
+ pushAll ( this . res , this . pendingTokens ) ;
1996
+ pushAll ( this . contextWindowsRes , this . pendingTokens ) ;
1996
1997
this . pendingTokens . length = 0 ;
1997
1998
1998
1999
this . streamRegulator . clearQueue ( ) ;
@@ -2192,7 +2193,7 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
2192
2193
this . customStopGenerationTriggersDetector . clearTriggeredStops ( ) ;
2193
2194
this . customStopGenerationTriggersDetector . clearInProgressStops ( ) ;
2194
2195
2195
- this . pendingTokens . push ( ... this . streamRegulator . popFreeChunkTokens ( ) ) ;
2196
+ pushAll ( this . pendingTokens , this . streamRegulator . popFreeChunkTokens ( ) ) ;
2196
2197
2197
2198
const triggeredStops = this . functionSyntaxStartDetector . getTriggeredStops ( ) ;
2198
2199
const partiallyFreeTokens = this . streamRegulator . getPartiallyFreeChunk ( this . llamaChat . model . tokenizer ) ;
@@ -2202,7 +2203,7 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
2202
2203
partiallyFreeTokens ,
2203
2204
this . llamaChat . model . tokenizer
2204
2205
) ;
2205
- this . pendingTokens . push ( ... queuedTokensBeforeStopTrigger ) ;
2206
+ pushAll ( this . pendingTokens , queuedTokensBeforeStopTrigger ) ;
2206
2207
2207
2208
const firstRemainingGenerationAfterStop = StopGenerationDetector . getFirstRemainingGenerationAfterStop ( triggeredStops ) ;
2208
2209
const remainingTextAfterStop = StopGenerationDetector . detokenizeRemainingGeneration (
@@ -2228,7 +2229,7 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
2228
2229
}
2229
2230
2230
2231
public popStreamRegulatorFreeTokens ( ) {
2231
- this . pendingTokens . push ( ... this . streamRegulator . popFreeChunkTokens ( ) ) ;
2232
+ pushAll ( this . pendingTokens , this . streamRegulator . popFreeChunkTokens ( ) ) ;
2232
2233
}
2233
2234
2234
2235
public handleStopGenerationTrigger ( lastHistoryItemType : "user" | "model" ) {
@@ -2237,7 +2238,7 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
2237
2238
) {
2238
2239
this . stopGenerationDetector . clearInProgressStops ( ) ;
2239
2240
this . customStopGenerationTriggersDetector . clearInProgressStops ( ) ;
2240
- this . pendingTokens . push ( ... this . streamRegulator . popFreeChunkTokens ( ) ) ;
2241
+ pushAll ( this . pendingTokens , this . streamRegulator . popFreeChunkTokens ( ) ) ;
2241
2242
2242
2243
const triggeredStops = this . stopGenerationDetector . hasTriggeredStops
2243
2244
? this . stopGenerationDetector . getTriggeredStops ( )
@@ -2250,7 +2251,7 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
2250
2251
partiallyFreeTokens ,
2251
2252
this . llamaChat . model . tokenizer
2252
2253
) ;
2253
- this . pendingTokens . push ( ... queuedTokensBeforeStopTrigger ) ;
2254
+ pushAll ( this . pendingTokens , queuedTokensBeforeStopTrigger ) ;
2254
2255
2255
2256
const firstRemainingGenerationAfterStop = StopGenerationDetector . getFirstRemainingGenerationAfterStop ( triggeredStops ) ;
2256
2257
@@ -2259,8 +2260,8 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
2259
2260
if ( this . pendingTokens . length > 0 )
2260
2261
this . onToken ?.( this . pendingTokens . slice ( ) ) ;
2261
2262
2262
- this . res . push ( ... this . pendingTokens ) ;
2263
- this . contextWindowsRes . push ( ... this . pendingTokens ) ;
2263
+ pushAll ( this . res , this . pendingTokens ) ;
2264
+ pushAll ( this . contextWindowsRes , this . pendingTokens ) ;
2264
2265
this . pendingTokens . length = 0 ;
2265
2266
2266
2267
let modelResponse = this . llamaChat . model . detokenize ( this . res ) ;
@@ -2336,8 +2337,8 @@ class GenerateResponseState<const Functions extends ChatModelFunctions | undefin
2336
2337
2337
2338
if ( this . pendingTokens . length > 0 ) {
2338
2339
this . onToken ?.( this . pendingTokens . slice ( ) ) ;
2339
- this . res . push ( ... this . pendingTokens ) ;
2340
- this . contextWindowsRes . push ( ... this . pendingTokens ) ;
2340
+ pushAll ( this . res , this . pendingTokens ) ;
2341
+ pushAll ( this . contextWindowsRes , this . pendingTokens ) ;
2341
2342
this . pendingTokens . length = 0 ;
2342
2343
}
2343
2344
}
0 commit comments