forked from XiaoMo/ChatGPT-Next-Web
fixup
This commit is contained in:
parent
d75b7d49b8
commit
ad1c8ffe21
@ -102,7 +102,7 @@ export function limitNumber(
|
|||||||
x: number,
|
x: number,
|
||||||
min: number,
|
min: number,
|
||||||
max: number,
|
max: number,
|
||||||
defaultValue: number
|
defaultValue: number,
|
||||||
) {
|
) {
|
||||||
if (typeof x !== "number" || isNaN(x)) {
|
if (typeof x !== "number" || isNaN(x)) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@ -217,7 +217,7 @@ interface ChatStore {
|
|||||||
updateMessage: (
|
updateMessage: (
|
||||||
sessionIndex: number,
|
sessionIndex: number,
|
||||||
messageIndex: number,
|
messageIndex: number,
|
||||||
updater: (message?: Message) => void
|
updater: (message?: Message) => void,
|
||||||
) => void;
|
) => void;
|
||||||
resetSession: () => void;
|
resetSession: () => void;
|
||||||
getMessagesWithMemory: () => Message[];
|
getMessagesWithMemory: () => Message[];
|
||||||
@ -345,12 +345,12 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
.slice(0, index)
|
.slice(0, index)
|
||||||
.concat([deletedSession])
|
.concat([deletedSession])
|
||||||
.concat(
|
.concat(
|
||||||
state.sessions.slice(index + Number(isLastSession))
|
state.sessions.slice(index + Number(isLastSession)),
|
||||||
),
|
),
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
5000
|
5000,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -412,7 +412,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
get().onNewMessage(botMessage);
|
get().onNewMessage(botMessage);
|
||||||
ControllerPool.remove(
|
ControllerPool.remove(
|
||||||
sessionIndex,
|
sessionIndex,
|
||||||
botMessage.id ?? messageIndex
|
botMessage.id ?? messageIndex,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
botMessage.content = content;
|
botMessage.content = content;
|
||||||
@ -436,7 +436,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
ControllerPool.addController(
|
ControllerPool.addController(
|
||||||
sessionIndex,
|
sessionIndex,
|
||||||
botMessage.id ?? messageIndex,
|
botMessage.id ?? messageIndex,
|
||||||
controller
|
controller,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
filterBot: !get().config.sendBotMessages,
|
filterBot: !get().config.sendBotMessages,
|
||||||
@ -475,12 +475,12 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
// get short term and unmemoried long term memory
|
// get short term and unmemoried long term memory
|
||||||
const shortTermMemoryMessageIndex = Math.max(
|
const shortTermMemoryMessageIndex = Math.max(
|
||||||
0,
|
0,
|
||||||
n - config.historyMessageCount
|
n - config.historyMessageCount,
|
||||||
);
|
);
|
||||||
const longTermMemoryMessageIndex = config.lastSummarizeIndex;
|
const longTermMemoryMessageIndex = session.lastSummarizeIndex;
|
||||||
const oldestIndex = Math.min(
|
const oldestIndex = Math.min(
|
||||||
shortTermMemoryMessageIndex,
|
shortTermMemoryMessageIndex,
|
||||||
longTermMemoryMessageIndex
|
longTermMemoryMessageIndex,
|
||||||
);
|
);
|
||||||
const threshold = config.compressMessageLengthThreshold;
|
const threshold = config.compressMessageLengthThreshold;
|
||||||
|
|
||||||
@ -506,7 +506,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
updateMessage(
|
updateMessage(
|
||||||
sessionIndex: number,
|
sessionIndex: number,
|
||||||
messageIndex: number,
|
messageIndex: number,
|
||||||
updater: (message?: Message) => void
|
updater: (message?: Message) => void,
|
||||||
) {
|
) {
|
||||||
const sessions = get().sessions;
|
const sessions = get().sessions;
|
||||||
const session = sessions.at(sessionIndex);
|
const session = sessions.at(sessionIndex);
|
||||||
@ -535,15 +535,15 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
(res) => {
|
(res) => {
|
||||||
get().updateCurrentSession(
|
get().updateCurrentSession(
|
||||||
(session) =>
|
(session) =>
|
||||||
(session.topic = res ? trimTopic(res) : DEFAULT_TOPIC)
|
(session.topic = res ? trimTopic(res) : DEFAULT_TOPIC),
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = get().config;
|
const config = get().config;
|
||||||
let toBeSummarizedMsgs = session.messages.slice(
|
let toBeSummarizedMsgs = session.messages.slice(
|
||||||
session.lastSummarizeIndex
|
session.lastSummarizeIndex,
|
||||||
);
|
);
|
||||||
|
|
||||||
const historyMsgLength = countMessages(toBeSummarizedMsgs);
|
const historyMsgLength = countMessages(toBeSummarizedMsgs);
|
||||||
@ -551,7 +551,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
if (historyMsgLength > get().config?.modelConfig?.max_tokens ?? 4000) {
|
if (historyMsgLength > get().config?.modelConfig?.max_tokens ?? 4000) {
|
||||||
const n = toBeSummarizedMsgs.length;
|
const n = toBeSummarizedMsgs.length;
|
||||||
toBeSummarizedMsgs = toBeSummarizedMsgs.slice(
|
toBeSummarizedMsgs = toBeSummarizedMsgs.slice(
|
||||||
Math.max(0, n - config.historyMessageCount)
|
Math.max(0, n - config.historyMessageCount),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,7 +564,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
"[Chat History] ",
|
"[Chat History] ",
|
||||||
toBeSummarizedMsgs,
|
toBeSummarizedMsgs,
|
||||||
historyMsgLength,
|
historyMsgLength,
|
||||||
config.compressMessageLengthThreshold
|
config.compressMessageLengthThreshold,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -589,7 +589,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
onError(error) {
|
onError(error) {
|
||||||
console.error("[Summarize] ", error);
|
console.error("[Summarize] ", error);
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -631,6 +631,6 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
|
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user