From 1afca0b28acb0f4e9ea60809355be8897c779e11 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Sun, 2 Apr 2023 18:41:25 +0000 Subject: [PATCH 01/14] fix: mobile scroll problem --- app/components/chat.tsx | 1 + app/components/home.module.scss | 1 + app/styles/globals.scss | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index b35cd3ebe..b152e8ae0 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -548,6 +548,7 @@ export function Chat(props: {
inputRef.current?.blur()} + onTouchStart={() => inputRef.current?.blur()} > {!isUser && !(message.preview || message.content.length === 0) && ( diff --git a/app/components/home.module.scss b/app/components/home.module.scss index 95964ae11..64ac2363f 100644 --- a/app/components/home.module.scss +++ b/app/components/home.module.scss @@ -333,6 +333,7 @@ .chat-input-panel { width: 100%; padding: 20px; + padding-top: 5px; box-sizing: border-box; flex-direction: column; } diff --git a/app/styles/globals.scss b/app/styles/globals.scss index e179dcf37..81811819b 100644 --- a/app/styles/globals.scss +++ b/app/styles/globals.scss @@ -188,7 +188,7 @@ input[type="text"] { appearance: none; border-radius: 10px; border: var(--border-in-light); - height: 36px; + min-height: 36px; box-sizing: border-box; background: var(--white); color: var(--black); From e8d71c815eb6056265b61235489352fda70ec319 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Sun, 2 Apr 2023 18:51:37 +0000 Subject: [PATCH 02/14] chore: fix preview bubble --- app/components/chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index b152e8ae0..4fb7200f2 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -451,7 +451,7 @@ export function Chat(props: { role: "user", content: userInput, date: new Date().toLocaleString(), - preview: false, + preview: true, }, ] : [], From 8d60a414f05da1a4d81eb8863de76b2fae64519f Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Sun, 2 Apr 2023 18:55:08 +0000 Subject: [PATCH 03/14] chore: fix usage display --- app/requests.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/requests.ts b/app/requests.ts index cf2ac7f7e..91c766597 100644 --- a/app/requests.ts +++ b/app/requests.ts @@ -88,7 +88,11 @@ export async function requestUsage() { const response = (await res.json()) as { total_usage: number; }; - return Math.round(response.total_usage) / 100; + + if (response.total_usage) { + response.total_usage = Math.round(response.total_usage) / 100; + } + return response.total_usage; } catch (error) { console.error("[Request usage] ", error, res.body); } From b44caeeefb9f90baa69fac1d76201447f7930e98 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Sun, 2 Apr 2023 19:14:53 +0000 Subject: [PATCH 04/14] fix: #289 #367 #353 #369 provide more error message info --- app/api/chat-stream/route.ts | 9 +++++++++ app/components/chat.tsx | 8 +++----- app/components/markdown.tsx | 2 +- app/components/ui-lib.module.scss | 2 ++ app/requests.ts | 10 ++++++++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/api/chat-stream/route.ts b/app/api/chat-stream/route.ts index e7bdfc5fb..f33175543 100644 --- a/app/api/chat-stream/route.ts +++ b/app/api/chat-stream/route.ts @@ -8,6 +8,15 @@ async function createStream(req: NextRequest) { const res = await requestOpenai(req); + const contentType = res.headers.get("Content-Type") ?? ""; + if (!contentType.includes("stream")) { + const content = await ( + await res.text() + ).replace(/provided:.*. You/, "provided: ***. You"); + console.log("[Stream] error ", content); + return "```json\n" + content + "```"; + } + const stream = new ReadableStream({ async start(controller) { function onParse(event: any) { diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 4fb7200f2..37a597c92 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -525,6 +525,8 @@ export function Chat(props: { className={styles["chat-body"]} ref={scrollRef} onScroll={(e) => onChatBodyScroll(e.currentTarget)} + onMouseOver={() => inputRef.current?.blur()} + onTouchStart={() => inputRef.current?.blur()} > {messages.map((message, i) => { const isUser = message.role === "user"; @@ -545,11 +547,7 @@ export function Chat(props: { {Locale.Chat.Typing}
)} -
inputRef.current?.blur()} - onTouchStart={() => inputRef.current?.blur()} - > +
{!isUser && !(message.preview || message.content.length === 0) && (
diff --git a/app/components/markdown.tsx b/app/components/markdown.tsx index 894926129..88e0f66f7 100644 --- a/app/components/markdown.tsx +++ b/app/components/markdown.tsx @@ -59,7 +59,7 @@ export function Markdown(props: { content: string }) { [ RehypeHighlight, { - detect: true, + detect: false, ignoreMissing: true, }, ], diff --git a/app/components/ui-lib.module.scss b/app/components/ui-lib.module.scss index 4aa836629..c3ebcc02c 100644 --- a/app/components/ui-lib.module.scss +++ b/app/components/ui-lib.module.scss @@ -128,6 +128,8 @@ justify-content: center; .toast-content { + max-width: 80vw; + word-break: break-all; font-size: 14px; background-color: var(--white); box-shadow: var(--card-shadow); diff --git a/app/requests.ts b/app/requests.ts index 91c766597..281f8ff1b 100644 --- a/app/requests.ts +++ b/app/requests.ts @@ -1,6 +1,7 @@ import type { ChatRequest, ChatReponse } from "./api/openai/typing"; import { filterConfig, Message, ModelConfig, useAccessStore } from "./store"; import Locale from "./locales"; +import { showToast } from "./components/ui-lib"; const TIME_OUT_MS = 30000; @@ -87,8 +88,17 @@ export async function requestUsage() { try { const response = (await res.json()) as { total_usage: number; + error?: { + type: string; + message: string; + }; }; + if (response.error && response.error.type) { + showToast(response.error.message); + return; + } + if (response.total_usage) { response.total_usage = Math.round(response.total_usage) / 100; } From 8d34b0f454b543be9681f744d33c43c156ecf135 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Sun, 2 Apr 2023 19:20:57 +0000 Subject: [PATCH 05/14] chore: fix mobile scroll --- app/components/chat.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 37a597c92..f1ea597dc 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -286,6 +286,7 @@ function useScrollToBottom() { const dom = scrollRef.current; if (dom && autoScroll) { setTimeout(() => (dom.scrollTop = dom.scrollHeight), 1); + setAutoScroll(false); } }); From e2c1475857843c65d803b67292a8f14adffe49d8 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Sun, 2 Apr 2023 19:24:29 +0000 Subject: [PATCH 06/14] revert: fix mobile scroll --- app/components/chat.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index f1ea597dc..3864a3292 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -286,7 +286,6 @@ function useScrollToBottom() { const dom = scrollRef.current; if (dom && autoScroll) { setTimeout(() => (dom.scrollTop = dom.scrollHeight), 1); - setAutoScroll(false); } }); @@ -460,6 +459,11 @@ export function Chat(props: { const [showPromptModal, setShowPromptModal] = useState(false); + // Auto focus + useEffect(() => { + inputRef.current?.focus(); + }, []); + return (
From 58433030768c351826cf31a7c8347671696fe46b Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 3 Apr 2023 03:26:30 +0800 Subject: [PATCH 07/14] Update README.md --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index 23c3d0b84..2e89b18a9 100644 --- a/README.md +++ b/README.md @@ -182,13 +182,6 @@ docker run -d -p 3000:3000 -e OPENAI_API_KEY="" -e CODE="" yidadaa/chatgpt-next- ![更多展示 More](./static/more.png) -## 捐赠 Donate USDT - -> BNB Smart Chain (BEP 20) - -``` -0x67cD02c7EB62641De576a1fA3EdB32eA0c3ffD89 -``` ## 鸣谢 Special Thanks From 8a1c2f89bea815ea6e88fcd784ba72d9730e687c Mon Sep 17 00:00:00 2001 From: Yorun <547747006@qq.com> Date: Mon, 3 Apr 2023 02:10:48 +0000 Subject: [PATCH 08/14] ci(sync): shorten the timer interval --- .github/workflows/sync.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 1c9dc413c..74016d0fb 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -2,8 +2,8 @@ name: Upstream Sync on: schedule: - - cron: '0 */12 * * *' # every 12 hours - workflow_dispatch: # on button click + - cron: "0 */6 * * *" # every 6 hours + workflow_dispatch: jobs: sync_latest_from_upstream: @@ -11,19 +11,19 @@ jobs: runs-on: ubuntu-latest steps: - # Step 1: run a standard checkout action, provided by github - - name: Checkout target repo - uses: actions/checkout@v3 + # Step 1: run a standard checkout action, provided by github + - name: Checkout target repo + uses: actions/checkout@v3 - # Step 2: run the sync action - - name: Sync upstream changes - id: sync - uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 - with: - upstream_sync_repo: Yidadaa/ChatGPT-Next-Web - upstream_sync_branch: main - target_sync_branch: main - target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set - - # Set test_mode true to run tests instead of the true action!! - test_mode: false + # Step 2: run the sync action + - name: Sync upstream changes + id: sync + uses: aormsby/Fork-Sync-With-Upstream-action@v3.4 + with: + upstream_sync_repo: Yidadaa/ChatGPT-Next-Web + upstream_sync_branch: main + target_sync_branch: main + target_repo_token: ${{ secrets.GITHUB_TOKEN }} # automatically generated, no need to set + + # Set test_mode true to run tests instead of the true action!! + test_mode: false From 62f86751997cfc198e4bbbb519743dca0a5e7737 Mon Sep 17 00:00:00 2001 From: Yorun <547747006@qq.com> Date: Mon, 3 Apr 2023 02:11:40 +0000 Subject: [PATCH 09/14] ci(sync): skip main repo execution --- .github/workflows/sync.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 74016d0fb..9c7b7e6f1 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -9,6 +9,7 @@ jobs: sync_latest_from_upstream: name: Sync latest commits from upstream repo runs-on: ubuntu-latest + if: ${{ github.event.repository.fork }} steps: # Step 1: run a standard checkout action, provided by github From 0d3bd4278002876c920ed132ac712b34e17315ef Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 3 Apr 2023 10:50:29 +0800 Subject: [PATCH 10/14] Update app.ts --- app/store/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/store/app.ts b/app/store/app.ts index 3e98757cb..29da33792 100644 --- a/app/store/app.ts +++ b/app/store/app.ts @@ -102,7 +102,7 @@ export function filterConfig(oldConfig: ModelConfig): Partial { return isValidModel(x as string); }, max_tokens(x) { - return isValidNumber(x as number, 100, 4000); + return isValidNumber(x as number, 100, 32000); }, presence_penalty(x) { return isValidNumber(x as number, -2, 2); From 73865651a0095885713b61ae36e8e900158b332c Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 3 Apr 2023 03:16:56 +0000 Subject: [PATCH 11/14] fix: #366 use fallback copy --- app/utils.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/utils.ts b/app/utils.ts index 1fb3d3166..5fe277c63 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -5,15 +5,19 @@ export function trimTopic(topic: string) { return topic.replace(/[,。!?、,.!?]*$/, ""); } -export function copyToClipboard(text: string) { - navigator.clipboard - .writeText(text) - .then((res) => { - showToast(Locale.Copy.Success); - }) - .catch((err) => { - showToast(Locale.Copy.Failed); - }); +export async function copyToClipboard(text: string) { + try { + await navigator.clipboard.writeText(text); + } catch (error) { + const textarea = document.createElement("textarea"); + textarea.value = text; + document.body.appendChild(textarea); + textarea.select(); + document.execCommand("copy"); + document.body.removeChild(textarea); + } finally { + showToast(Locale.Copy.Success); + } } export function downloadAs(text: string, filename: string) { From 0e784c50ad11079d7af5537c0e9cc28bf84c7ac9 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 3 Apr 2023 03:27:36 +0000 Subject: [PATCH 12/14] fix: #384 improve scroll --- app/components/chat.tsx | 8 ++++++-- app/styles/highlight.scss | 15 ++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 3864a3292..f13ba6e70 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -461,8 +461,9 @@ export function Chat(props: { // Auto focus useEffect(() => { + if (props.sideBarShowing) return; inputRef.current?.focus(); - }, []); + }, [props.sideBarShowing]); return (
@@ -530,7 +531,6 @@ export function Chat(props: { className={styles["chat-body"]} ref={scrollRef} onScroll={(e) => onChatBodyScroll(e.currentTarget)} - onMouseOver={() => inputRef.current?.blur()} onTouchStart={() => inputRef.current?.blur()} > {messages.map((message, i) => { @@ -592,6 +592,7 @@ export function Chat(props: { if (!isMobileScreen()) return; setUserInput(message.content); }} + onMouseOver={() => inputRef.current?.blur()} >
@@ -626,6 +627,9 @@ export function Chat(props: { setAutoScroll(false); setTimeout(() => setPromptHints([]), 500); }} + onMouseOver={() => { + inputRef.current?.focus(); + }} autoFocus={!props?.sideBarShowing} /> Date: Mon, 3 Apr 2023 03:35:24 +0000 Subject: [PATCH 13/14] fix: improve scroll --- app/components/chat.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index f13ba6e70..8b687c7eb 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -461,9 +461,9 @@ export function Chat(props: { // Auto focus useEffect(() => { - if (props.sideBarShowing) return; + if (props.sideBarShowing && isMobileScreen()) return; inputRef.current?.focus(); - }, [props.sideBarShowing]); + }, []); return (
From 6e6d2a3310604dcb3e6aa1ba78ea05b02ac60c57 Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Mon, 3 Apr 2023 11:43:38 +0800 Subject: [PATCH 14/14] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 2e89b18a9..815aba1af 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,6 @@ docker run -d -p 3000:3000 -e OPENAI_API_KEY="" -e CODE="" yidadaa/chatgpt-next- ## 鸣谢 Special Thanks - ### 捐赠者 Sponsor [@mushan0x0](https://github.com/mushan0x0)