perf: optimized output (#962)

* Update index.ts

* Update index.vue

* Update index.ts
This commit is contained in:
assassinliujie
2023-03-28 15:47:40 +08:00
committed by GitHub
parent c0a9fd5208
commit 78bcf7f4ce
2 changed files with 99 additions and 88 deletions

View File

@@ -25,12 +25,21 @@ router.post('/chat-process', [auth, limiter], async (req, res) => {
try {
const { prompt, options = {}, systemMessage } = req.body as RequestProps
let firstChunk = true
let chatLength = 0
let newChatLength = 0
await chatReplyProcess({
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 if (chatLength !== chat.text.length) {
newChatLength = chat.text.length
res.write(chat.text.substring(chatLength, newChatLength))
chatLength = newChatLength
}
},
systemMessage,
})