mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2026-02-19 21:04:25 +08:00
Compare commits
6 Commits
feature/co
...
88f8ca822f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88f8ca822f | ||
|
|
1cccaa2e80 | ||
|
|
d08af47342 | ||
|
|
a5289b39d0 | ||
|
|
1aa647688f | ||
|
|
fb5e9e5aed |
@@ -13,6 +13,7 @@ const DANGER_CONFIG = {
|
|||||||
hideBalanceQuery: serverConfig.hideBalanceQuery,
|
hideBalanceQuery: serverConfig.hideBalanceQuery,
|
||||||
disableFastLink: serverConfig.disableFastLink,
|
disableFastLink: serverConfig.disableFastLink,
|
||||||
customModels: serverConfig.customModels,
|
customModels: serverConfig.customModels,
|
||||||
|
visionModels: serverConfig.visionModels,
|
||||||
defaultModel: serverConfig.defaultModel,
|
defaultModel: serverConfig.defaultModel,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -84,10 +84,13 @@ export class ClaudeApi implements LLMApi {
|
|||||||
return res?.content?.[0]?.text;
|
return res?.content?.[0]?.text;
|
||||||
}
|
}
|
||||||
async chat(options: ChatOptions): Promise<void> {
|
async chat(options: ChatOptions): Promise<void> {
|
||||||
const visionModel = isVisionModel(options.config.model);
|
|
||||||
|
|
||||||
const accessStore = useAccessStore.getState();
|
const accessStore = useAccessStore.getState();
|
||||||
|
|
||||||
|
const visionModel = isVisionModel(
|
||||||
|
options.config.model,
|
||||||
|
accessStore.visionModels,
|
||||||
|
);
|
||||||
|
|
||||||
const shouldStream = !!options.config.stream;
|
const shouldStream = !!options.config.stream;
|
||||||
|
|
||||||
const modelConfig = {
|
const modelConfig = {
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export class GeminiProApi implements LLMApi {
|
|||||||
}
|
}
|
||||||
const messages = _messages.map((v) => {
|
const messages = _messages.map((v) => {
|
||||||
let parts: any[] = [{ text: getMessageTextContent(v) }];
|
let parts: any[] = [{ text: getMessageTextContent(v) }];
|
||||||
if (isVisionModel(options.config.model)) {
|
if (isVisionModel(options.config.model, accessStore.visionModels)) {
|
||||||
const images = getMessageImages(v);
|
const images = getMessageImages(v);
|
||||||
if (images.length > 0) {
|
if (images.length > 0) {
|
||||||
multimodal = true;
|
multimodal = true;
|
||||||
|
|||||||
@@ -194,6 +194,8 @@ export class ChatGPTApi implements LLMApi {
|
|||||||
|
|
||||||
let requestPayload: RequestPayload | DalleRequestPayload;
|
let requestPayload: RequestPayload | DalleRequestPayload;
|
||||||
|
|
||||||
|
const accessStore = useAccessStore.getState();
|
||||||
|
|
||||||
const isDalle3 = _isDalle3(options.config.model);
|
const isDalle3 = _isDalle3(options.config.model);
|
||||||
const isO1 = options.config.model.startsWith("o1");
|
const isO1 = options.config.model.startsWith("o1");
|
||||||
if (isDalle3) {
|
if (isDalle3) {
|
||||||
@@ -211,7 +213,10 @@ export class ChatGPTApi implements LLMApi {
|
|||||||
style: options.config?.style ?? "vivid",
|
style: options.config?.style ?? "vivid",
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
const visionModel = isVisionModel(options.config.model);
|
const visionModel = isVisionModel(
|
||||||
|
options.config.model,
|
||||||
|
accessStore.visionModels,
|
||||||
|
);
|
||||||
const messages: ChatOptions["messages"] = [];
|
const messages: ChatOptions["messages"] = [];
|
||||||
for (const v of options.messages) {
|
for (const v of options.messages) {
|
||||||
const content = visionModel
|
const content = visionModel
|
||||||
|
|||||||
@@ -94,7 +94,11 @@ export class HunyuanApi implements LLMApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async chat(options: ChatOptions) {
|
async chat(options: ChatOptions) {
|
||||||
const visionModel = isVisionModel(options.config.model);
|
const accessStore = useAccessStore.getState();
|
||||||
|
const visionModel = isVisionModel(
|
||||||
|
options.config.model,
|
||||||
|
accessStore.visionModels,
|
||||||
|
);
|
||||||
const messages = options.messages.map((v, index) => ({
|
const messages = options.messages.map((v, index) => ({
|
||||||
// "Messages 中 system 角色必须位于列表的最开始"
|
// "Messages 中 system 角色必须位于列表的最开始"
|
||||||
role: index !== 0 && v.role === "system" ? "user" : v.role,
|
role: index !== 0 && v.role === "system" ? "user" : v.role,
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ import {
|
|||||||
} from "../constant";
|
} from "../constant";
|
||||||
import { Avatar } from "./emoji";
|
import { Avatar } from "./emoji";
|
||||||
import { ContextPrompts, MaskAvatar, MaskConfig } from "./mask";
|
import { ContextPrompts, MaskAvatar, MaskConfig } from "./mask";
|
||||||
|
import { useSyncStore } from "../store/sync";
|
||||||
import { useMaskStore } from "../store/mask";
|
import { useMaskStore } from "../store/mask";
|
||||||
import { ChatCommandPrefix, useChatCommand, useCommand } from "../command";
|
import { ChatCommandPrefix, useChatCommand, useCommand } from "../command";
|
||||||
import { prettyObject } from "../utils/format";
|
import { prettyObject } from "../utils/format";
|
||||||
@@ -490,6 +491,7 @@ export function ChatActions(props: {
|
|||||||
const currentProviderName =
|
const currentProviderName =
|
||||||
session.mask.modelConfig?.providerName || ServiceProvider.OpenAI;
|
session.mask.modelConfig?.providerName || ServiceProvider.OpenAI;
|
||||||
const allModels = useAllModels();
|
const allModels = useAllModels();
|
||||||
|
const customVisionModels = useAccessStore().visionModels;
|
||||||
const models = useMemo(() => {
|
const models = useMemo(() => {
|
||||||
const filteredModels = allModels.filter((m) => m.available);
|
const filteredModels = allModels.filter((m) => m.available);
|
||||||
const defaultModel = filteredModels.find((m) => m.isDefault);
|
const defaultModel = filteredModels.find((m) => m.isDefault);
|
||||||
@@ -529,7 +531,7 @@ export function ChatActions(props: {
|
|||||||
const isMobileScreen = useMobileScreen();
|
const isMobileScreen = useMobileScreen();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const show = isVisionModel(currentModel);
|
const show = isVisionModel(currentModel, customVisionModels);
|
||||||
setShowUploadImage(show);
|
setShowUploadImage(show);
|
||||||
if (!show) {
|
if (!show) {
|
||||||
props.setAttachImages([]);
|
props.setAttachImages([]);
|
||||||
@@ -947,6 +949,8 @@ function _Chat() {
|
|||||||
const fontSize = config.fontSize;
|
const fontSize = config.fontSize;
|
||||||
const fontFamily = config.fontFamily;
|
const fontFamily = config.fontFamily;
|
||||||
|
|
||||||
|
const syncStore = useSyncStore();
|
||||||
|
|
||||||
const [showExport, setShowExport] = useState(false);
|
const [showExport, setShowExport] = useState(false);
|
||||||
|
|
||||||
const inputRef = useRef<HTMLTextAreaElement>(null);
|
const inputRef = useRef<HTMLTextAreaElement>(null);
|
||||||
@@ -1394,42 +1398,51 @@ function _Chat() {
|
|||||||
submit: (text) => {
|
submit: (text) => {
|
||||||
doSubmit(text);
|
doSubmit(text);
|
||||||
},
|
},
|
||||||
code: (text) => {
|
// code: (text) => {
|
||||||
if (accessStore.disableFastLink) return;
|
// if (accessStore.disableFastLink) return;
|
||||||
console.log("[Command] got code from url: ", text);
|
// console.log("[Command] got code from url: ", text);
|
||||||
showConfirm(Locale.URLCommand.Code + `code = ${text}`).then((res) => {
|
// showConfirm(Locale.URLCommand.Code + `code = ${text}`).then((res) => {
|
||||||
if (res) {
|
// if (res) {
|
||||||
accessStore.update((access) => (access.accessCode = text));
|
// accessStore.update((access) => (access.accessCode = text));
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
settings: (text) => {
|
settings: (text) => {
|
||||||
if (accessStore.disableFastLink) return;
|
if (accessStore.disableFastLink) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const payload = JSON.parse(text) as {
|
const payload = JSON.parse(text) as {
|
||||||
key?: string;
|
code?: string;
|
||||||
url?: string;
|
username?: string;
|
||||||
|
password?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("[Command] got settings from url: ", payload);
|
console.log("[Command] got settings from url: ", payload);
|
||||||
|
|
||||||
if (payload.key || payload.url) {
|
if (payload.code) {
|
||||||
showConfirm(
|
accessStore.update((access) => (access.accessCode = payload.code!));
|
||||||
Locale.URLCommand.Settings +
|
if (accessStore.isAuthorized()) {
|
||||||
`\n${JSON.stringify(payload, null, 4)}`,
|
context.pop();
|
||||||
).then((res) => {
|
const copiedHello = Object.assign({}, BOT_HELLO);
|
||||||
if (!res) return;
|
context.push(copiedHello);
|
||||||
if (payload.key) {
|
setUserInput(" ");
|
||||||
accessStore.update(
|
}
|
||||||
(access) => (access.openaiApiKey = payload.key!),
|
}
|
||||||
);
|
|
||||||
}
|
if (payload.username) {
|
||||||
if (payload.url) {
|
syncStore.update(
|
||||||
accessStore.update((access) => (access.openaiUrl = payload.url!));
|
(config) => (config.webdav.username = payload.username!),
|
||||||
}
|
);
|
||||||
accessStore.update((access) => (access.useCustomConfig = true));
|
}
|
||||||
});
|
|
||||||
|
if (payload.password) {
|
||||||
|
syncStore.update(
|
||||||
|
(config) => (config.webdav.password = payload.password!),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.username && payload.password) {
|
||||||
|
syncStore.sync();
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
console.error("[Command] failed to get settings from url: ", text);
|
console.error("[Command] failed to get settings from url: ", text);
|
||||||
@@ -1457,10 +1470,12 @@ function _Chat() {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const customVisionModels = useAccessStore().visionModels;
|
||||||
|
|
||||||
const handlePaste = useCallback(
|
const handlePaste = useCallback(
|
||||||
async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
|
async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
|
||||||
const currentModel = chatStore.currentSession().mask.modelConfig.model;
|
const currentModel = chatStore.currentSession().mask.modelConfig.model;
|
||||||
if (!isVisionModel(currentModel)) {
|
if (!isVisionModel(currentModel, customVisionModels)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const items = (event.clipboardData || window.clipboardData).items;
|
const items = (event.clipboardData || window.clipboardData).items;
|
||||||
@@ -1497,7 +1512,7 @@ function _Chat() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[attachImages, chatStore],
|
[attachImages, chatStore, customVisionModels],
|
||||||
);
|
);
|
||||||
|
|
||||||
async function uploadImage() {
|
async function uploadImage() {
|
||||||
@@ -1545,7 +1560,7 @@ function _Chat() {
|
|||||||
setAttachImages(images);
|
setAttachImages(images);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 快捷键 shortcut keys
|
// 捷键 shortcut keys
|
||||||
const [showShortcutKeyModal, setShowShortcutKeyModal] = useState(false);
|
const [showShortcutKeyModal, setShowShortcutKeyModal] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -528,6 +528,21 @@ function SyncItems() {
|
|||||||
setShowSyncConfigModal(true);
|
setShowSyncConfigModal(true);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{couldSync && (
|
||||||
|
<IconButton
|
||||||
|
icon={<UploadIcon />}
|
||||||
|
text={Locale.UI.Overwrite}
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
await syncStore.overwrite();
|
||||||
|
showToast(Locale.Settings.Sync.Success);
|
||||||
|
} catch (e) {
|
||||||
|
showToast(Locale.Settings.Sync.Fail);
|
||||||
|
console.error("[Sync]", e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{couldSync && (
|
{couldSync && (
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={<ResetIcon />}
|
icon={<ResetIcon />}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ declare global {
|
|||||||
ENABLE_BALANCE_QUERY?: string; // allow user to query balance or not
|
ENABLE_BALANCE_QUERY?: string; // allow user to query balance or not
|
||||||
DISABLE_FAST_LINK?: string; // disallow parse settings from url or not
|
DISABLE_FAST_LINK?: string; // disallow parse settings from url or not
|
||||||
CUSTOM_MODELS?: string; // to control custom models
|
CUSTOM_MODELS?: string; // to control custom models
|
||||||
|
VISION_MODELS?: string; // to control vision models
|
||||||
DEFAULT_MODEL?: string; // to control default model in every new chat window
|
DEFAULT_MODEL?: string; // to control default model in every new chat window
|
||||||
|
|
||||||
// stability only
|
// stability only
|
||||||
@@ -123,13 +124,16 @@ export const getServerSideConfig = () => {
|
|||||||
|
|
||||||
const disableGPT4 = !!process.env.DISABLE_GPT4;
|
const disableGPT4 = !!process.env.DISABLE_GPT4;
|
||||||
let customModels = process.env.CUSTOM_MODELS ?? "";
|
let customModels = process.env.CUSTOM_MODELS ?? "";
|
||||||
|
let visionModels = process.env.VISION_MODELS ?? "";
|
||||||
let defaultModel = process.env.DEFAULT_MODEL ?? "";
|
let defaultModel = process.env.DEFAULT_MODEL ?? "";
|
||||||
|
|
||||||
if (disableGPT4) {
|
if (disableGPT4) {
|
||||||
if (customModels) customModels += ",";
|
if (customModels) customModels += ",";
|
||||||
customModels += DEFAULT_MODELS.filter(
|
customModels += DEFAULT_MODELS.filter(
|
||||||
(m) =>
|
(m) =>
|
||||||
(m.name.startsWith("gpt-4") || m.name.startsWith("chatgpt-4o") || m.name.startsWith("o1")) &&
|
(m.name.startsWith("gpt-4") ||
|
||||||
|
m.name.startsWith("chatgpt-4o") ||
|
||||||
|
m.name.startsWith("o1")) &&
|
||||||
!m.name.startsWith("gpt-4o-mini"),
|
!m.name.startsWith("gpt-4o-mini"),
|
||||||
)
|
)
|
||||||
.map((m) => "-" + m.name)
|
.map((m) => "-" + m.name)
|
||||||
@@ -247,6 +251,7 @@ export const getServerSideConfig = () => {
|
|||||||
hideBalanceQuery: !process.env.ENABLE_BALANCE_QUERY,
|
hideBalanceQuery: !process.env.ENABLE_BALANCE_QUERY,
|
||||||
disableFastLink: !!process.env.DISABLE_FAST_LINK,
|
disableFastLink: !!process.env.DISABLE_FAST_LINK,
|
||||||
customModels,
|
customModels,
|
||||||
|
visionModels,
|
||||||
defaultModel,
|
defaultModel,
|
||||||
allowedWebDavEndpoints,
|
allowedWebDavEndpoints,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -757,6 +757,7 @@ const cn = {
|
|||||||
Export: "导出",
|
Export: "导出",
|
||||||
Import: "导入",
|
Import: "导入",
|
||||||
Sync: "同步",
|
Sync: "同步",
|
||||||
|
Overwrite: "覆盖",
|
||||||
Config: "配置",
|
Config: "配置",
|
||||||
},
|
},
|
||||||
Exporter: {
|
Exporter: {
|
||||||
|
|||||||
@@ -762,6 +762,7 @@ const en: LocaleType = {
|
|||||||
Edit: "Edit",
|
Edit: "Edit",
|
||||||
Export: "Export",
|
Export: "Export",
|
||||||
Import: "Import",
|
Import: "Import",
|
||||||
|
Overwrite: "Overwrite",
|
||||||
Sync: "Sync",
|
Sync: "Sync",
|
||||||
Config: "Config",
|
Config: "Config",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -589,6 +589,7 @@ const fr: PartialLocaleType = {
|
|||||||
Edit: "Modifier",
|
Edit: "Modifier",
|
||||||
Export: "Exporter",
|
Export: "Exporter",
|
||||||
Import: "Importer",
|
Import: "Importer",
|
||||||
|
Overwrite: "Remplacer",
|
||||||
Sync: "Synchroniser",
|
Sync: "Synchroniser",
|
||||||
Config: "Configurer",
|
Config: "Configurer",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -590,6 +590,7 @@ const it: PartialLocaleType = {
|
|||||||
Edit: "Modifica",
|
Edit: "Modifica",
|
||||||
Export: "Esporta",
|
Export: "Esporta",
|
||||||
Import: "Importa",
|
Import: "Importa",
|
||||||
|
Overwrite: "Sostituisci",
|
||||||
Sync: "Sincronizza",
|
Sync: "Sincronizza",
|
||||||
Config: "Configura",
|
Config: "Configura",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -505,6 +505,7 @@ const pt: PartialLocaleType = {
|
|||||||
Edit: "Editar",
|
Edit: "Editar",
|
||||||
Export: "Exportar",
|
Export: "Exportar",
|
||||||
Import: "Importar",
|
Import: "Importar",
|
||||||
|
Overwrite: "Substituir",
|
||||||
Sync: "Sincronizar",
|
Sync: "Sincronizar",
|
||||||
Config: "Configurar",
|
Config: "Configurar",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ const DEFAULT_ACCESS_STATE = {
|
|||||||
disableGPT4: false,
|
disableGPT4: false,
|
||||||
disableFastLink: false,
|
disableFastLink: false,
|
||||||
customModels: "",
|
customModels: "",
|
||||||
|
visionModels: "",
|
||||||
defaultModel: "",
|
defaultModel: "",
|
||||||
|
|
||||||
// tts config
|
// tts config
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { getClientConfig } from "../config/client";
|
|||||||
import {
|
import {
|
||||||
DEFAULT_INPUT_TEMPLATE,
|
DEFAULT_INPUT_TEMPLATE,
|
||||||
DEFAULT_MODELS,
|
DEFAULT_MODELS,
|
||||||
DEFAULT_SIDEBAR_WIDTH,
|
|
||||||
DEFAULT_TTS_ENGINE,
|
DEFAULT_TTS_ENGINE,
|
||||||
DEFAULT_TTS_ENGINES,
|
DEFAULT_TTS_ENGINES,
|
||||||
DEFAULT_TTS_MODEL,
|
DEFAULT_TTS_MODEL,
|
||||||
@@ -46,18 +45,20 @@ export const DEFAULT_CONFIG = {
|
|||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontFamily: "",
|
fontFamily: "",
|
||||||
theme: Theme.Auto as Theme,
|
theme: Theme.Auto as Theme,
|
||||||
tightBorder: !!config?.isApp,
|
// tightBorder: !!config?.isApp,
|
||||||
sendPreviewBubble: true,
|
tightBorder: true,
|
||||||
|
sendPreviewBubble: false,
|
||||||
enableAutoGenerateTitle: true,
|
enableAutoGenerateTitle: true,
|
||||||
sidebarWidth: DEFAULT_SIDEBAR_WIDTH,
|
// sidebarWidth: DEFAULT_SIDEBAR_WIDTH,
|
||||||
|
sidebarWidth: 100,
|
||||||
|
|
||||||
enableArtifacts: true, // show artifacts config
|
enableArtifacts: true, // show artifacts config
|
||||||
|
|
||||||
enableCodeFold: true, // code fold config
|
enableCodeFold: true, // code fold config
|
||||||
|
|
||||||
disablePromptHint: false,
|
disablePromptHint: true,
|
||||||
|
|
||||||
dontShowMaskSplashScreen: false, // dont show splash screen when create chat
|
dontShowMaskSplashScreen: true, // dont show splash screen when create chat
|
||||||
hideBuiltinMasks: false, // dont add builtin masks
|
hideBuiltinMasks: false, // dont add builtin masks
|
||||||
|
|
||||||
customModels: "",
|
customModels: "",
|
||||||
@@ -68,12 +69,12 @@ export const DEFAULT_CONFIG = {
|
|||||||
providerName: "OpenAI" as ServiceProvider,
|
providerName: "OpenAI" as ServiceProvider,
|
||||||
temperature: 0.5,
|
temperature: 0.5,
|
||||||
top_p: 1,
|
top_p: 1,
|
||||||
max_tokens: 4000,
|
max_tokens: 8000,
|
||||||
presence_penalty: 0,
|
presence_penalty: 0,
|
||||||
frequency_penalty: 0,
|
frequency_penalty: 0,
|
||||||
sendMemory: true,
|
sendMemory: true,
|
||||||
historyMessageCount: 4,
|
historyMessageCount: 16,
|
||||||
compressMessageLengthThreshold: 1000,
|
compressMessageLengthThreshold: 1000000,
|
||||||
compressModel: "",
|
compressModel: "",
|
||||||
compressProviderName: "",
|
compressProviderName: "",
|
||||||
enableInjectSystemPrompts: true,
|
enableInjectSystemPrompts: true,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const DEFAULT_SYNC_STATE = {
|
|||||||
proxyUrl: ApiPath.Cors as string,
|
proxyUrl: ApiPath.Cors as string,
|
||||||
|
|
||||||
webdav: {
|
webdav: {
|
||||||
endpoint: "",
|
endpoint: "https://dav.jyj.cx",
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
},
|
},
|
||||||
@@ -88,7 +88,7 @@ export const useSyncStore = createPersistStore(
|
|||||||
return client;
|
return client;
|
||||||
},
|
},
|
||||||
|
|
||||||
async sync() {
|
async sync(overwrite = false) {
|
||||||
const localState = getLocalAppState();
|
const localState = getLocalAppState();
|
||||||
const provider = get().provider;
|
const provider = get().provider;
|
||||||
const config = get()[provider];
|
const config = get()[provider];
|
||||||
@@ -103,11 +103,13 @@ export const useSyncStore = createPersistStore(
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const parsedRemoteState = JSON.parse(
|
if (!overwrite) {
|
||||||
await client.get(config.username),
|
const parsedRemoteState = JSON.parse(
|
||||||
) as AppState;
|
await client.get(config.username),
|
||||||
mergeAppState(localState, parsedRemoteState);
|
) as AppState;
|
||||||
setLocalAppState(localState);
|
mergeAppState(localState, parsedRemoteState);
|
||||||
|
setLocalAppState(localState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("[Sync] failed to get remote state", e);
|
console.log("[Sync] failed to get remote state", e);
|
||||||
@@ -119,6 +121,10 @@ export const useSyncStore = createPersistStore(
|
|||||||
this.markSyncTime();
|
this.markSyncTime();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async overwrite() {
|
||||||
|
await this.sync(true);
|
||||||
|
},
|
||||||
|
|
||||||
async check() {
|
async check() {
|
||||||
const client = this.getClient();
|
const client = this.getClient();
|
||||||
return await client.check();
|
return await client.check();
|
||||||
|
|||||||
14
app/utils.ts
14
app/utils.ts
@@ -7,6 +7,7 @@ import { ServiceProvider } from "./constant";
|
|||||||
import { fetch as tauriStreamFetch } from "./utils/stream";
|
import { fetch as tauriStreamFetch } from "./utils/stream";
|
||||||
import { VISION_MODEL_REGEXES, EXCLUDE_VISION_MODEL_REGEXES } from "./constant";
|
import { VISION_MODEL_REGEXES, EXCLUDE_VISION_MODEL_REGEXES } from "./constant";
|
||||||
import { getClientConfig } from "./config/client";
|
import { getClientConfig } from "./config/client";
|
||||||
|
import { getModelProvider } from "./utils/model";
|
||||||
|
|
||||||
export function trimTopic(topic: string) {
|
export function trimTopic(topic: string) {
|
||||||
// Fix an issue where double quotes still show in the Indonesian language
|
// Fix an issue where double quotes still show in the Indonesian language
|
||||||
@@ -253,12 +254,15 @@ export function getMessageImages(message: RequestMessage): string[] {
|
|||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isVisionModel(model: string) {
|
export function isVisionModel(model: string, customVisionModels: string) {
|
||||||
const clientConfig = getClientConfig();
|
const clientConfig = getClientConfig();
|
||||||
const envVisionModels = clientConfig?.visionModels
|
const allVisionModelsList = [customVisionModels, clientConfig?.visionModels]
|
||||||
?.split(",")
|
?.join(",")
|
||||||
.map((m) => m.trim());
|
.split(",")
|
||||||
if (envVisionModels?.includes(model)) {
|
.map((m) => m.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((m) => getModelProvider(m)[0]);
|
||||||
|
if (allVisionModelsList?.includes(model)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
ChatSession,
|
ChatSession,
|
||||||
useAccessStore,
|
// useAccessStore,
|
||||||
useAppConfig,
|
// useAppConfig,
|
||||||
useChatStore,
|
useChatStore,
|
||||||
} from "../store";
|
} from "../store";
|
||||||
import { useMaskStore } from "../store/mask";
|
// import { useMaskStore } from "../store/mask";
|
||||||
import { usePromptStore } from "../store/prompt";
|
// import { usePromptStore } from "../store/prompt";
|
||||||
import { StoreKey } from "../constant";
|
import { StoreKey } from "../constant";
|
||||||
import { merge } from "./merge";
|
import { merge } from "./merge";
|
||||||
|
|
||||||
@@ -32,18 +32,18 @@ export type GetStoreState<T> = T extends { getState: () => infer U }
|
|||||||
|
|
||||||
const LocalStateSetters = {
|
const LocalStateSetters = {
|
||||||
[StoreKey.Chat]: useChatStore.setState,
|
[StoreKey.Chat]: useChatStore.setState,
|
||||||
[StoreKey.Access]: useAccessStore.setState,
|
// [StoreKey.Access]: useAccessStore.setState,
|
||||||
[StoreKey.Config]: useAppConfig.setState,
|
// [StoreKey.Config]: useAppConfig.setState,
|
||||||
[StoreKey.Mask]: useMaskStore.setState,
|
// [StoreKey.Mask]: useMaskStore.setState,
|
||||||
[StoreKey.Prompt]: usePromptStore.setState,
|
// [StoreKey.Prompt]: usePromptStore.setState,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
const LocalStateGetters = {
|
const LocalStateGetters = {
|
||||||
[StoreKey.Chat]: () => getNonFunctionFileds(useChatStore.getState()),
|
[StoreKey.Chat]: () => getNonFunctionFileds(useChatStore.getState()),
|
||||||
[StoreKey.Access]: () => getNonFunctionFileds(useAccessStore.getState()),
|
// [StoreKey.Access]: () => getNonFunctionFileds(useAccessStore.getState()),
|
||||||
[StoreKey.Config]: () => getNonFunctionFileds(useAppConfig.getState()),
|
// [StoreKey.Config]: () => getNonFunctionFileds(useAppConfig.getState()),
|
||||||
[StoreKey.Mask]: () => getNonFunctionFileds(useMaskStore.getState()),
|
// [StoreKey.Mask]: () => getNonFunctionFileds(useMaskStore.getState()),
|
||||||
[StoreKey.Prompt]: () => getNonFunctionFileds(usePromptStore.getState()),
|
// [StoreKey.Prompt]: () => getNonFunctionFileds(usePromptStore.getState()),
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type AppState = {
|
export type AppState = {
|
||||||
@@ -100,22 +100,22 @@ const MergeStates: StateMerger = {
|
|||||||
|
|
||||||
return localState;
|
return localState;
|
||||||
},
|
},
|
||||||
[StoreKey.Prompt]: (localState, remoteState) => {
|
// [StoreKey.Prompt]: (localState, remoteState) => {
|
||||||
localState.prompts = {
|
// localState.prompts = {
|
||||||
...remoteState.prompts,
|
// ...remoteState.prompts,
|
||||||
...localState.prompts,
|
// ...localState.prompts,
|
||||||
};
|
// };
|
||||||
return localState;
|
// return localState;
|
||||||
},
|
// },
|
||||||
[StoreKey.Mask]: (localState, remoteState) => {
|
// [StoreKey.Mask]: (localState, remoteState) => {
|
||||||
localState.masks = {
|
// localState.masks = {
|
||||||
...remoteState.masks,
|
// ...remoteState.masks,
|
||||||
...localState.masks,
|
// ...localState.masks,
|
||||||
};
|
// };
|
||||||
return localState;
|
// return localState;
|
||||||
},
|
// },
|
||||||
[StoreKey.Config]: mergeWithUpdate<AppState[StoreKey.Config]>,
|
// [StoreKey.Config]: mergeWithUpdate<AppState[StoreKey.Config]>,
|
||||||
[StoreKey.Access]: mergeWithUpdate<AppState[StoreKey.Access]>,
|
// [StoreKey.Access]: mergeWithUpdate<AppState[StoreKey.Access]>,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getLocalAppState() {
|
export function getLocalAppState() {
|
||||||
|
|||||||
16
nextchat.json
Normal file
16
nextchat.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "nextchat",
|
||||||
|
"cwd": "/www/nextchat",
|
||||||
|
"script": "server.js",
|
||||||
|
"env": {
|
||||||
|
"PORT": 8032,
|
||||||
|
"CODE": "scut",
|
||||||
|
"BASE_URL": "https://oneapi.jyj.cx",
|
||||||
|
"OPENAI_API_KEY": "sk-jiangyj",
|
||||||
|
"HIDE_USER_API_KEY": true,
|
||||||
|
"CUSTOM_MODELS": "-all,gemini-2.0-pro-exp-02-05@openai,gemini-2.0-flash-thinking-exp-01-21@openai,gemini-2.0-flash-exp@openai,gemini-2.0-flash@openai,gemini-2.0-flash-lite@openai,gpt-4o-2024-11-20@openai,o3-mini@openai,deepseek-ai/deepseek-v3@openai,deepseek-ai/deepseek-r1@openai,deepseek-chat@openai,deepseek-reasoner@openai,ep-20250124104315-zsg4p@openai",
|
||||||
|
"DEFAULT_MODEL": "gemini-2.0-pro-exp-02-05@openai",
|
||||||
|
"WHITE_WEBDAV_ENDPOINTS": "https://dav.jyj.cx",
|
||||||
|
"VISION_MODELS": "gemini-2.0-flash-thinking-exp-01-21@openai,gemini-2.0-pro-exp-02-05@openai,gemini-2.0-flash-exp@openai,gemini-2.0-flash@openai,gemini-2.0-flash-lite@openai,gpt-4o-2024-11-20@openai,o3-mini@openai,deepseek-ai/DeepSeek-V3@openai,deepseek-ai/DeepSeek-R1@openai,deepseek-chat@openai,deepseek-reasoner@openai,ep-20250124104315-zsg4p@openai"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import { isVisionModel } from "../app/utils";
|
|||||||
|
|
||||||
describe("isVisionModel", () => {
|
describe("isVisionModel", () => {
|
||||||
const originalEnv = process.env;
|
const originalEnv = process.env;
|
||||||
|
const customVisionModels = "custom-vlm,another-vlm";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
@@ -27,12 +28,12 @@ describe("isVisionModel", () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
visionModels.forEach((model) => {
|
visionModels.forEach((model) => {
|
||||||
expect(isVisionModel(model)).toBe(true);
|
expect(isVisionModel(model, customVisionModels)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should exclude specific models", () => {
|
test("should exclude specific models", () => {
|
||||||
expect(isVisionModel("claude-3-5-haiku-20241022")).toBe(false);
|
expect(isVisionModel("claude-3-5-haiku-20241022", customVisionModels)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should not identify non-vision models", () => {
|
test("should not identify non-vision models", () => {
|
||||||
@@ -44,24 +45,26 @@ describe("isVisionModel", () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
nonVisionModels.forEach((model) => {
|
nonVisionModels.forEach((model) => {
|
||||||
expect(isVisionModel(model)).toBe(false);
|
expect(isVisionModel(model, customVisionModels)).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should identify models from VISION_MODELS env var", () => {
|
test("should identify models from VISION_MODELS env var", () => {
|
||||||
process.env.VISION_MODELS = "custom-vision-model,another-vision-model";
|
process.env.VISION_MODELS = "custom-vision-model,another-vision-model";
|
||||||
|
|
||||||
expect(isVisionModel("custom-vision-model")).toBe(true);
|
expect(isVisionModel("custom-vision-model", customVisionModels)).toBe(true);
|
||||||
expect(isVisionModel("another-vision-model")).toBe(true);
|
expect(isVisionModel("another-vision-model", customVisionModels)).toBe(true);
|
||||||
expect(isVisionModel("unrelated-model")).toBe(false);
|
expect(isVisionModel("custom-vlm", customVisionModels)).toBe(true);
|
||||||
|
expect(isVisionModel("another-vlm", customVisionModels)).toBe(true);
|
||||||
|
expect(isVisionModel("unrelated-model", customVisionModels)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should handle empty or missing VISION_MODELS", () => {
|
test("should handle empty or missing VISION_MODELS", () => {
|
||||||
process.env.VISION_MODELS = "";
|
process.env.VISION_MODELS = "";
|
||||||
expect(isVisionModel("unrelated-model")).toBe(false);
|
expect(isVisionModel("unrelated-model", customVisionModels)).toBe(false);
|
||||||
|
|
||||||
delete process.env.VISION_MODELS;
|
delete process.env.VISION_MODELS;
|
||||||
expect(isVisionModel("unrelated-model")).toBe(false);
|
expect(isVisionModel("unrelated-model", customVisionModels)).toBe(false);
|
||||||
expect(isVisionModel("gpt-4-vision")).toBe(true);
|
expect(isVisionModel("gpt-4-vision", customVisionModels)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user