This commit is contained in:
GH Action - Upstream Sync 2023-08-15 01:03:49 +00:00
commit eda06d1f9e
10 changed files with 63 additions and 12 deletions

View File

@ -13,6 +13,7 @@ import {
fetchEventSource, fetchEventSource,
} from "@fortaine/fetch-event-source"; } from "@fortaine/fetch-event-source";
import { prettyObject } from "@/app/utils/format"; import { prettyObject } from "@/app/utils/format";
import { getClientConfig } from "@/app/config/client";
export interface OpenAIListModelResponse { export interface OpenAIListModelResponse {
object: string; object: string;
@ -28,13 +29,16 @@ export class ChatGPTApi implements LLMApi {
path(path: string): string { path(path: string): string {
let openaiUrl = useAccessStore.getState().openaiUrl; let openaiUrl = useAccessStore.getState().openaiUrl;
const apiPath = "/api/openai";
if (openaiUrl.length === 0) { if (openaiUrl.length === 0) {
openaiUrl = DEFAULT_API_HOST; const isApp = !!getClientConfig()?.isApp;
openaiUrl = isApp ? DEFAULT_API_HOST : apiPath;
} }
if (openaiUrl.endsWith("/")) { if (openaiUrl.endsWith("/")) {
openaiUrl = openaiUrl.slice(0, openaiUrl.length - 1); 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; openaiUrl = "https://" + openaiUrl;
} }
return [openaiUrl, path].join("/"); return [openaiUrl, path].join("/");

View File

@ -940,7 +940,7 @@ function _Chat() {
const prevPageMsgIndex = msgRenderIndex - CHAT_PAGE_SIZE; const prevPageMsgIndex = msgRenderIndex - CHAT_PAGE_SIZE;
const nextPageMsgIndex = msgRenderIndex + CHAT_PAGE_SIZE; const nextPageMsgIndex = msgRenderIndex + CHAT_PAGE_SIZE;
if (isTouchTopEdge) { if (isTouchTopEdge && !isTouchBottomEdge) {
setMsgRenderIndex(prevPageMsgIndex); setMsgRenderIndex(prevPageMsgIndex);
} else if (isTouchBottomEdge) { } else if (isTouchBottomEdge) {
setMsgRenderIndex(nextPageMsgIndex); setMsgRenderIndex(nextPageMsgIndex);

View File

@ -15,7 +15,7 @@ import dynamic from "next/dynamic";
import { Path, SlotID } from "../constant"; import { Path, SlotID } from "../constant";
import { ErrorBoundary } from "./error"; import { ErrorBoundary } from "./error";
import { getLang } from "../locales"; import { getISOLang, getLang } from "../locales";
import { import {
HashRouter as Router, HashRouter as Router,
@ -86,6 +86,17 @@ export function useSwitchTheme() {
}, [config.theme]); }, [config.theme]);
} }
function useHtmlLang() {
useEffect(() => {
const lang = getISOLang();
const htmlLang = document.documentElement.lang;
if (lang !== htmlLang) {
document.documentElement.lang = lang;
}
}, []);
}
const useHasHydrated = () => { const useHasHydrated = () => {
const [hasHydrated, setHasHydrated] = useState<boolean>(false); const [hasHydrated, setHasHydrated] = useState<boolean>(false);
@ -168,6 +179,7 @@ export function useLoadData() {
export function Home() { export function Home() {
useSwitchTheme(); useSwitchTheme();
useLoadData(); useLoadData();
useHtmlLang();
useEffect(() => { useEffect(() => {
console.log("[Config] got config from build time", getClientConfig()); console.log("[Config] got config from build time", getClientConfig());

View File

@ -38,12 +38,6 @@ export function Mermaid(props: { code: string }) {
if (!svg) return; if (!svg) return;
const text = new XMLSerializer().serializeToString(svg); const text = new XMLSerializer().serializeToString(svg);
const blob = new Blob([text], { type: "image/svg+xml" }); const blob = new Blob([text], { type: "image/svg+xml" });
console.log(blob);
// const url = URL.createObjectURL(blob);
// const win = window.open(url);
// if (win) {
// win.onload = () => URL.revokeObjectURL(url);
// }
showImageModal(URL.createObjectURL(blob)); showImageModal(URL.createObjectURL(blob));
} }
@ -152,11 +146,11 @@ export function Markdown(
className="markdown-body" className="markdown-body"
style={{ style={{
fontSize: `${props.fontSize ?? 14}px`, fontSize: `${props.fontSize ?? 14}px`,
direction: /[\u0600-\u06FF]/.test(props.content) ? "rtl" : "ltr",
}} }}
ref={mdRef} ref={mdRef}
onContextMenu={props.onContextMenu} onContextMenu={props.onContextMenu}
onDoubleClickCapture={props.onDoubleClickCapture} onDoubleClickCapture={props.onDoubleClickCapture}
dir="auto"
> >
{props.loading ? ( {props.loading ? (
<LoadingIcon /> <LoadingIcon />

View File

@ -529,6 +529,22 @@ export function Settings() {
></InputRange> ></InputRange>
</ListItem> </ListItem>
<ListItem
title={Locale.Settings.AutoGenerateTitle.Title}
subTitle={Locale.Settings.AutoGenerateTitle.SubTitle}
>
<input
type="checkbox"
checked={config.enableAutoGenerateTitle}
onChange={(e) =>
updateConfig(
(config) =>
(config.enableAutoGenerateTitle = e.currentTarget.checked),
)
}
></input>
</ListItem>
<ListItem <ListItem
title={Locale.Settings.SendPreviewBubble.Title} title={Locale.Settings.SendPreviewBubble.Title}
subTitle={Locale.Settings.SendPreviewBubble.SubTitle} subTitle={Locale.Settings.SendPreviewBubble.SubTitle}

View File

@ -170,6 +170,10 @@ const cn = {
Title: "预览气泡", Title: "预览气泡",
SubTitle: "在预览气泡中预览 Markdown 内容", SubTitle: "在预览气泡中预览 Markdown 内容",
}, },
AutoGenerateTitle: {
Title: "自动生成标题",
SubTitle: "根据对话内容生成合适的标题",
},
Mask: { Mask: {
Splash: { Splash: {
Title: "面具启动页", Title: "面具启动页",

View File

@ -172,6 +172,10 @@ const en: LocaleType = {
Title: "Send Preview Bubble", Title: "Send Preview Bubble",
SubTitle: "Preview markdown in bubble", SubTitle: "Preview markdown in bubble",
}, },
AutoGenerateTitle: {
Title: "Auto Generate Title",
SubTitle: "Generate a suitable title based on the conversation content",
},
Mask: { Mask: {
Splash: { Splash: {
Title: "Mask Splash Screen", Title: "Mask Splash Screen",

View File

@ -116,3 +116,13 @@ export function changeLang(lang: Lang) {
setItem(LANG_KEY, lang); setItem(LANG_KEY, lang);
location.reload(); location.reload();
} }
export function getISOLang() {
const isoLangString: Record<string, string> = {
cn: "zh-Hans",
tw: "zh-Hant",
};
const lang = getLang();
return isoLangString[lang] ?? lang;
}

View File

@ -479,6 +479,7 @@ export const useChatStore = create<ChatStore>()(
}, },
summarizeSession() { summarizeSession() {
const config = useAppConfig.getState();
const session = get().currentSession(); const session = get().currentSession();
// remove error messages if any // remove error messages if any
@ -487,6 +488,7 @@ export const useChatStore = create<ChatStore>()(
// should summarize topic after chating more than 50 words // should summarize topic after chating more than 50 words
const SUMMARIZE_MIN_LEN = 50; const SUMMARIZE_MIN_LEN = 50;
if ( if (
config.enableAutoGenerateTitle &&
session.topic === DEFAULT_TOPIC && session.topic === DEFAULT_TOPIC &&
countMessages(messages) >= SUMMARIZE_MIN_LEN countMessages(messages) >= SUMMARIZE_MIN_LEN
) { ) {

View File

@ -27,6 +27,7 @@ export const DEFAULT_CONFIG = {
theme: Theme.Auto as Theme, theme: Theme.Auto as Theme,
tightBorder: !!getClientConfig()?.isApp, tightBorder: !!getClientConfig()?.isApp,
sendPreviewBubble: true, sendPreviewBubble: true,
enableAutoGenerateTitle: true,
sidebarWidth: 300, sidebarWidth: 300,
disablePromptHint: false, disablePromptHint: false,
@ -147,7 +148,7 @@ export const useAppConfig = create<ChatConfigStore>()(
}), }),
{ {
name: StoreKey.Config, name: StoreKey.Config,
version: 3.6, version: 3.7,
migrate(persistedState, version) { migrate(persistedState, version) {
const state = persistedState as ChatConfig; const state = persistedState as ChatConfig;
@ -170,6 +171,10 @@ export const useAppConfig = create<ChatConfigStore>()(
state.modelConfig.enableInjectSystemPrompts = true; state.modelConfig.enableInjectSystemPrompts = true;
} }
if (version < 3.7) {
state.enableAutoGenerateTitle = true;
}
return state as any; return state as any;
}, },
}, },