From 4c63ee23cdf2760a4b88510081b2d630c583050e Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Thu, 19 Sep 2024 15:13:33 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20#5422=20=E5=BF=AB=E6=8D=B7=E9=94=AE?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E4=B8=8A=E4=B8=8B=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/chat.tsx | 20 ++++++++++++++++++++ app/locales/cn.ts | 1 + app/locales/en.ts | 1 + app/locales/tw.ts | 1 + 4 files changed, 23 insertions(+) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 3d519dee722..08c931f9efe 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -874,6 +874,10 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { title: Locale.Chat.ShortcutKey.showShortcutKey, keys: isMac ? ["⌘", "/"] : ["Ctrl", "/"], }, + { + title: Locale.Chat.ShortcutKey.clearContext, + keys: isMac ? ["⌘", "Shift", "Delete"] : ["Ctrl", "Shift", "Delete"], + }, ]; return (
@@ -1560,6 +1564,22 @@ function _Chat() { event.preventDefault(); setShowShortcutKeyModal(true); } + // 清除上下文 command + shift + delete + else if ( + (event.metaKey || event.ctrlKey) && + event.shiftKey && + event.key.toLowerCase() === "delete" + ) { + event.preventDefault(); + chatStore.updateCurrentSession((session) => { + if (session.clearContextIndex === session.messages.length) { + session.clearContextIndex = undefined; + } else { + session.clearContextIndex = session.messages.length; + session.memoryPrompt = ""; // will clear memory + } + }); + } }; window.addEventListener("keydown", handleKeyDown); diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 0017e8e4243..0acf8c545a6 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -95,6 +95,7 @@ const cn = { copyLastMessage: "复制最后一个回复", copyLastCode: "复制最后一个代码块", showShortcutKey: "显示快捷方式", + clearContext: "清除上下文", }, }, Export: { diff --git a/app/locales/en.ts b/app/locales/en.ts index 63e244b9a81..559b93abd56 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -97,6 +97,7 @@ const en: LocaleType = { copyLastMessage: "Copy Last Reply", copyLastCode: "Copy Last Code Block", showShortcutKey: "Show Shortcuts", + clearContext: "Clear Context", }, }, Export: { diff --git a/app/locales/tw.ts b/app/locales/tw.ts index b0602a08174..b84d3bf1f03 100644 --- a/app/locales/tw.ts +++ b/app/locales/tw.ts @@ -90,6 +90,7 @@ const tw = { copyLastMessage: "複製最後一個回覆", copyLastCode: "複製最後一個代碼塊", showShortcutKey: "顯示快捷方式", + clearContext: "清除上下文", }, }, Export: { From 5b5dea1c59605f26b382d780b5a558169d1a1021 Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Mon, 30 Dec 2024 12:11:50 +0800 Subject: [PATCH 2/8] =?UTF-8?q?chore:=20=E6=9B=B4=E6=8D=A2=E5=BF=AB?= =?UTF-8?q?=E6=8D=B7=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/chat.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 08c931f9efe..138c0b86544 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -876,7 +876,7 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { }, { title: Locale.Chat.ShortcutKey.clearContext, - keys: isMac ? ["⌘", "Shift", "Delete"] : ["Ctrl", "Shift", "Delete"], + keys: isMac ? ["⌘", "Shift", "k"] : ["Ctrl", "Shift", "k"], }, ]; return ( @@ -1568,7 +1568,7 @@ function _Chat() { else if ( (event.metaKey || event.ctrlKey) && event.shiftKey && - event.key.toLowerCase() === "delete" + event.key.toLowerCase() === "k" ) { event.preventDefault(); chatStore.updateCurrentSession((session) => { From 57c88c0717bf21f29395642f32a306dc2388018d Mon Sep 17 00:00:00 2001 From: code-october <148516338+code-october@users.noreply.github.com> Date: Mon, 30 Dec 2024 08:58:41 +0000 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20VISION=5FMDOELS=20?= =?UTF-8?q?=E5=9C=A8=20docker=20=E8=BF=90=E8=A1=8C=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/config/route.ts | 1 + app/config/build.ts | 1 - app/config/server.ts | 3 +++ app/store/access.ts | 6 +++++- app/utils.ts | 6 +++--- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/api/config/route.ts b/app/api/config/route.ts index b0d9da03103..855a5db017e 100644 --- a/app/api/config/route.ts +++ b/app/api/config/route.ts @@ -14,6 +14,7 @@ const DANGER_CONFIG = { disableFastLink: serverConfig.disableFastLink, customModels: serverConfig.customModels, defaultModel: serverConfig.defaultModel, + visionModels: serverConfig.visionModels, }; declare global { diff --git a/app/config/build.ts b/app/config/build.ts index aa7c10729b6..b2b1ad49da1 100644 --- a/app/config/build.ts +++ b/app/config/build.ts @@ -40,7 +40,6 @@ export const getBuildConfig = () => { buildMode, isApp, template: process.env.DEFAULT_INPUT_TEMPLATE ?? DEFAULT_INPUT_TEMPLATE, - visionModels: process.env.VISION_MODELS || "", }; }; diff --git a/app/config/server.ts b/app/config/server.ts index d5ffaab5467..73faa881527 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -23,6 +23,7 @@ declare global { DISABLE_FAST_LINK?: string; // disallow parse settings from url or not CUSTOM_MODELS?: string; // to control custom models DEFAULT_MODEL?: string; // to control default model in every new chat window + VISION_MODELS?: string; // to control vision models // stability only STABILITY_URL?: string; @@ -128,6 +129,7 @@ export const getServerSideConfig = () => { const disableGPT4 = !!process.env.DISABLE_GPT4; let customModels = process.env.CUSTOM_MODELS ?? ""; let defaultModel = process.env.DEFAULT_MODEL ?? ""; + let visionModels = process.env.VISION_MODELS ?? ""; if (disableGPT4) { if (customModels) customModels += ","; @@ -249,6 +251,7 @@ export const getServerSideConfig = () => { disableFastLink: !!process.env.DISABLE_FAST_LINK, customModels, defaultModel, + visionModels, allowedWebDavEndpoints, }; }; diff --git a/app/store/access.ts b/app/store/access.ts index 3c7f84adac0..f0352ad549f 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -131,6 +131,7 @@ const DEFAULT_ACCESS_STATE = { disableFastLink: false, customModels: "", defaultModel: "", + visionModels: "", // tts config edgeTTSVoiceName: "zh-CN-YunxiNeural", @@ -145,7 +146,10 @@ export const useAccessStore = createPersistStore( return get().needCode; }, - + setVisionModels() { + this.fetch(); + return get().visionModels; + }, edgeVoiceName() { this.fetch(); diff --git a/app/utils.ts b/app/utils.ts index 810dc7842b1..4f5b7b0b7de 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -6,7 +6,7 @@ import { ServiceProvider } from "./constant"; // import { fetch as tauriFetch, ResponseType } from "@tauri-apps/api/http"; import { fetch as tauriStreamFetch } from "./utils/stream"; import { VISION_MODEL_REGEXES, EXCLUDE_VISION_MODEL_REGEXES } from "./constant"; -import { getClientConfig } from "./config/client"; +import { useAccessStore } from "./store"; import { ModelSize } from "./typing"; export function trimTopic(topic: string) { @@ -255,8 +255,8 @@ export function getMessageImages(message: RequestMessage): string[] { } export function isVisionModel(model: string) { - const clientConfig = getClientConfig(); - const envVisionModels = clientConfig?.visionModels + const visionModels = useAccessStore.getState().visionModels; + const envVisionModels = visionModels ?.split(",") .map((m) => m.trim()); if (envVisionModels?.includes(model)) { From 266e9efd2e004664d73f0aa7f93a8684c0e5c55e Mon Sep 17 00:00:00 2001 From: code-october <148516338+code-october@users.noreply.github.com> Date: Mon, 30 Dec 2024 09:13:12 +0000 Subject: [PATCH 4/8] rename the function --- app/store/access.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/store/access.ts b/app/store/access.ts index f0352ad549f..1fed5dfeda7 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -146,7 +146,7 @@ export const useAccessStore = createPersistStore( return get().needCode; }, - setVisionModels() { + getVisionModels() { this.fetch(); return get().visionModels; }, From 6d84f9d3ae62da0c5d1617645f961d9f9e1a1a27 Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Tue, 31 Dec 2024 13:27:15 +0800 Subject: [PATCH 5/8] chore: update --- app/components/chat.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 138c0b86544..b15be19f9a0 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -876,7 +876,9 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { }, { title: Locale.Chat.ShortcutKey.clearContext, - keys: isMac ? ["⌘", "Shift", "k"] : ["Ctrl", "Shift", "k"], + keys: isMac + ? ["⌘", "Shift", "Backspace"] + : ["Ctrl", "Shift", "Backspace"], }, ]; return ( @@ -1513,7 +1515,7 @@ function _Chat() { const [showShortcutKeyModal, setShowShortcutKeyModal] = useState(false); useEffect(() => { - const handleKeyDown = (event: any) => { + const handleKeyDown = (event: KeyboardEvent) => { // 打开新聊天 command + shift + o if ( (event.metaKey || event.ctrlKey) && @@ -1564,11 +1566,11 @@ function _Chat() { event.preventDefault(); setShowShortcutKeyModal(true); } - // 清除上下文 command + shift + delete + // 清除上下文 command + shift + Backspace else if ( (event.metaKey || event.ctrlKey) && event.shiftKey && - event.key.toLowerCase() === "k" + event.key.toLowerCase() === "backspace" ) { event.preventDefault(); chatStore.updateCurrentSession((session) => { @@ -1582,10 +1584,10 @@ function _Chat() { } }; - window.addEventListener("keydown", handleKeyDown); + document.addEventListener("keydown", handleKeyDown); return () => { - window.removeEventListener("keydown", handleKeyDown); + document.removeEventListener("keydown", handleKeyDown); }; }, [messages, chatStore, navigate]); From aba4baf38403dd717ee04f5555ba81749d9ee6c8 Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Tue, 31 Dec 2024 14:25:43 +0800 Subject: [PATCH 6/8] chore: update --- app/components/chat.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index b15be19f9a0..6fcd23d3853 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -876,9 +876,7 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { }, { title: Locale.Chat.ShortcutKey.clearContext, - keys: isMac - ? ["⌘", "Shift", "Backspace"] - : ["Ctrl", "Shift", "Backspace"], + keys: isMac ? ["⌘", "Shift", "k"] : ["Ctrl", "Shift", "k"], }, ]; return ( @@ -1566,11 +1564,11 @@ function _Chat() { event.preventDefault(); setShowShortcutKeyModal(true); } - // 清除上下文 command + shift + Backspace + // 清除上下文 command + shift + k else if ( (event.metaKey || event.ctrlKey) && event.shiftKey && - event.key.toLowerCase() === "backspace" + event.key.toLowerCase() === "k" ) { event.preventDefault(); chatStore.updateCurrentSession((session) => { From c5d9b1131ec932e53cd0394c283e24549f6426cb Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Tue, 31 Dec 2024 14:38:58 +0800 Subject: [PATCH 7/8] fix: merge bug --- app/components/chat.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 25f692f2ad7..0d6051a31a3 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1614,7 +1614,7 @@ function _Chat() { event.key.toLowerCase() === "k" ) { event.preventDefault(); - chatStore.updateCurrentSession((session) => { + chatStore.updateTargetSession(session, (session) => { if (session.clearContextIndex === session.messages.length) { session.clearContextIndex = undefined; } else { @@ -1630,7 +1630,7 @@ function _Chat() { return () => { document.removeEventListener("keydown", handleKeyDown); }; - }, [messages, chatStore, navigate]); + }, [messages, chatStore, navigate, session]); const [showChatSidePanel, setShowChatSidePanel] = useState(false); From d184eb64585562de7f75e1ff7d291eb242b2f076 Mon Sep 17 00:00:00 2001 From: DDMeaqua Date: Tue, 31 Dec 2024 14:50:54 +0800 Subject: [PATCH 8/8] chore: cmd + shift+ backspace --- app/components/chat.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 0d6051a31a3..9990a359e14 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -902,7 +902,9 @@ export function ShortcutKeyModal(props: { onClose: () => void }) { }, { title: Locale.Chat.ShortcutKey.clearContext, - keys: isMac ? ["⌘", "Shift", "k"] : ["Ctrl", "Shift", "k"], + keys: isMac + ? ["⌘", "Shift", "backspace"] + : ["Ctrl", "Shift", "backspace"], }, ]; return ( @@ -1607,11 +1609,11 @@ function _Chat() { event.preventDefault(); setShowShortcutKeyModal(true); } - // 清除上下文 command + shift + k + // 清除上下文 command + shift + backspace else if ( (event.metaKey || event.ctrlKey) && event.shiftKey && - event.key.toLowerCase() === "k" + event.key.toLowerCase() === "backspace" ) { event.preventDefault(); chatStore.updateTargetSession(session, (session) => {