Commit 04a98081 authored by 박민석's avatar 박민석

add chatLoader

parent 618456f2
Pipeline #21107 passed with stages
in 3 minutes and 46 seconds
...@@ -164,21 +164,25 @@ ...@@ -164,21 +164,25 @@
chatBody.appendChild(user) chatBody.appendChild(user)
chatBody.scrollTop = chatBody.scrollHeight chatBody.scrollTop = chatBody.scrollHeight
if (!docType) { // if (!docType) {
createAiMessage('가이드 도움에 필요한 제품을 선택해주세요.') // createAiMessage('가이드 도움에 필요한 제품을 선택해주세요.')
return // return
} // }
isLoading = true isLoading = true
const messageItem = document.createElement('pre') const chatLoader = document.createElement('div')
messageItem.className = 'message ai' chatLoader.className = 'chat-loader'
chatBody.appendChild(messageItem) const loader = document.createElement('div')
loader.className = 'loader'
chatLoader.appendChild(loader)
chatBody.appendChild(chatLoader)
chatBody.scrollTop = chatBody.scrollHeight chatBody.scrollTop = chatBody.scrollHeight
const payload = { const payload = {
question: message, question: message,
docsType: docType.toLowerCase(), // docsType: docType.toLowerCase(),
docsType: 'bxi',
} }
fetch('https://docs.bxi.link/ask', { fetch('https://docs.bxi.link/ask', {
...@@ -192,9 +196,13 @@ ...@@ -192,9 +196,13 @@
const reader = response.body?.getReader() const reader = response.body?.getReader()
const decoder = new TextDecoder('utf-8') const decoder = new TextDecoder('utf-8')
const messageItem = document.createElement('pre')
messageItem.className = 'message ai'
function readStream () { function readStream () {
return reader?.read().then(({ done, value }) => { return reader?.read().then(({ done, value }) => {
if (done) { if (done) {
chatBody.removeChild(chatLoader)
isLoading = false isLoading = false
return return
} }
...@@ -205,32 +213,16 @@ ...@@ -205,32 +213,16 @@
}) })
} }
chatBody.appendChild(messageItem)
chatBody.scrollTop = chatBody.scrollHeight
return readStream() return readStream()
}) })
.catch((error) => { .catch((error) => {
console.error('Chatbot Error', error) console.error('Chatbot Error', error)
chatBody.removeChild(chatLoader)
isLoading = false isLoading = false
}) })
// const chatLoader = document.createElement('div')
// chatLoader.className = 'chat-loader'
// const loader = document.createElement('div')
// loader.className = 'loader'
// chatLoader.appendChild(loader)
// chatBody.appendChild(chatLoader)
// chatBody.scrollTop = chatBody.scrollHeight
// setTimeout(() => {
// chatBody.removeChild(chatLoader)
// const ai = document.createElement('pre')
// ai.className = 'message ai'
// ai.textContent = '지금은 답해드릴 수 없어요.'
// chatBody.appendChild(ai)
// chatBody.scrollTop = chatBody.scrollHeight
// isLoading = false
// }, 3000)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment