增加流式返回的开关
This commit is contained in:
@@ -5,6 +5,7 @@ import {mapState} from "vuex";
|
||||
import AiDrag from "../basic/AiDrag.vue";
|
||||
import AiLocateDialog from "../tools/AiLocateDialog.vue";
|
||||
import AiUploader from "../basic/AiUploader.vue";
|
||||
import {$checkJson} from "../../lib/js/utils";
|
||||
|
||||
export default {
|
||||
name: "AiCopilot",
|
||||
@@ -137,8 +138,8 @@ export default {
|
||||
else this.$message.error("最多上传一个文件")
|
||||
},
|
||||
sendMessage(message, isSSE = false) {
|
||||
if (isSSE) {
|
||||
const {content, sdkFileUrl} = message
|
||||
if (isSSE || localStorage.getItem("isSSE")) {
|
||||
const {content, sdkFileUrl, appId} = message
|
||||
const body = {
|
||||
inputs: {},
|
||||
query: content,
|
||||
@@ -149,21 +150,29 @@ export default {
|
||||
return new Promise(resolve => this.http.post("/sse/chat-messages", body, {
|
||||
withoutToken: 1, headers: {
|
||||
Accept: 'text/event-stream',
|
||||
Authorization: "Bearer app-DRXYELe63911kx7F9RvKUonf"
|
||||
Authorization: `Bearer ${appId}`
|
||||
},
|
||||
onDownloadProgress: evt => {
|
||||
evt.target.responseText.split("data:").forEach(data => {
|
||||
if (data.trim()) {
|
||||
evt.target.responseText.split(/(data|event):/).forEach(data => {
|
||||
if ($checkJson(data.trim())) {
|
||||
const res = JSON.parse(data.trim())
|
||||
if (this.history.at(-1).userType != 1) {
|
||||
this.history.push({userType: 1, content: "", workflow: []})
|
||||
}
|
||||
const last = this.history.at(-1)
|
||||
if (res.event == "node_started") {
|
||||
last.workflow = ["el-icon-loading", res.data.title]
|
||||
} else if (res.event == "node_finished") {
|
||||
last.workflow = ["el-icon-finished", res.data.title]
|
||||
}
|
||||
const chunk = res.answer?.trim()
|
||||
if (!!chunk) {
|
||||
if (this.history.at(-1).userType != 1) {
|
||||
this.history.push({userType: 1, content: chunk})
|
||||
} else if (!this.history.at(-1).content?.includes(chunk)) {
|
||||
this.history.at(-1).content += chunk
|
||||
}
|
||||
if (!last.content?.includes(chunk)) last.content += chunk
|
||||
}
|
||||
if (res.event == "message_end") {
|
||||
last.workflow = ""
|
||||
resolve()
|
||||
}
|
||||
if (res.event == "message_end") resolve()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user