test: output

This commit is contained in:
ChenZhaoYu
2023-03-28 16:11:52 +08:00
parent 76cef650b4
commit 88740c13f0
2 changed files with 100 additions and 89 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,
})
@@ -76,7 +85,7 @@ router.post('/verify', async (req, res) => {
res.send({ status: 'Success', message: 'Verify successfully', data: null })
}
catch (error) {
res.send({ status: 'Fail', message: error.message, data: null })
res.send({ status: 'Fail', message: error.messagen, data: null })
}
})