Selaa lähdekoodia

Merge branch 'main' of https://github.com/Yidadaa/ChatGPT-Next-Web

GH Action - Upstream Sync 2 vuotta sitten
vanhempi
commit
735afc64f6
7 muutettua tiedostoa jossa 45 lisäystä ja 50 poistoa
  1. 1 1
      README.md
  2. 1 0
      app/components/chat.tsx
  3. 0 34
      app/icons/user.svg
  4. 6 6
      app/locales/cn.ts
  5. 3 3
      app/locales/jp.ts
  6. 3 3
      app/locales/tw.ts
  7. 31 3
      app/store/app.ts

+ 1 - 1
README.md

@@ -40,7 +40,7 @@ One-Click to deploy well-designed ChatGPT web UI on Vercel.
 - [ ] Share as image, share to ShareGPT
 - [ ] Desktop App with tauri
 - [ ] Self-host Model: support llama, alpaca, ChatGLM, BELLE etc.
-- [ ] Plugins: support network search, caculator, any other apis etc. [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165)
+- [ ] Plugins: support network search, calculator, any other apis etc. [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165)
 
 ### Not in Plan
 

+ 1 - 0
app/components/chat.tsx

@@ -708,6 +708,7 @@ export function Chat(props: {
         className={styles["chat-body"]}
         ref={scrollRef}
         onScroll={(e) => onChatBodyScroll(e.currentTarget)}
+        onMouseDown={() => inputRef.current?.blur()}
         onWheel={(e) => setAutoScroll(hitBottom && e.deltaY > 0)}
         onTouchStart={() => {
           inputRef.current?.blur();

+ 0 - 34
app/icons/user.svg

@@ -1,34 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="38"
-  height="38" viewBox="0 0 38 38" fill="none">
-  <defs>
-    <filter id="filter_0" x="-4" y="-4" width="38" height="38" filterUnits="userSpaceOnUse"
-      color-interpolation-filters="sRGB">
-      <feFlood flood-opacity="0" result="BackgroundImageFix" />
-      <feColorMatrix in="SourceAlpha" type="matrix"
-        values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" />
-      <feOffset dx="0" dy="2" />
-      <feGaussianBlur stdDeviation="2" />
-      <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0" />
-      <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_Shadow" />
-      <feBlend mode="normal" in="SourceGraphic" in2="effect1_Shadow" result="shape" />
-    </filter>
-    <rect id="path_0" x="0" y="0" width="30" height="30" />
-  </defs>
-  <g opacity="1" transform="translate(4 2)  rotate(0 15 15)">
-    <g id="undefined" filter="url(#filter_0)">
-      <rect stroke="#000000" stroke-width="1" stroke-opacity="0.05" />
-      <rect x="0" y="0" width="30" height="30" rx="10" />
-    </g>
-    <mask id="bg-mask-0" fill="white">
-      <use xlink:href="#path_0"></use>
-    </mask>
-    <g mask="url(#bg-mask-0)">
-      <g opacity="1" transform="translate(6 4.5)  rotate(0 9 11)">
-        <text>
-          <tspan x="0" y="16.240000000000002" font-size="14" line-height="0" fill="#000000"
-            opacity="1" font-family="SourceHanSansCN-Regular" letter-spacing="0">🤣</tspan>
-        </text>
-      </g>
-    </g>
-  </g>
-</svg>

+ 6 - 6
app/locales/cn.ts

@@ -38,12 +38,12 @@ const cn = {
     MessageFromChatGPT: "来自 ChatGPT 的消息",
   },
   Memory: {
-    Title: "历史记忆",
-    EmptyContent: "尚未记忆",
-    Send: "发送记忆",
-    Copy: "复制记忆",
+    Title: "历史摘要",
+    EmptyContent: "尚未总结",
+    Send: "启用总结并发送摘要",
+    Copy: "复制摘要",
     Reset: "重置对话",
-    ResetConfirm: "重置后将清空当前对话记录以及历史记忆,确认重置?",
+    ResetConfirm: "重置后将清空当前对话记录以及历史摘要,确认重置?",
   },
   Home: {
     NewChat: "新的聊天",
@@ -108,7 +108,7 @@ const cn = {
       Modal: {
         Title: "提示词列表",
         Add: "增加一条",
-        Search: "搜尋提示詞",
+        Search: "搜索提示词",
       },
     },
     HistoryCount: {

+ 3 - 3
app/locales/jp.ts

@@ -109,9 +109,9 @@ const jp = {
         `組み込み ${builtin} 件、ユーザー定義 ${custom} 件`,
       Edit: "編集",
       Modal: {
-        Title: "提示词列表",
-        Add: "增加一条",
-        Search: "搜尋提示詞",
+        Title: "プロンプトリスト",
+        Add: "新規追加",
+        Search: "プロンプトワード検索",
       },
     },
     HistoryCount: {

+ 3 - 3
app/locales/tw.ts

@@ -108,7 +108,7 @@ const tw: LocaleType = {
       Modal: {
         Title: "提示詞列表",
         Add: "增加一條",
-        Search: "搜索提示词",
+        Search: "搜尋提示詞",
       },
     },
     HistoryCount: {
@@ -160,9 +160,9 @@ const tw: LocaleType = {
       History: (content: string) =>
         "這是 AI 與用戶的歷史聊天總結,作為前情提要:" + content,
       Topic:
-        "Summarise the conversation in a short and concise eye-catching title that instantly conveys the main topic. Use as few words as possible. Use the language used in the enquiry, e.g. use English for English enquiry, use zh-hant for traditional chinese enquiry. Don't use quotation marks at the beginning and the end.",
+        "Use the language used by the user (e.g. en for english conversation, zh-hant for chinese conversation, etc.) to generate a title (at most 6 words) summarizing our conversation without any lead-in, quotation marks, preamble like 'Title:', direct text copies, single-word replies, quotation marks, translations, or brackets. Remove enclosing quotation marks. The title should make third-party grasp the essence of the conversation in first sight.",
       Summarize:
-        "Summarise the conversation in at most 250 tokens for continuing the conversation in future. Use the language used in the conversation, e.g. use English for English conversation, use zh-hant for traditional chinese conversation.",
+        "Use the language used by the user (e.g. en-us for english conversation, zh-hant for chinese conversation, etc.) to summarise the conversation in at most 200 words. The summary will be used as prompt for you to continue the conversation in the future.",
     },
     ConfirmClearAll: "確認清除所有對話、設定數據?",
   },

+ 31 - 3
app/store/app.ts

@@ -462,6 +462,7 @@ export const useChatStore = create<ChatStore>()(
 
         const context = session.context.slice();
 
+        // long term memory
         if (
           session.sendMemory &&
           session.memoryPrompt &&
@@ -471,9 +472,33 @@ export const useChatStore = create<ChatStore>()(
           context.push(memoryPrompt);
         }
 
-        const recentMessages = context.concat(
-          messages.slice(Math.max(0, n - config.historyMessageCount)),
+        // get short term and unmemoried long term memory
+        const shortTermMemoryMessageIndex = Math.max(
+          0,
+          n - config.historyMessageCount,
         );
+        const longTermMemoryMessageIndex = session.lastSummarizeIndex;
+        const oldestIndex = Math.min(
+          shortTermMemoryMessageIndex,
+          longTermMemoryMessageIndex,
+        );
+        const threshold = config.compressMessageLengthThreshold;
+
+        // get recent messages as many as possible
+        const reversedRecentMessages = [];
+        for (
+          let i = n - 1, count = 0;
+          i >= oldestIndex && count < threshold;
+          i -= 1
+        ) {
+          const msg = messages[i];
+          if (!msg || msg.isError) continue;
+          count += msg.content.length;
+          reversedRecentMessages.push(msg);
+        }
+
+        // concat
+        const recentMessages = context.concat(reversedRecentMessages.reverse());
 
         return recentMessages;
       },
@@ -542,7 +567,10 @@ export const useChatStore = create<ChatStore>()(
           config.compressMessageLengthThreshold,
         );
 
-        if (historyMsgLength > config.compressMessageLengthThreshold) {
+        if (
+          historyMsgLength > config.compressMessageLengthThreshold &&
+          session.sendMemory
+        ) {
           requestChatStream(
             toBeSummarizedMsgs.concat({
               role: "system",