|
65 | 65 | } |
66 | 66 |
|
67 | 67 | function storeMessages() { |
68 | | - console.log('localStorage', chatMessages); |
69 | 68 |
|
70 | 69 | localStorage.setItem( |
71 | 70 | LOCAL_STORAGE_KEY.STORAGE_CHAT_KEY, |
|
77 | 76 | const eventSource = await fetchTextStream(query, knowledge_1); |
78 | 77 |
|
79 | 78 | eventSource.addEventListener("message", (e: any) => { |
80 | | - let currentMsg = e.data; |
81 | | - currentMsg = currentMsg.replace("@#$", " ") |
82 | | - console.log("currentMsg", currentMsg); |
83 | | - if (currentMsg == "[DONE]") { |
84 | | - console.log("done getCurrentTimeStamp", getCurrentTimeStamp); |
85 | | - let startTime = chatMessages[chatMessages.length - 1].time; |
86 | | -
|
87 | | - loading = false; |
88 | | - let totalTime = parseFloat(((getCurrentTimeStamp() - startTime) / 1000).toFixed(2)); |
89 | | - console.log("done totalTime", totalTime); |
90 | | - console.log( |
91 | | - "chatMessages[chatMessages.length - 1]", |
92 | | - chatMessages[chatMessages.length - 1] |
93 | | - ); |
94 | | -
|
95 | | - if (chatMessages.length - 1 !== -1) { |
96 | | - chatMessages[chatMessages.length - 1].time = totalTime; |
97 | | - } |
98 | | - console.log("done chatMessages", chatMessages); |
99 | | -
|
100 | | - storeMessages(); |
101 | | - } else { |
| 79 | + let Msg = e.data; |
| 80 | + if (Msg.startsWith("b")) { |
| 81 | + const currentMsg = Msg.slice(2, -1); |
102 | 82 | if (chatMessages[chatMessages.length - 1].role == MessageRole.User) { |
103 | | -
|
104 | 83 | chatMessages = [ |
105 | 84 | ...chatMessages, |
106 | 85 | { |
|
110 | 89 | time: startSendTime, |
111 | 90 | }, |
112 | 91 | ]; |
113 | | - console.log("? chatMessages", chatMessages); |
114 | 92 | } else { |
115 | 93 | let content = chatMessages[chatMessages.length - 1].content as string; |
116 | | - chatMessages[chatMessages.length - 1].content = |
117 | | - content + currentMsg; |
| 94 | + chatMessages[chatMessages.length - 1].content = content + currentMsg; |
118 | 95 | } |
119 | 96 | scrollToBottom(scrollToDiv); |
| 97 | + } else if (Msg === "[DONE]") { |
| 98 | + let startTime = chatMessages[chatMessages.length - 1].time; |
| 99 | +
|
| 100 | + loading = false; |
| 101 | + let totalTime = parseFloat( |
| 102 | + ((getCurrentTimeStamp() - startTime) / 1000).toFixed(2) |
| 103 | + ); |
| 104 | +
|
| 105 | + if (chatMessages.length - 1 !== -1) { |
| 106 | + chatMessages[chatMessages.length - 1].time = totalTime; |
| 107 | + } |
| 108 | +
|
| 109 | + storeMessages(); |
120 | 110 | } |
121 | 111 | }); |
122 | 112 | eventSource.stream(); |
|
171 | 161 | class="fixed relative flex w-full flex-col items-center justify-between bg-white p-2 pb-0" |
172 | 162 | > |
173 | 163 | <div class="relative my-4 flex w-full flex-row justify-center"> |
174 | | - <div class="focus:border-none relative w-full"> |
| 164 | + <div class="relative w-full focus:border-none"> |
175 | 165 | <input |
176 | 166 | class="text-md block w-full border-0 border-b-2 border-gray-300 px-1 py-4 |
177 | 167 | text-gray-900 focus:border-gray-300 focus:ring-0 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500" |
|
210 | 200 | <button |
211 | 201 | class="bg-primary text-primary-foreground hover:bg-primary/90 group flex items-center justify-center space-x-2 p-2" |
212 | 202 | type="button" |
213 | | - data-testid='clear-chat' |
| 203 | + data-testid="clear-chat" |
214 | 204 | on:click={() => handelClearHistory()} |
215 | 205 | ><svg |
216 | 206 | xmlns="http://www.w3.org/2000/svg" |
|
228 | 218 | {/if} |
229 | 219 | <!-- clear --> |
230 | 220 |
|
231 | | - <div class="mx-auto flex h-full w-full flex-col" data-testid='chat-message' |
232 | | - > |
| 221 | + <div class="mx-auto flex h-full w-full flex-col" data-testid="chat-message"> |
233 | 222 | <Scrollbar |
234 | 223 | classLayout="flex flex-col gap-1 mr-4" |
235 | 224 | className="chat-scrollbar h-0 w-full grow px-2 pt-2 mt-3 mr-5" |
|
0 commit comments