pref: message output optimization (#935)

* Update index.ts

修改后端,让保留打字机效果的同时优化前后端之间传输的内容,节省流量和性能

* Update index.vue

修改前端,和之前修改的后端匹配,保留打字机效果同时优化性能和流量传输

* chore: lint fix

---------

Co-authored-by: ChenZhaoYu <790348264@qq.com>
This commit is contained in:
assassinliujie
2023-03-28 09:40:20 +08:00
committed by GitHub
parent e2eeee455a
commit b579d24d19
2 changed files with 98 additions and 88 deletions

View File

@@ -29,8 +29,16 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
message: prompt,
lastContext: options,
process: (chat: ChatMessage) => {
res.write(firstChunk ? JSON.stringify(chat) : `\n${JSON.stringify(chat)}`)
firstChunk = false
if (firstChunk) {
res.write(`${JSON.stringify(chat)}t1h1i4s5i1s4a1s9i1l9l8y1s0plit`)
firstChunk = false
}
else {
let tmp = chat.delta
if (!(chat.delta))
tmp = ''
res.write(tmp)
}
},
systemMessage,
})