From ff166f7b4cf52be5716fb93b7c0f3c872def2ef5 Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Mon, 26 Feb 2024 17:18:46 +0800 Subject: [PATCH 1/8] chore: adjust for ollama support (#4129) --- app/client/api.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/app/client/api.ts b/app/client/api.ts index 9133e2a64..c4d548a41 100644 --- a/app/client/api.ts +++ b/app/client/api.ts @@ -151,7 +151,6 @@ export function getHeaders() { const accessStore = useAccessStore.getState(); const headers: Record = { "Content-Type": "application/json", - "x-requested-with": "XMLHttpRequest", Accept: "application/json", }; const modelConfig = useChatStore.getState().currentSession().mask.modelConfig; From aacd26c7db7d87953d14f3c0cf841cf422a2e027 Mon Sep 17 00:00:00 2001 From: Fred Date: Mon, 26 Feb 2024 18:14:10 +0800 Subject: [PATCH 2/8] feat: bump version --- src-tauri/tauri.conf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index d88194020..405d267ff 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -9,7 +9,7 @@ }, "package": { "productName": "NextChat", - "version": "2.10.3" + "version": "2.11.2" }, "tauri": { "allowlist": { From bc1794fb4af5229c4811008ad247b57bbf091334 Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:15:00 +0800 Subject: [PATCH 3/8] feat: bump version (#4133) --- src-tauri/tauri.conf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index d88194020..405d267ff 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -9,7 +9,7 @@ }, "package": { "productName": "NextChat", - "version": "2.10.3" + "version": "2.11.2" }, "tauri": { "allowlist": { From f22e36e52f35a1d447b50d3b8afb1b70bb160961 Mon Sep 17 00:00:00 2001 From: DonaldBear Date: Tue, 27 Feb 2024 00:16:56 +0800 Subject: [PATCH 4/8] feat(tw.ts): added new translations (#4142) * feat(tw.ts): added new translations I have translated previously untranslated text in response to the latest update. * feat(tw.ts): added new translations I have translated previously untranslated text in response to the latest update. --- app/locales/tw.ts | 261 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 256 insertions(+), 5 deletions(-) diff --git a/app/locales/tw.ts b/app/locales/tw.ts index af47e30ff..80e1b054f 100644 --- a/app/locales/tw.ts +++ b/app/locales/tw.ts @@ -1,16 +1,36 @@ +import { getClientConfig } from "../config/client"; import { SubmitKey } from "../store/config"; -import type { PartialLocaleType } from "./index"; -const tw: PartialLocaleType = { +const isApp = !!getClientConfig()?.isApp; + +const tw = { WIP: "該功能仍在開發中……", Error: { - Unauthorized: "目前您的狀態是未授權,請前往[設定頁面](/#/auth)輸入授權碼。", + Unauthorized: isApp + ? "檢測到無效 API Key,請前往[設定](/#/settings)頁檢查 API Key 是否配置正確。" + : "訪問密碼不正確或為空,請前往[登錄](/#/auth)頁輸入正確的訪問密碼,或者在[設定](/#/settings)頁填入你自己的 OpenAI API Key。", + }, + + Auth: { + Title: "需要密碼", + Tips: "管理員開啟了密碼驗證,請在下方填入訪問碼", + SubTips: "或者輸入你的 OpenAI 或 Google API 密鑰", + Input: "在此處填寫訪問碼", + Confirm: "確認", + Later: "稍後再說", }, ChatItem: { ChatItemCount: (count: number) => `${count} 則對話`, }, Chat: { SubTitle: (count: number) => `您已經與 ChatGPT 進行了 ${count} 則對話`, + EditMessage: { + Title: "編輯消息記錄", + Topic: { + Title: "聊天主題", + SubTitle: "更改當前聊天主題", + }, + }, Actions: { ChatList: "檢視訊息列表", CompressedHistory: "檢視壓縮後的歷史 Prompt", @@ -18,7 +38,33 @@ const tw: PartialLocaleType = { Copy: "複製", Stop: "停止", Retry: "重試", + Pin: "固定", + PinToastContent: "已將 1 條對話固定至預設提示詞", + PinToastAction: "查看", Delete: "刪除", + Edit: "編輯", + }, + Commands: { + new: "新建聊天", + newm: "從面具新建聊天", + next: "下一個聊天", + prev: "上一個聊天", + clear: "清除上下文", + del: "刪除聊天", + }, + InputActions: { + Stop: "停止響應", + ToBottom: "滾到最新", + Theme: { + auto: "自動主題", + light: "亮色模式", + dark: "深色模式", + }, + Prompt: "快捷指令", + Masks: "所有面具", + Clear: "清除聊天", + Settings: "對話設定", + UploadImage: "上傳圖片", }, Rename: "重新命名對話", Typing: "正在輸入…", @@ -34,13 +80,37 @@ const tw: PartialLocaleType = { Reset: "重設", SaveAs: "另存新檔", }, + IsContext: "預設提示詞", }, Export: { Title: "將聊天記錄匯出為 Markdown", Copy: "複製全部", Download: "下載檔案", + Share: "分享到 ShareGPT", MessageFromYou: "來自您的訊息", MessageFromChatGPT: "來自 ChatGPT 的訊息", + Format: { + Title: "導出格式", + SubTitle: "可以導出 Markdown 文本或者 PNG 圖片", + }, + IncludeContext: { + Title: "包含面具上下文", + SubTitle: "是否在消息中展示面具上下文", + }, + Steps: { + Select: "選取", + Preview: "預覽", + }, + Image: { + Toast: "正在生成截圖", + Modal: "長按或右鍵保存圖片", + }, + }, + Select: { + Search: "搜索消息", + All: "選取全部", + Latest: "最近幾條", + Clear: "清除選中", }, Memory: { Title: "上下文記憶 Prompt", @@ -60,6 +130,20 @@ const tw: PartialLocaleType = { Title: "設定", SubTitle: "設定選項", + Danger: { + Reset: { + Title: "重置所有設定", + SubTitle: "重置所有設定項回默認值", + Action: "立即重置", + Confirm: "確認重置所有設定?", + }, + Clear: { + Title: "清除所有數據", + SubTitle: "清除所有聊天、設定數據", + Action: "立即清除", + Confirm: "確認清除所有聊天、設定數據?", + }, + }, Lang: { Name: "Language", // ATTENTION: if you wanna add a new translation, please do not translate this value, leave it as `Language` All: "所有語言", @@ -73,6 +157,11 @@ const tw: PartialLocaleType = { Title: "匯入系統提示", SubTitle: "強制在每個請求的訊息列表開頭新增一個模擬 ChatGPT 的系統提示", }, + InputTemplate: { + Title: "用戶輸入預處理", + SubTitle: "用戶最新的一條消息會填充到此模板", + }, + Update: { Version: (x: string) => `目前版本:${x}`, IsLatest: "已是最新版本", @@ -88,11 +177,62 @@ const tw: PartialLocaleType = { Title: "預覽氣泡", SubTitle: "在預覽氣泡中預覽 Markdown 內容", }, + AutoGenerateTitle: { + Title: "自動生成標題", + SubTitle: "根據對話內容生成合適的標題", + }, + Sync: { + CloudState: "雲端數據", + NotSyncYet: "還沒有進行過同步", + Success: "同步成功", + Fail: "同步失敗", + + Config: { + Modal: { + Title: "配置雲端同步", + Check: "檢查可用性", + }, + SyncType: { + Title: "同步類型", + SubTitle: "選擇喜愛的同步服務器", + }, + Proxy: { + Title: "啟用代理", + SubTitle: "在瀏覽器中同步時,必須啟用代理以避免跨域限制", + }, + ProxyUrl: { + Title: "代理地址", + SubTitle: "僅適用於本項目自帶的跨域代理", + }, + + WebDav: { + Endpoint: "WebDAV 地址", + UserName: "用戶名", + Password: "密碼", + }, + + UpStash: { + Endpoint: "UpStash Redis REST Url", + UserName: "備份名稱", + Password: "UpStash Redis REST Token", + }, + }, + + LocalState: "本地數據", + Overview: (overview: any) => { + return `${overview.chat} 次對話,${overview.message} 條消息,${overview.prompt} 條提示詞,${overview.mask} 個面具`; + }, + ImportFailed: "導入失敗", + }, Mask: { Splash: { Title: "面具啟動頁面", SubTitle: "新增聊天時,呈現面具啟動頁面", }, + Builtin: { + Title: "隱藏內置面具", + SubTitle: "在所有面具列表中隱藏內置面具", + }, }, Prompt: { Disable: { @@ -131,11 +271,81 @@ const tw: PartialLocaleType = { NoAccess: "輸入 API Key 檢視餘額", }, + Access: { + AccessCode: { + Title: "訪問密碼", + SubTitle: "管理員已開啟加密訪問", + Placeholder: "請輸入訪問密碼", + }, + CustomEndpoint: { + Title: "自定義接口 (Endpoint)", + SubTitle: "是否使用自定義 Azure 或 OpenAI 服務", + }, + Provider: { + Title: "模型服務商", + SubTitle: "切換不同的服務商", + }, + OpenAI: { + ApiKey: { + Title: "API Key", + SubTitle: "使用自定義 OpenAI Key 繞過密碼訪問限制", + Placeholder: "OpenAI API Key", + }, + + Endpoint: { + Title: "接口(Endpoint) 地址", + SubTitle: "除默認地址外,必須包含 http(s)://", + }, + }, + Azure: { + ApiKey: { + Title: "接口密鑰", + SubTitle: "使用自定義 Azure Key 繞過密碼訪問限制", + Placeholder: "Azure API Key", + }, + + Endpoint: { + Title: "接口(Endpoint) 地址", + SubTitle: "樣例:", + }, + + ApiVerion: { + Title: "接口版本 (azure api version)", + SubTitle: "選擇指定的部分版本", + }, + }, + Google: { + ApiKey: { + Title: "API 密鑰", + SubTitle: "從 Google AI 獲取您的 API 密鑰", + Placeholder: "輸入您的 Google AI Studio API 密鑰", + }, + + Endpoint: { + Title: "終端地址", + SubTitle: "示例:", + }, + + ApiVersion: { + Title: "API 版本(僅適用於 gemini-pro)", + SubTitle: "選擇一個特定的 API 版本", + }, + }, + CustomModel: { + Title: "自定義模型名", + SubTitle: "增加自定義模型可選項,使用英文逗號隔開", + }, + }, + Model: "模型 (model)", Temperature: { Title: "隨機性 (temperature)", SubTitle: "值越大,回應越隨機", }, + TopP: { + Title: "核采樣 (top_p)", + SubTitle: "與隨機性類似,但不要和隨機性一起更改", + }, MaxTokens: { Title: "單次回應限制 (max_tokens)", SubTitle: "單次互動所用的最大 Token 數", @@ -166,10 +376,16 @@ const tw: PartialLocaleType = { Success: "已複製到剪貼簿中", Failed: "複製失敗,請賦予剪貼簿權限", }, + Download: { + Success: "內容已下載到您的目錄。", + Failed: "下載失敗。", + }, Context: { Toast: (x: any) => `已設定 ${x} 條前置上下文`, Edit: "前置上下文和歷史記憶", Add: "新增一條", + Clear: "上下文已清除", + Revert: "恢覆上下文", }, Plugin: { Name: "外掛" }, FineTuned: { Sysmessage: "你是一個助手" }, @@ -198,16 +414,34 @@ const tw: PartialLocaleType = { Config: { Avatar: "角色頭像", Name: "角色名稱", + Sync: { + Title: "使用全局設定", + SubTitle: "當前對話是否使用全局模型設定", + Confirm: "當前對話的自定義設定將會被自動覆蓋,確認啟用全局設定?", + }, + HideContext: { + Title: "隱藏預設對話", + SubTitle: "隱藏後預設對話不會出現在聊天界面", + }, + Share: { + Title: "分享此面具", + SubTitle: "生成此面具的直達鏈接", + Action: "覆制鏈接", + }, }, }, NewChat: { Return: "返回", Skip: "跳過", + NotShow: "不再呈現", + ConfirmNoShow: "確認停用?停用後可以隨時在設定中重新啟用。", Title: "挑選一個面具", SubTitle: "現在開始,與面具背後的靈魂思維碰撞", More: "搜尋更多", - NotShow: "不再呈現", - ConfirmNoShow: "確認停用?停用後可以隨時在設定中重新啟用。", + }, + URLCommand: { + Code: "檢測到鏈接中已經包含訪問碼,是否自動填入?", + Settings: "檢測到鏈接中包含了預制設置,是否自動填入?", }, UI: { Confirm: "確認", @@ -215,8 +449,15 @@ const tw: PartialLocaleType = { Close: "關閉", Create: "新增", Edit: "編輯", + Export: "導出", + Import: "導入", + Sync: "同步", + Config: "配置", }, Exporter: { + Description: { + Title: "只有清除上下文之後的消息會被展示", + }, Model: "模型", Messages: "訊息", Topic: "主題", @@ -224,4 +465,14 @@ const tw: PartialLocaleType = { }, }; +type DeepPartial = T extends object + ? { + [P in keyof T]?: DeepPartial; + } + : T; + +export type LocaleType = typeof tw; +export type PartialLocaleType = DeepPartial; + export default tw; +// Translated by @chunkiuuu, feel free the submit new pr if there are typo/incorrect translations :D \ No newline at end of file From 069766d5818dafad32cda7d07eefafd95b126a3a Mon Sep 17 00:00:00 2001 From: Algorithm5838 <108630393+Algorithm5838@users.noreply.github.com> Date: Tue, 27 Feb 2024 05:28:54 +0300 Subject: [PATCH 5/8] Correct cutoff dates (#4118) --- app/constant.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/constant.ts b/app/constant.ts index 74b030c55..c1f91d31c 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -108,9 +108,9 @@ export const GEMINI_SUMMARIZE_MODEL = "gemini-pro"; export const KnowledgeCutOffDate: Record = { default: "2021-09", - "gpt-4-turbo-preview": "2023-04", + "gpt-4-turbo-preview": "2023-12", "gpt-4-1106-preview": "2023-04", - "gpt-4-0125-preview": "2023-04", + "gpt-4-0125-preview": "2023-12", "gpt-4-vision-preview": "2023-04", // After improvements, // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously. From 410a22dc634816b13848977d037506fbe2ad4957 Mon Sep 17 00:00:00 2001 From: Fred Date: Tue, 27 Feb 2024 11:43:40 +0800 Subject: [PATCH 6/8] feat: auto detach scrolling --- app/components/chat.tsx | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 369d84c33..ba1e94b9c 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -6,6 +6,7 @@ import React, { useMemo, useCallback, Fragment, + RefObject, } from "react"; import SendWhiteIcon from "../icons/send-white.svg"; @@ -382,11 +383,13 @@ function ChatAction(props: { ); } -function useScrollToBottom() { +function useScrollToBottom( + scrollRef: RefObject, + detach: boolean = false, +) { // for auto-scroll - const scrollRef = useRef(null); - const [autoScroll, setAutoScroll] = useState(true); + const [autoScroll, setAutoScroll] = useState(true); function scrollDomToBottom() { const dom = scrollRef.current; if (dom) { @@ -399,7 +402,7 @@ function useScrollToBottom() { // auto scroll useEffect(() => { - if (autoScroll) { + if (autoScroll && !detach) { scrollDomToBottom(); } }); @@ -658,7 +661,17 @@ function _Chat() { const [userInput, setUserInput] = useState(""); const [isLoading, setIsLoading] = useState(false); const { submitKey, shouldSubmit } = useSubmitHandler(); - const { scrollRef, setAutoScroll, scrollDomToBottom } = useScrollToBottom(); + const scrollRef = useRef(null); + const isScrolledToBottom = scrollRef?.current + ? Math.abs( + scrollRef.current.scrollHeight - + (scrollRef.current.scrollTop + scrollRef.current.clientHeight), + ) <= 1 + : false; + const { setAutoScroll, scrollDomToBottom } = useScrollToBottom( + scrollRef, + isScrolledToBottom, + ); const [hitBottom, setHitBottom] = useState(true); const isMobileScreen = useMobileScreen(); const navigate = useNavigate(); @@ -1003,7 +1016,6 @@ function _Chat() { setHitBottom(isHitBottom); setAutoScroll(isHitBottom); }; - function scrollToBottom() { setMsgRenderIndex(renderMessages.length - CHAT_PAGE_SIZE); scrollDomToBottom(); @@ -1151,6 +1163,13 @@ function _Chat() { )}
+

+ {JSON.stringify({ + scrollHeight: scrollRef?.current?.scrollHeight, + scrollTop: scrollRef?.current?.scrollTop, + clientHeight: scrollRef?.current?.clientHeight, + })} +

setIsEditingMessage(true)} From e3b3ae97bc3edb660104ca8f414ecf021837e3a5 Mon Sep 17 00:00:00 2001 From: Fred Date: Tue, 27 Feb 2024 11:49:44 +0800 Subject: [PATCH 7/8] chore: clear scroll info --- app/components/chat.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index ba1e94b9c..9144f9a5f 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -1163,13 +1163,6 @@ function _Chat() { )}
-

- {JSON.stringify({ - scrollHeight: scrollRef?.current?.scrollHeight, - scrollTop: scrollRef?.current?.scrollTop, - clientHeight: scrollRef?.current?.clientHeight, - })} -

setIsEditingMessage(true)} From 08fa22749aea8f497811f684bd9c7ef68d698666 Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:28:01 +0800 Subject: [PATCH 8/8] fix: add max_tokens when using vision model (#4157) --- app/client/platforms/openai.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 919716bfb..437aff582 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -110,6 +110,16 @@ export class ChatGPTApi implements LLMApi { // Please do not ask me why not send max_tokens, no reason, this param is just shit, I dont want to explain anymore. }; + // add max_tokens to vision model + if (visionModel) { + Object.defineProperty(requestPayload, "max_tokens", { + enumerable: true, + configurable: true, + writable: true, + value: Math.max(modelConfig.max_tokens, 4096), + }); + } + console.log("[Request] openai payload: ", requestPayload); const shouldStream = !!options.config.stream;