mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: 对话流处理
This commit is contained in:
parent
d3409d9845
commit
d7f6ec1fba
|
|
@ -165,8 +165,10 @@ class ChatMessageSerializer(serializers.Serializer):
|
|||
for chunk in response:
|
||||
all_text += chunk.content
|
||||
yield 'data: ' + json.dumps({'chat_id': chat_id, 'id': _id, 'operate': paragraph is not None,
|
||||
'content': chunk.content}) + "\n\n"
|
||||
'content': chunk.content, 'is_end': False}) + "\n\n"
|
||||
|
||||
yield 'data: ' + json.dumps({'chat_id': chat_id, 'id': _id, 'operate': paragraph is not None,
|
||||
'content': '', 'is_end': True}) + "\n\n"
|
||||
chat_info.append_chat_message(
|
||||
ChatMessage(_id, message, title, content, embedding_id, dataset_id, document_id,
|
||||
paragraph_id,
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ export class ChatRecordManage {
|
|||
this.chat.write_ed = true
|
||||
this.write_ed = true
|
||||
if (this.loading) {
|
||||
console.log('停止')
|
||||
this.loading.value = false
|
||||
}
|
||||
if (this.id) {
|
||||
|
|
@ -76,7 +75,6 @@ export class ChatRecordManage {
|
|||
}
|
||||
}
|
||||
close() {
|
||||
console.log('close')
|
||||
this.is_close = true
|
||||
}
|
||||
append(answer_text_block: string) {
|
||||
|
|
|
|||
|
|
@ -282,13 +282,17 @@ function chatMessage() {
|
|||
if (str && str.startsWith('data:')) {
|
||||
const split = str.match(/data:.*}\n\n/g)
|
||||
if (split) {
|
||||
split.forEach((item_str) => {
|
||||
row.record_id = JSON?.parse(item_str.replace('data:', '')).id
|
||||
const content = JSON?.parse(item_str.replace('data:', ''))?.content
|
||||
for (const index in split) {
|
||||
const chunk = JSON?.parse(split[index].replace('data:', ''))
|
||||
row.record_id = chunk.id
|
||||
const content = chunk?.content
|
||||
if (content) {
|
||||
ChatManagement.append(id, content)
|
||||
}
|
||||
})
|
||||
if (chunk.is_end) {
|
||||
ChatManagement.close(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
@ -297,7 +301,15 @@ function chatMessage() {
|
|||
}
|
||||
return reader.read().then(write)
|
||||
}
|
||||
reader.read().then(write)
|
||||
reader
|
||||
.read()
|
||||
.then(write)
|
||||
.finally((ok: any) => {
|
||||
ChatManagement.close(id)
|
||||
})
|
||||
.catch((e: any) => {
|
||||
ChatManagement.close(id)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue