From 82c025a34a9bec5186e0bff6c3691522efc85f32 Mon Sep 17 00:00:00 2001 From: Yorun <547747006@qq.com> Date: Mon, 3 Apr 2023 06:03:36 +0000 Subject: [PATCH 1/5] ci(sync): add push permission --- .github/workflows/sync.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 9c7b7e6f..38c272e8 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -1,5 +1,8 @@ name: Upstream Sync +permissions: + contents: write + on: schedule: - cron: "0 */6 * * *" # every 6 hours @@ -12,7 +15,7 @@ jobs: if: ${{ github.event.repository.fork }} steps: - # Step 1: run a standard checkout action, provided by github + # Step 1: run a standard checkout action - name: Checkout target repo uses: actions/checkout@v3 From 73f4ea38c6c899f3ef1ce7169523f4b28a45c646 Mon Sep 17 00:00:00 2001 From: cyhhao Date: Mon, 3 Apr 2023 14:13:57 +0800 Subject: [PATCH 2/5] session message should exclude all error tips --- app/components/chat.tsx | 5 ++++- app/requests.ts | 7 +++---- app/store/app.ts | 16 ++++++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 3864a329..70afa319 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -513,7 +513,10 @@ export function Chat(props: { bordered title={Locale.Chat.Actions.Export} onClick={() => { - exportMessages(session.messages, session.topic); + exportMessages( + session.messages.filter((msg) => !msg.isError), + session.topic, + ); }} /> diff --git a/app/requests.ts b/app/requests.ts index 281f8ff1..ee3103b7 100644 --- a/app/requests.ts +++ b/app/requests.ts @@ -114,7 +114,7 @@ export async function requestChatStream( filterBot?: boolean; modelConfig?: ModelConfig; onMessage: (message: string, done: boolean) => void; - onError: (error: Error) => void; + onError: (error: Error, statusCode?: number) => void; onController?: (controller: AbortController) => void; }, ) { @@ -178,11 +178,10 @@ export async function requestChatStream( finish(); } else if (res.status === 401) { console.error("Anauthorized"); - responseText = Locale.Error.Unauthorized; - finish(); + options?.onError(new Error("Anauthorized"), res.status); } else { console.error("Stream Error", res.body); - options?.onError(new Error("Stream Error")); + options?.onError(new Error("Stream Error"), res.status); } } catch (err) { console.error("NetWork Error", err); diff --git a/app/store/app.ts b/app/store/app.ts index 3e98757c..f83c1e08 100644 --- a/app/store/app.ts +++ b/app/store/app.ts @@ -14,6 +14,7 @@ import Locale from "../locales"; export type Message = ChatCompletionResponseMessage & { date: string; streaming?: boolean; + isError?: boolean; }; export enum SubmitKey { @@ -351,9 +352,15 @@ export const useChatStore = create()( set(() => ({})); } }, - onError(error) { - botMessage.content += "\n\n" + Locale.Store.Error; + onError(error, statusCode) { + if (statusCode === 401) { + botMessage.content = Locale.Error.Unauthorized; + } else { + botMessage.content += "\n\n" + Locale.Store.Error; + } botMessage.streaming = false; + userMessage.isError = true; + botMessage.isError = true; set(() => ({})); ControllerPool.remove(sessionIndex, messageIndex); }, @@ -383,7 +390,8 @@ export const useChatStore = create()( getMessagesWithMemory() { const session = get().currentSession(); const config = get().config; - const n = session.messages.length; + const messages = session.messages.filter((msg) => !msg.isError); + const n = messages.length; const context = session.context.slice(); @@ -393,7 +401,7 @@ export const useChatStore = create()( } const recentMessages = context.concat( - session.messages.slice(Math.max(0, n - config.historyMessageCount)), + messages.slice(Math.max(0, n - config.historyMessageCount)), ); return recentMessages; From a6890c0f58c5f9895fdcfa74763f5f205071e43e Mon Sep 17 00:00:00 2001 From: cyhhao Date: Mon, 3 Apr 2023 14:56:13 +0800 Subject: [PATCH 3/5] optimize: scrolling experience --- app/components/chat.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 70afa319..34cef0b6 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -377,7 +377,8 @@ export function Chat(props: { chatStore.onUserInput(userInput).then(() => setIsLoading(false)); setUserInput(""); setPromptHints([]); - inputRef.current?.focus(); + if (!isMobileScreen()) inputRef.current?.focus(); + setAutoScroll(true); }; // stop response @@ -533,8 +534,11 @@ export function Chat(props: { className={styles["chat-body"]} ref={scrollRef} onScroll={(e) => onChatBodyScroll(e.currentTarget)} - onMouseOver={() => inputRef.current?.blur()} - onTouchStart={() => inputRef.current?.blur()} + onWheel={() => setAutoScroll(false)} + onTouchStart={() => { + inputRef.current?.blur(); + setAutoScroll(false); + }} > {messages.map((message, i) => { const isUser = message.role === "user"; From 8db26bbd5ff843ee183f1493a23fdeb66c743a0d Mon Sep 17 00:00:00 2001 From: cyhhao Date: Mon, 3 Apr 2023 15:20:16 +0800 Subject: [PATCH 4/5] rm msg body mouseover --- app/components/chat.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 1499e816..4cc60fa5 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -593,7 +593,6 @@ export function Chat(props: { if (!isMobileScreen()) return; setUserInput(message.content); }} - onMouseOver={() => inputRef.current?.blur()} > From ae8ceb8dca5fad06b3fb27dc8132526981ad3ecf Mon Sep 17 00:00:00 2001 From: cyhhao Date: Mon, 3 Apr 2023 15:21:03 +0800 Subject: [PATCH 5/5] rm input mouseover --- app/components/chat.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index 4cc60fa5..2bd80aa8 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -627,9 +627,6 @@ export function Chat(props: { setAutoScroll(false); setTimeout(() => setPromptHints([]), 500); }} - onMouseOver={() => { - inputRef.current?.focus(); - }} autoFocus={!props?.sideBarShowing} />