diff --git a/README.md b/README.md index 3b6308be9..1764f2dbe 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ One-Click to deploy well-designed ChatGPT web UI on Vercel. [Demo](https://chat-gpt-next-web.vercel.app/) / [Issues](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [Join Discord](https://discord.gg/zrhvHCr79N) / [Buy Me a Coffee](https://www.buymeacoffee.com/yidadaa) -[演示](https://chat-gpt-next-web.vercel.app/) / [反馈](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [QQ 群](https://user-images.githubusercontent.com/16968934/231789746-41f34d05-6ef9-43f3-a1d1-ff109d4c3c14.jpg) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg) +[演示](https://chat-gpt-next-web.vercel.app/) / [反馈](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [QQ 群](https://user-images.githubusercontent.com/16968934/233002565-139daa1a-eb3a-4a12-ac37-6418e7a15d36.png) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg) [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FYidadaa%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web) @@ -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 diff --git a/app/api/common.ts b/app/api/common.ts index 53ab18ed6..22e71884f 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -18,10 +18,15 @@ export async function requestOpenai(req: NextRequest) { console.log("[Proxy] ", openaiPath); console.log("[Base Url]", baseUrl); + if (process.env.OPENAI_ORG_ID) { + console.log("[Org ID]", process.env.OPENAI_ORG_ID); + } + return fetch(`${baseUrl}/${openaiPath}`, { headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, + ...(process.env.OPENAI_ORG_ID && { "OpenAI-Organization": process.env.OPENAI_ORG_ID }), }, method: req.method, body: req.body, diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 3c66627f6..5dce8fd61 100644 --- a/app/components/chat.tsx +++ b/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(); diff --git a/app/icons/user.svg b/app/icons/user.svg deleted file mode 100644 index 7f91de4dc..000000000 --- a/app/icons/user.svg +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 🤣 - - - - - \ No newline at end of file diff --git a/app/locales/cn.ts b/app/locales/cn.ts index d0ab27ca2..1c198195e 100644 --- a/app/locales/cn.ts +++ b/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: { diff --git a/app/locales/jp.ts b/app/locales/jp.ts index a793b5fe0..2818820b5 100644 --- a/app/locales/jp.ts +++ b/app/locales/jp.ts @@ -109,9 +109,9 @@ const jp = { `組み込み ${builtin} 件、ユーザー定義 ${custom} 件`, Edit: "編集", Modal: { - Title: "提示词列表", - Add: "增加一条", - Search: "搜尋提示詞", + Title: "プロンプトリスト", + Add: "新規追加", + Search: "プロンプトワード検索", }, }, HistoryCount: { diff --git a/app/locales/tw.ts b/app/locales/tw.ts index 2fbb2e477..44c07898d 100644 --- a/app/locales/tw.ts +++ b/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: "確認清除所有對話、設定數據?", }, diff --git a/app/store/app.ts b/app/store/app.ts index 39df9ef79..8d875fee5 100644 --- a/app/store/app.ts +++ b/app/store/app.ts @@ -462,6 +462,7 @@ export const useChatStore = create()( const context = session.context.slice(); + // long term memory if ( session.sendMemory && session.memoryPrompt && @@ -471,9 +472,33 @@ export const useChatStore = create()( 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.max( + 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()( config.compressMessageLengthThreshold, ); - if (historyMsgLength > config.compressMessageLengthThreshold) { + if ( + historyMsgLength > config.compressMessageLengthThreshold && + session.sendMemory + ) { requestChatStream( toBeSummarizedMsgs.concat({ role: "system",