feat: support compress chat history

This commit is contained in:
Yifei Zhang
2023-03-19 15:13:10 +00:00
parent 9398b34b5c
commit c133cae04b
6 changed files with 125 additions and 24 deletions

View File

@@ -208,7 +208,10 @@ export function Chat(props: { showSideBar?: () => void }) {
<IconButton
icon={<BrainIcon />}
bordered
title="查看压缩后的历史 Prompt(开发中)"
title="查看压缩后的历史 Prompt"
onClick={() => {
showMemoryPrompt(session.memoryPrompt)
}}
/>
</div>
<div className={styles["window-action-button"]}>
@@ -320,6 +323,16 @@ function exportMessages(messages: Message[], topic: string) {
})
}
function showMemoryPrompt(prompt: string) {
showModal({
title: "上下文记忆 Prompt", children: <div className="markdown-body">
<pre className={styles['export-content']}>{prompt}</pre>
</div>, actions: [
<IconButton key="copy" icon={<CopyIcon />} bordered text="全部复制" onClick={() => copyToClipboard(prompt)} />,
]
})
}
export function Home() {
const [createNewSession] = useChatStore((state) => [state.newSession]);
const loading = !useChatStore?.persist?.hasHydrated();

View File

@@ -6,6 +6,7 @@ import styles from "./settings.module.scss";
import ResetIcon from "../icons/reload.svg";
import CloseIcon from "../icons/close.svg";
import ClearIcon from "../icons/clear.svg";
import { List, ListItem, Popover } from "./ui-lib";
@@ -15,10 +16,11 @@ import { Avatar } from "./home";
export function Settings(props: { closeSettings: () => void }) {
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
const [config, updateConfig, resetConfig] = useChatStore((state) => [
const [config, updateConfig, resetConfig, clearAllData] = useChatStore((state) => [
state.config,
state.updateConfig,
state.resetConfig,
state.clearAllData,
]);
return (
@@ -31,10 +33,10 @@ export function Settings(props: { closeSettings: () => void }) {
<div className={styles["window-actions"]}>
<div className={styles["window-action-button"]}>
<IconButton
icon={<CloseIcon />}
onClick={props.closeSettings}
icon={<ClearIcon />}
onClick={clearAllData}
bordered
title="重置所有选项"
title="清除所有数据"
/>
</div>
<div className={styles["window-action-button"]}>
@@ -45,6 +47,14 @@ export function Settings(props: { closeSettings: () => void }) {
title="重置所有选项"
/>
</div>
<div className={styles["window-action-button"]}>
<IconButton
icon={<CloseIcon />}
onClick={props.closeSettings}
bordered
title="关闭"
/>
</div>
</div>
</div>
<div className={styles["settings"]}>
@@ -147,6 +157,24 @@ export function Settings(props: { closeSettings: () => void }) {
></input>
</ListItem>
<ListItem>
<div className={styles["settings-title"]}>
</div>
<input
type="number"
min={500}
max={4000}
value={config.compressMessageLengthThreshold}
onChange={(e) =>
updateConfig(
(config) => (config.compressMessageLengthThreshold = e.currentTarget.valueAsNumber)
)
}
></input>
</ListItem>
<ListItem>
<div className={styles["settings-title"]}>

View File

@@ -90,7 +90,7 @@
}
.modal-content {
height: 40vh;
max-height: 40vh;
padding: var(--modal-padding);
overflow: auto;
}
@@ -118,7 +118,7 @@
width: 90vw;
.modal-content {
height: 50vh;
max-height: 50vh;
}
}
}