feat: 新建会话时自动释放显存,清理模型上下文

This commit is contained in:
thzxx
2026-04-05 00:01:35 +08:00
parent 292e84651c
commit 08cd0de89b
+11
View File
@@ -59,6 +59,17 @@ async function startNewSession() {
await db.saveSession(currentSession); await db.saveSession(currentSession);
} }
// 释放显存,清理模型上下文
const api = state.get(KEYS.API);
const model = currentSession?.model || state.get('_defaultModel', '');
if (api && model) {
try {
await api.chat({ model, messages: [], keep_alive: 0 });
} catch (e) {
console.warn('[App] 释放显存失败:', e);
}
}
const session = createNewSession(); const session = createNewSession();
state.set(KEYS.CURRENT_SESSION, session); state.set(KEYS.CURRENT_SESSION, session);
state.set(KEYS.IS_HISTORY_VIEW, false); state.set(KEYS.IS_HISTORY_VIEW, false);