From 20a508e2d6e16252e44f6a9cbb07dd5c195b6fc3 Mon Sep 17 00:00:00 2001 From: imldy Date: Sat, 15 Jul 2023 02:13:39 +0800 Subject: [PATCH 1/5] feat: add autoGenerateTitle option (cherry picked from commit 656ab94a9c4edfee820616b8cfc39f5ee9952a3a) --- app/components/settings.tsx | 16 ++++++++++++++++ app/locales/cn.ts | 5 +++++ app/locales/en.ts | 5 +++++ app/store/chat.ts | 2 ++ app/store/config.ts | 7 ++++++- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index c438f68c5..1e6ef7139 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -529,6 +529,22 @@ export function Settings() { > + + + updateConfig( + (config) => + (config.enableAutoGenerateTitle = e.currentTarget.checked), + ) + } + > + + ()( }, summarizeSession() { + const config = useAppConfig.getState(); const session = get().currentSession(); // remove error messages if any @@ -487,6 +488,7 @@ export const useChatStore = create()( // 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 ) { diff --git a/app/store/config.ts b/app/store/config.ts index d963d39dd..7070ea05e 100644 --- a/app/store/config.ts +++ b/app/store/config.ts @@ -27,6 +27,7 @@ export const DEFAULT_CONFIG = { theme: Theme.Auto as Theme, tightBorder: !!getClientConfig()?.isApp, sendPreviewBubble: true, + enableAutoGenerateTitle: true, sidebarWidth: 300, disablePromptHint: false, @@ -147,7 +148,7 @@ export const useAppConfig = create()( }), { name: StoreKey.Config, - version: 3.6, + version: 3.7, migrate(persistedState, version) { const state = persistedState as ChatConfig; @@ -170,6 +171,10 @@ export const useAppConfig = create()( state.modelConfig.enableInjectSystemPrompts = true; } + if (version < 3.7) { + state.enableAutoGenerateTitle = true; + } + return state as any; }, }, From 803b66ae9d871300bb077a0b89ddf050d5240936 Mon Sep 17 00:00:00 2001 From: imldy Date: Mon, 14 Aug 2023 20:47:02 +0800 Subject: [PATCH 2/5] chore: Concise description --- app/locales/cn.ts | 3 +-- app/locales/en.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 0636a116a..3929e09e7 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -172,8 +172,7 @@ const cn = { }, AutoGenerateTitle: { Title: "自动生成标题", - SubTitle: - "根据对话内容生成合适的标题(需标题为默认标题,并且内容长度大于设定的最小长度)", + SubTitle: "根据对话内容生成合适的标题", }, Mask: { Splash: { diff --git a/app/locales/en.ts b/app/locales/en.ts index 75cd02ed5..d37149c92 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -174,8 +174,7 @@ const en: LocaleType = { }, AutoGenerateTitle: { Title: "Auto Generate Title", - SubTitle: - "Generate a suitable title based on the conversation content (requires default title and content length greater than the set minimum length)", + SubTitle: "Generate a suitable title based on the conversation content", }, Mask: { Splash: { From ae8226907ff03100cafd45ba5d648d2a62f77fef Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Mon, 14 Aug 2023 21:36:29 +0800 Subject: [PATCH 3/5] feat: close #2621 use better default api url --- app/client/platforms/openai.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 9dc92e9ae..fd4eb59ce 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -13,6 +13,7 @@ import { fetchEventSource, } from "@fortaine/fetch-event-source"; import { prettyObject } from "@/app/utils/format"; +import { getClientConfig } from "@/app/config/client"; export interface OpenAIListModelResponse { object: string; @@ -28,13 +29,16 @@ export class ChatGPTApi implements LLMApi { path(path: string): string { let openaiUrl = useAccessStore.getState().openaiUrl; + const apiPath = "/api/openai"; + if (openaiUrl.length === 0) { - openaiUrl = DEFAULT_API_HOST; + const isApp = !!getClientConfig()?.isApp; + openaiUrl = isApp ? DEFAULT_API_HOST : apiPath; } if (openaiUrl.endsWith("/")) { openaiUrl = openaiUrl.slice(0, openaiUrl.length - 1); } - if (!openaiUrl.startsWith("http") && !openaiUrl.startsWith("/api/openai")) { + if (!openaiUrl.startsWith("http") && !openaiUrl.startsWith(apiPath)) { openaiUrl = "https://" + openaiUrl; } return [openaiUrl, path].join("/"); From e8e01aa60d559fb7654b0f5e9521aa637e3d0b22 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Mon, 14 Aug 2023 21:55:18 +0800 Subject: [PATCH 4/5] feat: close #2618 use correct html lang attr --- app/components/home.tsx | 14 +++++++++++++- app/layout.tsx | 2 +- app/locales/index.ts | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/components/home.tsx b/app/components/home.tsx index c6829c2dc..745298d56 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -15,7 +15,7 @@ import dynamic from "next/dynamic"; import { Path, SlotID } from "../constant"; import { ErrorBoundary } from "./error"; -import { getLang } from "../locales"; +import { getISOLang, getLang } from "../locales"; import { HashRouter as Router, @@ -86,6 +86,17 @@ export function useSwitchTheme() { }, [config.theme]); } +function useHtmlLang() { + useEffect(() => { + const lang = getISOLang(); + const htmlLang = document.documentElement.lang; + + if (lang !== htmlLang) { + document.documentElement.lang = lang; + } + }, []); +} + const useHasHydrated = () => { const [hasHydrated, setHasHydrated] = useState(false); @@ -168,6 +179,7 @@ export function useLoadData() { export function Home() { useSwitchTheme(); useLoadData(); + useHtmlLang(); useEffect(() => { console.log("[Config] got config from build time", getClientConfig()); diff --git a/app/layout.tsx b/app/layout.tsx index 883a268d3..5e0762653 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -3,7 +3,7 @@ import "./styles/globals.scss"; import "./styles/markdown.scss"; import "./styles/highlight.scss"; import { getClientConfig } from "./config/client"; -import { type Metadata } from 'next'; +import { type Metadata } from "next"; export const metadata: Metadata = { title: "ChatGPT Next Web", diff --git a/app/locales/index.ts b/app/locales/index.ts index 7ece45838..528600bec 100644 --- a/app/locales/index.ts +++ b/app/locales/index.ts @@ -116,3 +116,13 @@ export function changeLang(lang: Lang) { setItem(LANG_KEY, lang); location.reload(); } + +export function getISOLang() { + const isoLangString: Record = { + cn: "zh-Hans", + tw: "zh-Hant", + }; + + const lang = getLang(); + return isoLangString[lang] ?? lang; +} From db5c7aba788c5f0a1a347f7d68baa5f0b1c5f516 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Mon, 14 Aug 2023 22:11:38 +0800 Subject: [PATCH 5/5] fix: #2615 scrollbar jitter under certain message counts --- app/components/chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index a99f72f15..f661d0a47 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -940,7 +940,7 @@ function _Chat() { const prevPageMsgIndex = msgRenderIndex - CHAT_PAGE_SIZE; const nextPageMsgIndex = msgRenderIndex + CHAT_PAGE_SIZE; - if (isTouchTopEdge) { + if (isTouchTopEdge && !isTouchBottomEdge) { setMsgRenderIndex(prevPageMsgIndex); } else if (isTouchBottomEdge) { setMsgRenderIndex(nextPageMsgIndex);