From 7372b37fe6f00d4d54a3082935118fe72887c8d3 Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Sat, 18 Mar 2023 00:29:34 +0800 Subject: [PATCH 01/10] style: hide footer in mobile mode style: avoid ui overflow in mobile mode --- client/src/components/Main/Footer.jsx | 2 +- client/src/components/Main/Landing.jsx | 2 +- client/src/components/Main/TextChat.jsx | 4 ++-- client/src/components/Messages/index.jsx | 2 +- client/src/components/Nav/MobileNav.jsx | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/components/Main/Footer.jsx b/client/src/components/Main/Footer.jsx index 21e6fff89a..0015596749 100644 --- a/client/src/components/Main/Footer.jsx +++ b/client/src/components/Main/Footer.jsx @@ -2,7 +2,7 @@ import React from 'react'; export default function Footer() { return ( -
+
+

ChatGPT Clone diff --git a/client/src/components/Main/TextChat.jsx b/client/src/components/Main/TextChat.jsx index 8d7db4e71a..cf5d83132f 100644 --- a/client/src/components/Main/TextChat.jsx +++ b/client/src/components/Main/TextChat.jsx @@ -314,8 +314,8 @@ export default function TextChat({ messages }) { }; return ( -
-
+
+
{isSubmitting ? ( diff --git a/client/src/components/Messages/index.jsx b/client/src/components/Messages/index.jsx index 28b2fbfeda..114096b2fe 100644 --- a/client/src/components/Messages/index.jsx +++ b/client/src/components/Messages/index.jsx @@ -63,7 +63,7 @@ export default function Messages({ messages, messageTree }) { return (
diff --git a/client/src/components/Nav/MobileNav.jsx b/client/src/components/Nav/MobileNav.jsx index 0c846524fc..558c88f1a4 100644 --- a/client/src/components/Nav/MobileNav.jsx +++ b/client/src/components/Nav/MobileNav.jsx @@ -23,7 +23,7 @@ export default function MobileNav({ setNavVisible }) { } return ( -
+
- ) : latestMessage && !latestMessage?.isCreatedByUser ? ( - - ) : null} + :(latestMessage&&!latestMessage?.isCreatedByUser)? + + :null + }
- +
diff --git a/client/src/utils/handleSubmit.js b/client/src/utils/handleSubmit.js index b5803aef17..9e48c2028a 100644 --- a/client/src/utils/handleSubmit.js +++ b/client/src/utils/handleSubmit.js @@ -46,9 +46,8 @@ const useMessageHandler = () => { dispatch(setMessages([...currentMessages, initialResponse])); } else { dispatch(setMessages([...currentMessages, currentMsg, initialResponse])); + dispatch(setText('')); } - dispatch(setText('')); - const submission = { convo, isCustomModel, From a213868b1764abef5b796052dccb4a8770a26031 Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Sat, 18 Mar 2023 01:00:38 +0800 Subject: [PATCH 04/10] fix: set isSubmitting with messages together style: some notification --- client/src/components/Main/TextChat.jsx | 13 ++----------- client/src/utils/handleSubmit.js | 16 +++++++++------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/client/src/components/Main/TextChat.jsx b/client/src/components/Main/TextChat.jsx index 4544c8a35d..0038f37a7a 100644 --- a/client/src/components/Main/TextChat.jsx +++ b/client/src/components/Main/TextChat.jsx @@ -100,10 +100,6 @@ export default function TextChat({ messages }) { const { messages, _currentMsg, message, isCustomModel, sender, isRegenerate } = currentState; const { model, chatGptLabel, promptPrefix } = message; -<<<<<<< HEAD - if (isRegenerate) dispatch(setMessages([...messages, responseMessage])); - else dispatch(setMessages([...messages, requestMessage, responseMessage])); -======= if (isRegenerate) dispatch( setMessages([...messages, responseMessage,]) @@ -113,7 +109,6 @@ export default function TextChat({ messages }) { setMessages([...messages, requestMessage, responseMessage,]) ); dispatch(setSubmitState(false)); ->>>>>>> 92d0d11 (feat: save cancelled flag in message) const isBing = model === 'bingai' || model === 'sydney'; @@ -213,14 +208,10 @@ export default function TextChat({ messages }) { } const currentState = submission; -<<<<<<< HEAD - let currentMsg = { ...currentState.message }; -======= - let currentMsg = {...currentState.message}; + let currentMsg = { ...currentState.message }; let latestResponseText = ''; ->>>>>>> 92d0d11 (feat: save cancelled flag in message) const { server, payload } = createPayload(submission); const onMessage = (e) => { if (stopStream) { @@ -383,7 +374,7 @@ export default function TextChat({ messages }) { onChange={changeHandler} onCompositionStart={handleCompositionStart} onCompositionEnd={handleCompositionEnd} - placeholder={disabled ? 'Choose another model or customize GPT again' : isNotAppendable ? 'Can not send new message after an error or unfinished response.' : ''} + placeholder={disabled ? 'Choose another model or customize GPT again' : isNotAppendable ? 'Try to regenerate the incomplete response.' : ''} disabled={disabled || isNotAppendable} className="m-0 h-auto max-h-52 resize-none overflow-auto border-0 bg-transparent p-0 pl-12 pr-8 leading-6 focus:outline-none focus:ring-0 focus-visible:ring-0 dark:bg-transparent md:pl-8" /> diff --git a/client/src/utils/handleSubmit.js b/client/src/utils/handleSubmit.js index 9e48c2028a..a9fbdb0d45 100644 --- a/client/src/utils/handleSubmit.js +++ b/client/src/utils/handleSubmit.js @@ -41,13 +41,6 @@ const useMessageHandler = () => { const currentMsg = { sender: 'User', text, current: true, isCreatedByUser: true, parentMessageId, conversationId, messageId: fakeMessageId }; const initialResponse = { sender, text: '', parentMessageId: isRegenerate?messageId:fakeMessageId, messageId: (isRegenerate?messageId:fakeMessageId) + '_', submitting: true }; - dispatch(setSubmitState(true)); - if (isRegenerate) { - dispatch(setMessages([...currentMessages, initialResponse])); - } else { - dispatch(setMessages([...currentMessages, currentMsg, initialResponse])); - dispatch(setText('')); - } const submission = { convo, isCustomModel, @@ -63,7 +56,16 @@ const useMessageHandler = () => { initialResponse, sender, }; + console.log('User Input:', text); + + if (isRegenerate) { + dispatch(setMessages([...currentMessages, initialResponse])); + } else { + dispatch(setMessages([...currentMessages, currentMsg, initialResponse])); + dispatch(setText('')); + } + dispatch(setSubmitState(true)); dispatch(setSubmission(submission)); } From a90db1f1a42a6e7cb371efc8ebd4a18735f72c93 Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Sat, 18 Mar 2023 01:04:52 +0800 Subject: [PATCH 05/10] fix: add model to customGpts fix: filter models by model only --- client/src/components/Models/ModelMenu.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/components/Models/ModelMenu.jsx b/client/src/components/Models/ModelMenu.jsx index 300df6abba..9bc8aa5fdd 100644 --- a/client/src/components/Models/ModelMenu.jsx +++ b/client/src/components/Models/ModelMenu.jsx @@ -38,7 +38,8 @@ export default function ModelMenu() { const { data, isLoading, mutate } = swr(`/api/customGpts`, (res) => { const fetchedModels = res.map((modelItem) => ({ ...modelItem, - name: modelItem.chatGptLabel + name: modelItem.chatGptLabel, + model: 'chatgptCustom' })); dispatch(setModels(fetchedModels)); @@ -100,7 +101,7 @@ export default function ModelMenu() { localStorage.setItem('model', JSON.stringify(model)); }, [model]); - const filteredModels = models.filter(({model, _id }) => initial[model] || _id.length > 1 ); + const filteredModels = models.filter(({model, _id }) => initial[model] ); const onChange = (value) => { if (!value) { From ce78123369c64a3e97682fbe552f859800f5f445 Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Sat, 18 Mar 2023 01:24:35 +0800 Subject: [PATCH 06/10] fix: allow delete of last char while submitting --- client/src/components/Main/TextChat.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/components/Main/TextChat.jsx b/client/src/components/Main/TextChat.jsx index 0038f37a7a..969a6222ac 100644 --- a/client/src/components/Main/TextChat.jsx +++ b/client/src/components/Main/TextChat.jsx @@ -317,9 +317,9 @@ export default function TextChat({ messages }) { const changeHandler = (e) => { const { value } = e.target; - if (isSubmitting && (value === '' || value === '\n')) { - return; - } + // if (isSubmitting && (value === '' || value === '\n')) { + // return; + // } dispatch(setText(value)); }; From e8611a1d0783febe2ec70de2199fa658a9d2a3d2 Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Sat, 18 Mar 2023 01:54:06 +0800 Subject: [PATCH 07/10] fix: don't reset isSubmitting in useEffect of submission --- client/src/components/Main/TextChat.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/components/Main/TextChat.jsx b/client/src/components/Main/TextChat.jsx index 969a6222ac..759d045c07 100644 --- a/client/src/components/Main/TextChat.jsx +++ b/client/src/components/Main/TextChat.jsx @@ -267,7 +267,6 @@ export default function TextChat({ messages }) { events.stream(); return () => { - dispatch(setSubmitState(false)); events.removeEventListener('message', onMessage); const isCancelled = events.readyState <= 1; events.close(); From 7987c0100cc44b98298a585d6859903ea741ba63 Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Sat, 18 Mar 2023 02:04:51 +0800 Subject: [PATCH 08/10] fix: add crypto as deps. [need confirm] --- api/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/api/package.json b/api/package.json index 8311456f41..71f38cc780 100644 --- a/api/package.json +++ b/api/package.json @@ -24,6 +24,7 @@ "@waylaidwanderer/chatgpt-api": "^1.28.2", "axios": "^1.3.4", "cors": "^2.8.5", + "crypto": "^1.0.1", "dotenv": "^16.0.3", "express": "^4.18.2", "express-session": "^1.17.3", From 0ff3bbb28f8bb1862443e7d50c203a00ca2c8013 Mon Sep 17 00:00:00 2001 From: Wentao Lyu <35-wentao.lyu@users.noreply.git.stereye.tech> Date: Sat, 18 Mar 2023 02:15:24 +0800 Subject: [PATCH 09/10] clean up --- client/src/components/Main/TextChat.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/components/Main/TextChat.jsx b/client/src/components/Main/TextChat.jsx index 759d045c07..aeae024c22 100644 --- a/client/src/components/Main/TextChat.jsx +++ b/client/src/components/Main/TextChat.jsx @@ -35,7 +35,7 @@ export default function TextChat({ messages }) { const { error, latestMessage } = convo; const { ask, regenerate, stopGenerating } = useMessageHandler(); - const isNotAppendable = (!isSubmitting && latestMessage?.cancelled) || latestMessage?.error; + const isNotAppendable = latestMessage?.cancelled || latestMessage?.error; // auto focus to input, when enter a conversation. useEffect(() => { From 1513c27f7d3e1a763361a9ac53e8e63da151bca8 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Fri, 17 Mar 2023 14:48:21 -0400 Subject: [PATCH 10/10] adjust: wording and placeholder text size --- client/src/components/Main/TextChat.jsx | 90 ++++++++++++++++--------- 1 file changed, 57 insertions(+), 33 deletions(-) diff --git a/client/src/components/Main/TextChat.jsx b/client/src/components/Main/TextChat.jsx index aeae024c22..4459645d2a 100644 --- a/client/src/components/Main/TextChat.jsx +++ b/client/src/components/Main/TextChat.jsx @@ -43,7 +43,6 @@ export default function TextChat({ messages }) { }, [convo?.conversationId]); const messageHandler = (data, currentState, currentMsg) => { - const { messages, _currentMsg, message, sender, isRegenerate } = currentState; if (isRegenerate) @@ -79,9 +78,32 @@ export default function TextChat({ messages }) { const { messages, _currentMsg, message, sender, isRegenerate } = currentState; if (isRegenerate) - dispatch(setMessages([...messages, { sender, text: data, parentMessageId: message?.overrideParentMessageId, messageId: message?.overrideParentMessageId + '_', cancelled: true }])); + dispatch( + setMessages([ + ...messages, + { + sender, + text: data, + parentMessageId: message?.overrideParentMessageId, + messageId: message?.overrideParentMessageId + '_', + cancelled: true + } + ]) + ); else - dispatch(setMessages([...messages, currentMsg, { sender, text: data, parentMessageId: currentMsg?.messageId, messageId: currentMsg?.messageId + '_', cancelled: true }])); + dispatch( + setMessages([ + ...messages, + currentMsg, + { + sender, + text: data, + parentMessageId: currentMsg?.messageId, + messageId: currentMsg?.messageId + '_', + cancelled: true + } + ]) + ); }; const createdHandler = (data, currentState, currentMsg) => { @@ -100,14 +122,8 @@ export default function TextChat({ messages }) { const { messages, _currentMsg, message, isCustomModel, sender, isRegenerate } = currentState; const { model, chatGptLabel, promptPrefix } = message; - if (isRegenerate) - dispatch( - setMessages([...messages, responseMessage,]) - ); - else - dispatch( - setMessages([...messages, requestMessage, responseMessage,]) - ); + if (isRegenerate) dispatch(setMessages([...messages, responseMessage])); + else dispatch(setMessages([...messages, requestMessage, responseMessage])); dispatch(setSubmitState(false)); const isBing = model === 'bingai' || model === 'sydney'; @@ -211,7 +227,7 @@ export default function TextChat({ messages }) { let currentMsg = { ...currentState.message }; let latestResponseText = ''; - + const { server, payload } = createPayload(submission); const onMessage = (e) => { if (stopStream) { @@ -271,8 +287,8 @@ export default function TextChat({ messages }) { const isCancelled = events.readyState <= 1; events.close(); if (isCancelled) { - const e = new Event("cancel"); - events.dispatchEvent(e) + const e = new Event('cancel'); + events.dispatchEvent(e); } }; }, [submission]); @@ -328,11 +344,11 @@ export default function TextChat({ messages }) { }; return ( -
-
+
+
- - {isSubmitting? + + {isSubmitting ? ( - :(latestMessage&&!latestMessage?.isCreatedByUser)? - - :null - } + ) : latestMessage && !latestMessage?.isCreatedByUser ? ( + + ) : null}
+ -