feat: add typing effect (#1017)

* feat: add typing effect

* fix: ts2339 xxx not exist on type 'never'

---------

Co-authored-by: WangYi <wangyi@windimg.com>
This commit is contained in:
puppywang
2023-03-31 11:50:32 +08:00
committed by GitHub
parent 468bed7705
commit c0f4af05e3
4 changed files with 46 additions and 15 deletions

View File

@@ -25,7 +25,7 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
try {
const { prompt, options = {}, systemMessage } = req.body as RequestProps
let firstChunk = true
await chatReplyProcess({
const finalResponse = await chatReplyProcess({
message: prompt,
lastContext: options,
process: (chat: ChatMessage) => {
@@ -34,6 +34,7 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
},
systemMessage,
})
res.write(firstChunk ? JSON.stringify(finalResponse) : `\n${JSON.stringify(finalResponse)}`)
}
catch (error) {
res.write(JSON.stringify(error))