From 7cd47f60e1ab9721a47379270ca831ab86ef81f5 Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 17 Sep 2024 17:40:30 +1000 Subject: [PATCH 1/7] callback after stream finished Signed-off-by: cbh778899 --- src/utils/workers/openai-worker.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/workers/openai-worker.js b/src/utils/workers/openai-worker.js index 0eb0c26..99ff0e1 100644 --- a/src/utils/workers/openai-worker.js +++ b/src/utils/workers/openai-worker.js @@ -96,6 +96,7 @@ export async function chatCompletions(messages, cb = null) { if(chunk.choices[0].finish_reason) break; if(abort_signal) break; } + cb && cb(response_text, true); } catch(error) { console.error(error); cb && cb(`**${error.name}**:\n\`\`\`\n${error.message}\n\`\`\``, true); From 9ad5fc6f3c4ebaa4eefbf10fadc5f87beff8fef6 Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 17 Sep 2024 17:40:56 +1000 Subject: [PATCH 2/7] do not store session to idb, this will fail everytime Signed-off-by: cbh778899 --- src/components/chat/index.jsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/chat/index.jsx b/src/components/chat/index.jsx index 51ce95f..2320190 100644 --- a/src/components/chat/index.jsx +++ b/src/components/chat/index.jsx @@ -1,13 +1,11 @@ import { useState } from "react"; import Tickets from "./Tickets"; import Conversation from "./Conversation"; -import useIDB from "../../utils/idb"; export default function Chat() { const [chat, selectChat] = useState({}); const [history, setHistory] = useState([]); - const idb = useIDB(); function updateChatClient(client) { selectChat({ @@ -19,8 +17,6 @@ export default function Chat() { history_cp.findIndex(e=>e.uid === chat.uid) ].client = client; setHistory(history_cp); - - idb.updateOne('chat-history', {client}, [{uid:chat.uid}]) } return ( From 3ffd1da27f882f7f5fc384626fdda35165e39913 Mon Sep 17 00:00:00 2001 From: cbh778899 Date: Tue, 17 Sep 2024 17:41:33 +1000 Subject: [PATCH 3/7] specify if there's an empty message Signed-off-by: cbh778899 --- src/components/chat/Conversation.jsx | 14 ++++---------- src/components/chat/ConversationBubble.jsx | 6 +++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/components/chat/Conversation.jsx b/src/components/chat/Conversation.jsx index 4ad1894..5559b39 100644 --- a/src/components/chat/Conversation.jsx +++ b/src/components/chat/Conversation.jsx @@ -53,7 +53,6 @@ export default function Conversation({ uid, client, updateClient }) { if(!isFinished) { setPendingMessage(text); } else { - setPendingMessage(''); setConversation([ ...conversation, user_msg, { role: 'assistant', content: text } @@ -67,7 +66,6 @@ export default function Conversation({ uid, client, updateClient }) { idb.updateOne( 'chat-history', {updatedAt: Date.now()}, [{uid}] ) - setHidePending(true); } } @@ -106,13 +104,9 @@ export default function Conversation({ uid, client, updateClient }) { ] } - const result = await chat_functions.current.completions(messages, cb); - if(!result) { - setPendingMessage(''); - setHidePending(true); - } else { - console.log(result) - } + await chat_functions.current.completions(messages, cb); + setPendingMessage(''); + setHidePending(true); } useEffect(()=>{ @@ -163,7 +157,7 @@ export default function Conversation({ uid, client, updateClient }) { }) }