fix: 改进滑动窗口保留最近消息 + 添加北京时间注释
Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
parent
e7723e6444
commit
203ecee955
|
|
@ -8,8 +8,8 @@ name: Generate Session Summary for Notion
|
|||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '50 23 * * *'
|
||||
- cron: '50 14 * * *'
|
||||
- cron: '50 23 * * *' # 07:50 Beijing Time
|
||||
- cron: '50 14 * * *' # 22:50 Beijing Time
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
|
|
|
|||
|
|
@ -1579,14 +1579,14 @@ function trimMessagesForContext(sysMsgs, msgs, isGuest){
|
|||
const reserve = CONTEXT_CONFIG.systemPromptReserve;
|
||||
const sysTokens = sysMsgs.reduce((n,m)=>n+estimateTokens(m.content),0);
|
||||
const budget = limit - Math.max(sysTokens, reserve);
|
||||
if(budget<=0) return sysMsgs;
|
||||
|
||||
// 从最新消息向前累加,滑动窗口裁剪最早消息
|
||||
// 预算不足时至少保留最近一条用户消息
|
||||
const kept=[];
|
||||
let used=0;
|
||||
for(let i=msgs.length-1;i>=0;i--){
|
||||
const t=estimateTokens(msgs[i].content);
|
||||
if(used+t>budget) break;
|
||||
if(used+t>budget && kept.length>0) break;
|
||||
kept.unshift(msgs[i]);
|
||||
used+=t;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue