|
|
@@ -1,33 +1,29 @@
|
|
|
-import { trimTopic, getMessageTextContent } from "../utils";
|
|
|
+import { getMessageTextContent, trimTopic } from "../utils";
|
|
|
|
|
|
-import Locale, { getLang } from "../locales";
|
|
|
+import { indexedDBStorage } from "@/app/utils/indexedDB-storage";
|
|
|
+import { nanoid } from "nanoid";
|
|
|
+import type {
|
|
|
+ ClientApi,
|
|
|
+ MultimodalContent,
|
|
|
+ RequestMessage,
|
|
|
+} from "../client/api";
|
|
|
+import { getClientApi } from "../client/api";
|
|
|
+import { ChatControllerPool } from "../client/controller";
|
|
|
import { showToast } from "../components/ui-lib";
|
|
|
-import { ModelConfig, ModelType, useAppConfig } from "./config";
|
|
|
-import { createEmptyMask, Mask } from "./mask";
|
|
|
import {
|
|
|
DEFAULT_INPUT_TEMPLATE,
|
|
|
DEFAULT_MODELS,
|
|
|
DEFAULT_SYSTEM_TEMPLATE,
|
|
|
KnowledgeCutOffDate,
|
|
|
StoreKey,
|
|
|
- SUMMARIZE_MODEL,
|
|
|
- GEMINI_SUMMARIZE_MODEL,
|
|
|
} from "../constant";
|
|
|
-import { getClientApi } from "../client/api";
|
|
|
-import type {
|
|
|
- ClientApi,
|
|
|
- RequestMessage,
|
|
|
- MultimodalContent,
|
|
|
-} from "../client/api";
|
|
|
-import { ChatControllerPool } from "../client/controller";
|
|
|
+import Locale, { getLang } from "../locales";
|
|
|
+import { isDalle3, safeLocalStorage } from "../utils";
|
|
|
import { prettyObject } from "../utils/format";
|
|
|
-import { estimateTokenLength } from "../utils/token";
|
|
|
-import { nanoid } from "nanoid";
|
|
|
import { createPersistStore } from "../utils/store";
|
|
|
-import { collectModelsWithDefaultModel } from "../utils/model";
|
|
|
-import { useAccessStore } from "./access";
|
|
|
-import { isDalle3, safeLocalStorage } from "../utils";
|
|
|
-import { indexedDBStorage } from "@/app/utils/indexedDB-storage";
|
|
|
+import { estimateTokenLength } from "../utils/token";
|
|
|
+import { ModelConfig, ModelType, useAppConfig } from "./config";
|
|
|
+import { createEmptyMask, Mask } from "./mask";
|
|
|
|
|
|
const localStorage = safeLocalStorage();
|
|
|
|
|
|
@@ -106,27 +102,6 @@ function createEmptySession(): ChatSession {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-function getSummarizeModel(currentModel: string) {
|
|
|
- // if it is using gpt-* models, force to use 4o-mini to summarize
|
|
|
- if (currentModel.startsWith("gpt") || currentModel.startsWith("chatgpt")) {
|
|
|
- const configStore = useAppConfig.getState();
|
|
|
- const accessStore = useAccessStore.getState();
|
|
|
- const allModel = collectModelsWithDefaultModel(
|
|
|
- configStore.models,
|
|
|
- [configStore.customModels, accessStore.customModels].join(","),
|
|
|
- accessStore.defaultModel,
|
|
|
- );
|
|
|
- const summarizeModel = allModel.find(
|
|
|
- (m) => m.name === SUMMARIZE_MODEL && m.available,
|
|
|
- );
|
|
|
- return summarizeModel?.name ?? currentModel;
|
|
|
- }
|
|
|
- if (currentModel.startsWith("gemini")) {
|
|
|
- return GEMINI_SUMMARIZE_MODEL;
|
|
|
- }
|
|
|
- return currentModel;
|
|
|
-}
|
|
|
-
|
|
|
function countMessages(msgs: ChatMessage[]) {
|
|
|
return msgs.reduce(
|
|
|
(pre, cur) => pre + estimateTokenLength(getMessageTextContent(cur)),
|
|
|
@@ -581,7 +556,7 @@ export const useChatStore = createPersistStore(
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const providerName = modelConfig.providerName;
|
|
|
+ const providerName = modelConfig.compressProviderName;
|
|
|
const api: ClientApi = getClientApi(providerName);
|
|
|
|
|
|
// remove error messages if any
|
|
|
@@ -603,7 +578,7 @@ export const useChatStore = createPersistStore(
|
|
|
api.llm.chat({
|
|
|
messages: topicMessages,
|
|
|
config: {
|
|
|
- model: getSummarizeModel(session.mask.modelConfig.model),
|
|
|
+ model: modelConfig.compressModel,
|
|
|
stream: false,
|
|
|
providerName,
|
|
|
},
|
|
|
@@ -666,7 +641,7 @@ export const useChatStore = createPersistStore(
|
|
|
config: {
|
|
|
...modelcfg,
|
|
|
stream: true,
|
|
|
- model: getSummarizeModel(session.mask.modelConfig.model),
|
|
|
+ model: modelConfig.compressModel,
|
|
|
},
|
|
|
onUpdate(message) {
|
|
|
session.memoryPrompt = message;
|
|
|
@@ -715,7 +690,7 @@ export const useChatStore = createPersistStore(
|
|
|
},
|
|
|
{
|
|
|
name: StoreKey.Chat,
|
|
|
- version: 3.1,
|
|
|
+ version: 3.2,
|
|
|
migrate(persistedState, version) {
|
|
|
const state = persistedState as any;
|
|
|
const newState = JSON.parse(
|
|
|
@@ -762,6 +737,16 @@ export const useChatStore = createPersistStore(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ // add default summarize model for every session
|
|
|
+ if (version < 3.2) {
|
|
|
+ newState.sessions.forEach((s) => {
|
|
|
+ const config = useAppConfig.getState();
|
|
|
+ s.mask.modelConfig.compressModel = config.modelConfig.compressModel;
|
|
|
+ s.mask.modelConfig.compressProviderName =
|
|
|
+ config.modelConfig.compressProviderName;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
return newState as any;
|
|
|
},
|
|
|
},
|