|
|
@@ -547,7 +547,7 @@ export const useChatStore = createPersistStore(
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- summarizeSession() {
|
|
|
+ summarizeSession(refreshTitle: boolean = false) {
|
|
|
const config = useAppConfig.getState();
|
|
|
const session = get().currentSession();
|
|
|
const modelConfig = session.mask.modelConfig;
|
|
|
@@ -565,16 +565,26 @@ export const useChatStore = createPersistStore(
|
|
|
// should summarize topic after chating more than 50 words
|
|
|
const SUMMARIZE_MIN_LEN = 50;
|
|
|
if (
|
|
|
- config.enableAutoGenerateTitle &&
|
|
|
- session.topic === DEFAULT_TOPIC &&
|
|
|
- countMessages(messages) >= SUMMARIZE_MIN_LEN
|
|
|
+ (config.enableAutoGenerateTitle &&
|
|
|
+ session.topic === DEFAULT_TOPIC &&
|
|
|
+ countMessages(messages) >= SUMMARIZE_MIN_LEN) ||
|
|
|
+ refreshTitle
|
|
|
) {
|
|
|
- const topicMessages = messages.concat(
|
|
|
- createMessage({
|
|
|
- role: "user",
|
|
|
- content: Locale.Store.Prompt.Topic,
|
|
|
- }),
|
|
|
+ const startIndex = Math.max(
|
|
|
+ 0,
|
|
|
+ messages.length - modelConfig.historyMessageCount,
|
|
|
);
|
|
|
+ const topicMessages = messages
|
|
|
+ .slice(
|
|
|
+ startIndex < messages.length ? startIndex : messages.length - 1,
|
|
|
+ messages.length,
|
|
|
+ )
|
|
|
+ .concat(
|
|
|
+ createMessage({
|
|
|
+ role: "user",
|
|
|
+ content: Locale.Store.Prompt.Topic,
|
|
|
+ }),
|
|
|
+ );
|
|
|
api.llm.chat({
|
|
|
messages: topicMessages,
|
|
|
config: {
|