From 73216513dd9a0000430658122e5d589d81b658fb Mon Sep 17 00:00:00 2001 From: jtung4 Date: Fri, 14 Apr 2023 19:49:48 +0800 Subject: [PATCH 1/5] Update tw.ts --- app/locales/tw.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/locales/tw.ts b/app/locales/tw.ts index 77975b896..b239ed65d 100644 --- a/app/locales/tw.ts +++ b/app/locales/tw.ts @@ -152,9 +152,9 @@ const tw: LocaleType = { Prompt: { History: (content: string) => "這是 AI 與用戶的歷史聊天總結,作為前情提要:" + content, - Topic: "直接返回這句話的簡要主題,無須解釋,若無主題,請直接返回「閒聊」", + 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.", Summarize: - "簡要總結一下你和用戶的對話,作為後續的上下文提示 prompt,且字數控制在 200 字以內", + "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.", }, ConfirmClearAll: "確認清除所有對話、設定數據?", }, From fb14785cadf2055818bd4ff9c6064b59e53c2700 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sat, 15 Apr 2023 02:28:30 +0800 Subject: [PATCH 2/5] fix: #804 disable auto scroll in textarea --- app/components/chat.tsx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index b9ae13926..b0deb5a51 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -442,16 +442,6 @@ export function Chat(props: { inputRef.current?.focus(); }; - const scrollInput = () => { - const dom = inputRef.current; - if (!dom) return; - const paddingBottomNum: number = parseInt( - window.getComputedStyle(dom).paddingBottom, - 10, - ); - dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum; - }; - // auto grow input const [inputRows, setInputRows] = useState(2); const measure = useDebouncedCallback( @@ -476,7 +466,6 @@ export function Chat(props: { // only search prompts when user input is short const SEARCH_TEXT_LIMIT = 30; const onInput = (text: string) => { - scrollInput(); setUserInput(text); const n = text.trim().length; From 47a2911ee2cd229feb14967a10d02148d2ae2913 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sat, 15 Apr 2023 02:37:24 +0800 Subject: [PATCH 3/5] feat: edit session title button --- app/components/chat.tsx | 24 +++++++++++------------- app/icons/rename.svg | 1 + 2 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 app/icons/rename.svg diff --git a/app/components/chat.tsx b/app/components/chat.tsx index b0deb5a51..f7b67b293 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -3,6 +3,7 @@ import { memo, useState, useRef, useEffect, useLayoutEffect } from "react"; import SendWhiteIcon from "../icons/send-white.svg"; import BrainIcon from "../icons/brain.svg"; +import RenameIcon from "../icons/rename.svg"; import ExportIcon from "../icons/share.svg"; import ReturnIcon from "../icons/return.svg"; import CopyIcon from "../icons/copy.svg"; @@ -589,6 +590,13 @@ export function Chat(props: { const [showPromptModal, setShowPromptModal] = useState(false); + const renameSession = () => { + const newTopic = prompt(Locale.Chat.Rename, session.topic); + if (newTopic && newTopic !== session.topic) { + chatStore.updateCurrentSession((session) => (session.topic = newTopic!)); + } + }; + // Auto focus useEffect(() => { if (props.sideBarShowing && isMobileScreen()) return; @@ -602,14 +610,7 @@ export function Chat(props: {
{ - const newTopic = prompt(Locale.Chat.Rename, session.topic); - if (newTopic && newTopic !== session.topic) { - chatStore.updateCurrentSession( - (session) => (session.topic = newTopic!), - ); - } - }} + onClickCapture={renameSession} > {session.topic}
@@ -628,12 +629,9 @@ export function Chat(props: {
} + icon={} bordered - title={Locale.Chat.Actions.CompressedHistory} - onClick={() => { - setShowPromptModal(true); - }} + onClick={renameSession} />
diff --git a/app/icons/rename.svg b/app/icons/rename.svg new file mode 100644 index 000000000..cee69eb8d --- /dev/null +++ b/app/icons/rename.svg @@ -0,0 +1 @@ + From 0a79df3670e9aed5b62d1331012cbffdce74255a Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sat, 15 Apr 2023 02:50:04 +0800 Subject: [PATCH 4/5] refactor: remove protocol env vars --- README.md | 13 ++++--------- README_CN.md | 12 ++++-------- app/api/common.ts | 11 +++++++++-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 8a09a0657..42642ec98 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,7 @@ We recommend that you follow the steps below to re-deploy: - Choose and deploy in Vercel again, [please see the detailed tutorial](./docs/vercel-cn.md). ### Enable Automatic Updates + After forking the project, due to the limitations imposed by Github, you need to manually enable Workflows and Upstream Sync Action on the Actions page of the forked project. Once enabled, automatic updates will be scheduled every hour: ![Automatic Updates](./docs/images/enable-actions.jpg) @@ -104,6 +105,7 @@ After forking the project, due to the limitations imposed by Github, you need to ![Enable Automatic Updates](./docs/images/enable-actions-sync.jpg) ### Manually Updating Code + If you want to update instantly, you can check out the [Github documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) to learn how to synchronize a forked project with upstream code. You can star or watch this project or follow author to get release notifictions in time. @@ -134,18 +136,11 @@ Access passsword, separated by comma. ### `BASE_URL` (optional) -> Default: `api.openai.com` +> Default: `https://api.openai.com` +> Examples: `http://your-openai-proxy.com` Override openai api request base url. -### `PROTOCOL` (optional) - -> Default: `https` - -> Values: `http` | `https` - -Override openai api request protocol. - ## Development > [简体中文 > 如何进行二次开发](./README_CN.md#开发) diff --git a/README_CN.md b/README_CN.md index 7d1a835c4..9c80d865f 100644 --- a/README_CN.md +++ b/README_CN.md @@ -43,6 +43,7 @@ - 在 Vercel 重新选择并部署,[请查看详细教程](./docs/vercel-cn.md#如何新建项目)。 ### 打开自动更新 + 当你 fork 项目之后,由于 Github 的限制,需要手动去你 fork 后的项目的 Actions 页面启用 Workflows,并启用 Upstream Sync Action,启用之后即可开启每小时定时自动更新: ![自动更新](./docs/images/enable-actions.jpg) @@ -85,17 +86,12 @@ OpanAI 密钥,你在 openai 账户页面申请的 api key。 ### `BASE_URL` (可选) -> Default: `api.openai.com` +> Default: `https://api.openai.com` +> Examples: `http://your-openai-proxy.com` OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填写此选项。 -### `PROTOCOL` (可选) - -> Default: `https` - -> Values: `http` | `https` - -OpenAI 代理接口协议,如果遇到 ssl 证书问题,请尝试通过此选项设置为 http。 +> 如果遇到 ssl 证书问题,请将 `BASE_URL` 的协议设置为 http。 ## 开发 diff --git a/app/api/common.ts b/app/api/common.ts index 842eeacaf..53ab18ed6 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -9,9 +9,16 @@ export async function requestOpenai(req: NextRequest) { const apiKey = req.headers.get("token"); const openaiPath = req.headers.get("path"); - console.log("[Proxy] ", openaiPath); + let baseUrl = BASE_URL; - return fetch(`${PROTOCOL}://${BASE_URL}/${openaiPath}`, { + if (!baseUrl.startsWith("http")) { + baseUrl = `${PROTOCOL}://${baseUrl}`; + } + + console.log("[Proxy] ", openaiPath); + console.log("[Base Url]", baseUrl); + + return fetch(`${baseUrl}/${openaiPath}`, { headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, From ad274b7cadea0c66a6bce2a8a188dc87e98371fe Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sat, 15 Apr 2023 02:51:15 +0800 Subject: [PATCH 5/5] fixup --- README.md | 1 + README_CN.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 42642ec98..a6288798a 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,7 @@ Access passsword, separated by comma. ### `BASE_URL` (optional) > Default: `https://api.openai.com` + > Examples: `http://your-openai-proxy.com` Override openai api request base url. diff --git a/README_CN.md b/README_CN.md index 9c80d865f..d2d64aa00 100644 --- a/README_CN.md +++ b/README_CN.md @@ -87,6 +87,7 @@ OpanAI 密钥,你在 openai 账户页面申请的 api key。 ### `BASE_URL` (可选) > Default: `https://api.openai.com` + > Examples: `http://your-openai-proxy.com` OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填写此选项。