File tree 1 file changed +7
-5
lines changed
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -370,28 +370,30 @@ export const useChatStore = create<ChatStore>()(
370
370
context . push ( memoryPrompt ) ;
371
371
}
372
372
373
- // get short term and unmemoried long term memory
373
+ // get short term and unmemorized long term memory
374
374
const shortTermMemoryMessageIndex = Math . max (
375
375
0 ,
376
376
n - modelConfig . historyMessageCount ,
377
377
) ;
378
378
const longTermMemoryMessageIndex = session . lastSummarizeIndex ;
379
- const mostRecentIndex = Math . max (
379
+
380
+ // try to concat history messages
381
+ const memoryStartIndex = Math . min (
380
382
shortTermMemoryMessageIndex ,
381
383
longTermMemoryMessageIndex ,
382
384
) ;
383
- const threshold = modelConfig . compressMessageLengthThreshold * 2 ;
385
+ const threshold = modelConfig . max_tokens ;
384
386
385
387
// get recent messages as many as possible
386
388
const reversedRecentMessages = [ ] ;
387
389
for (
388
390
let i = n - 1 , count = 0 ;
389
- i >= mostRecentIndex && count < threshold ;
391
+ i >= memoryStartIndex && count < threshold ;
390
392
i -= 1
391
393
) {
392
394
const msg = messages [ i ] ;
393
395
if ( ! msg || msg . isError ) continue ;
394
- count += msg . content . length ;
396
+ count += estimateTokenLength ( msg . content ) ;
395
397
reversedRecentMessages . push ( msg ) ;
396
398
}
397
399
You can’t perform that action at this time.
0 commit comments