Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SWLab UI
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
SWD
SWLab UI
Commits
7866693e
Commit
7866693e
authored
Sep 20, 2024
by
박민석
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test chatbot
parent
da41f056
Pipeline
#21073
failed with stages
in 1 minute and 35 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
1 deletion
+23
-1
08-chat.js
src/js/08-chat.js
+23
-1
No files found.
src/js/08-chat.js
View file @
7866693e
...
...
@@ -171,6 +171,11 @@
isLoading
=
true
const
messageItem
=
document
.
createElement
(
'pre'
)
messageItem
.
className
=
'message ai'
chatBody
.
appendChild
(
messageItem
)
chatBody
.
scrollTop
=
chatBody
.
scrollHeight
const
payload
=
{
question
:
message
,
docsType
:
docType
.
toLowerCase
(),
...
...
@@ -184,10 +189,27 @@
body
:
JSON
.
stringify
(
payload
),
})
.
then
((
response
)
=>
{
console
.
log
(
response
)
// response 확인 테스트
const
reader
=
response
.
body
?.
getReader
()
const
decoder
=
new
TextDecoder
(
'utf-8'
)
function
readStream
()
{
return
reader
?.
read
().
then
(({
done
,
value
})
=>
{
if
(
done
)
{
isLoading
=
false
return
}
const
chunk
=
decoder
.
decode
(
value
,
{
stream
:
true
})
messageItem
.
textContent
+=
chunk
chatBody
.
scrollTop
=
chatBody
?.
scrollHeight
return
readStream
()
})
}
return
readStream
()
})
.
catch
((
error
)
=>
{
console
.
error
(
'Chatbot Error'
,
error
)
isLoading
=
false
})
// const chatLoader = document.createElement('div')
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment