diff --git a/.lintstagedrc.json b/.lintstagedrc.json
index 023bf16a..58784bad 100644
--- a/.lintstagedrc.json
+++ b/.lintstagedrc.json
@@ -1,6 +1,6 @@
{
- "./app/**/*.{js,ts,jsx,tsx,json,html,css,scss,md}": [
- "eslint --fix",
- "prettier --write"
- ]
-}
\ No newline at end of file
+ "./app/**/*.{js,ts,jsx,tsx,json,html,css,md}": [
+ "eslint --fix",
+ "prettier --write"
+ ]
+}
diff --git a/app/components/home.module.scss b/app/components/home.module.scss
index fb96bd45..87231fee 100644
--- a/app/components/home.module.scss
+++ b/app/components/home.module.scss
@@ -221,6 +221,14 @@
margin-bottom: 100px;
}
+.chat-body-title {
+ cursor: pointer;
+
+ &:hover {
+ text-decoration: underline;
+ }
+}
+
.chat-message {
display: flex;
flex-direction: row;
diff --git a/app/components/home.tsx b/app/components/home.tsx
index de2cc8fe..847b6cf4 100644
--- a/app/components/home.tsx
+++ b/app/components/home.tsx
@@ -333,7 +333,17 @@ export function Chat(props: {
className={styles["window-header-title"]}
onClick={props?.showSideBar}
>
-
+
{
+ const newTopic = prompt(Locale.Chat.Rename, session.topic);
+ if (newTopic && newTopic !== session.topic) {
+ chatStore.updateCurrentSession(
+ (session) => (session.topic = newTopic!),
+ );
+ }
+ }}
+ >
{session.topic}
diff --git a/app/locales/cn.ts b/app/locales/cn.ts
index 76f6a770..e9cbad9e 100644
--- a/app/locales/cn.ts
+++ b/app/locales/cn.ts
@@ -18,6 +18,7 @@ const cn = {
Stop: "停止",
Retry: "重试",
},
+ Rename: "重命名对话",
Typing: "正在输入…",
Input: (submitKey: string) => {
var inputHints = `输入消息,${submitKey} 发送`;
@@ -124,7 +125,7 @@ const cn = {
History: (content: string) =>
"这是 ai 和用户的历史聊天总结作为前情提要:" + content,
Topic:
- "直接返回这句话的简要主题,不要解释,如果没有主题,请直接返回“闲聊”",
+ "使用四到五个字直接返回这句话的简要主题,不要解释、不要标点、不要语气词、不要多余文本,如果没有主题,请直接返回“闲聊”",
Summarize:
"简要总结一下你和用户的对话,用作后续的上下文提示 prompt,控制在 50 字以内",
},
diff --git a/app/locales/en.ts b/app/locales/en.ts
index d21679ab..f31badd0 100644
--- a/app/locales/en.ts
+++ b/app/locales/en.ts
@@ -20,6 +20,7 @@ const en: LocaleType = {
Stop: "Stop",
Retry: "Retry",
},
+ Rename: "Rename Chat",
Typing: "Typing…",
Input: (submitKey: string) => {
var inputHints = `Type something and press ${submitKey} to send`;
@@ -129,7 +130,7 @@ const en: LocaleType = {
"This is a summary of the chat history between the AI and the user as a recap: " +
content,
Topic:
- "Provide a brief topic of the sentence without explanation. If there is no topic, return 'Chitchat'.",
+ "Please generate a four to five word title summarizing our conversation without any lead-in, punctuation, quotation marks, periods, symbols, or additional text. Remove enclosing quotation marks.",
Summarize:
"Summarize our discussion briefly in 50 characters or less to use as a prompt for future context.",
},
diff --git a/app/locales/tw.ts b/app/locales/tw.ts
index 63312eb4..b78e1b83 100644
--- a/app/locales/tw.ts
+++ b/app/locales/tw.ts
@@ -19,6 +19,7 @@ const tw: LocaleType = {
Stop: "停止",
Retry: "重試",
},
+ Rename: "重命名對話",
Typing: "正在輸入…",
Input: (submitKey: string) => {
var inputHints = `輸入訊息後,按下 ${submitKey} 鍵即可發送`;
diff --git a/app/store/app.ts b/app/store/app.ts
index 8a978c0a..118e9ed6 100644
--- a/app/store/app.ts
+++ b/app/store/app.ts
@@ -206,6 +206,10 @@ interface ChatStore {
clearAllData: () => void;
}
+function countMessages(msgs: Message[]) {
+ return msgs.reduce((pre, cur) => pre + cur.content.length, 0);
+}
+
const LOCAL_KEY = "chat-next-web-store";
export const useChatStore = create()(
@@ -393,8 +397,12 @@ export const useChatStore = create()(
summarizeSession() {
const session = get().currentSession();
- if (session.topic === DEFAULT_TOPIC && session.messages.length >= 3) {
- // should summarize topic
+ // should summarize topic after chating more than 50 words
+ const SUMMARIZE_MIN_LEN = 50;
+ if (
+ session.topic === DEFAULT_TOPIC &&
+ countMessages(session.messages) >= SUMMARIZE_MIN_LEN
+ ) {
requestWithPrompt(session.messages, Locale.Store.Prompt.Topic).then(
(res) => {
get().updateCurrentSession(
@@ -408,10 +416,7 @@ export const useChatStore = create()(
let toBeSummarizedMsgs = session.messages.slice(
session.lastSummarizeIndex,
);
- const historyMsgLength = toBeSummarizedMsgs.reduce(
- (pre, cur) => pre + cur.content.length,
- 0,
- );
+ const historyMsgLength = countMessages(toBeSummarizedMsgs);
if (historyMsgLength > 4000) {
toBeSummarizedMsgs = toBeSummarizedMsgs.slice(