mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-07-21 11:57:47 +00:00
perf: optimized output (#962)
* Update index.ts * Update index.vue * Update index.ts
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
Reference in New Issue
Block a user