|
@ -44,7 +44,7 @@ |
|
|
v-if="item.isStop && !item.isEnd" |
|
|
v-if="item.isStop && !item.isEnd" |
|
|
@click="startChat(index)" |
|
|
@click="startChat(index)" |
|
|
link |
|
|
link |
|
|
>继续 |
|
|
>重新生成 |
|
|
</el-button> |
|
|
</el-button> |
|
|
<el-button type="primary" v-else-if="!item.isEnd" @click="stopChat(index)" link |
|
|
<el-button type="primary" v-else-if="!item.isEnd" @click="stopChat(index)" link |
|
|
>停止回答 |
|
|
>停止回答 |
|
@ -150,7 +150,7 @@ |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
<!-- 文件导入对话框 --> |
|
|
<!-- 文件导入对话框 --> |
|
|
<el-dialog title="文件导入" v-model="upload.open" width="400px" append-to-body> |
|
|
<el-dialog z-index="9999" title="文件导入" v-model="upload.open" width="400px" append-to-body> |
|
|
<el-upload v-if="upload.open" |
|
|
<el-upload v-if="upload.open" |
|
|
ref="uploadRef" |
|
|
ref="uploadRef" |
|
|
:headers="upload.headers" |
|
|
:headers="upload.headers" |
|
@ -229,6 +229,7 @@ const inputValue = ref('') |
|
|
const chartOpenId = ref('') |
|
|
const chartOpenId = ref('') |
|
|
const chatList = ref([]) |
|
|
const chatList = ref([]) |
|
|
const answerList = ref([]) |
|
|
const answerList = ref([]) |
|
|
|
|
|
const controller = ref(null) |
|
|
|
|
|
|
|
|
const popoverVisible = ref(false) |
|
|
const popoverVisible = ref(false) |
|
|
const currentMachine = ref([]) |
|
|
const currentMachine = ref([]) |
|
@ -263,32 +264,22 @@ function setScrollBottom() { |
|
|
*/ |
|
|
*/ |
|
|
const scrollTop = ref(0) |
|
|
const scrollTop = ref(0) |
|
|
|
|
|
|
|
|
const scorll = ref(true) |
|
|
|
|
|
|
|
|
|
|
|
const getMaxHeight = () => { |
|
|
const getMaxHeight = () => { |
|
|
return dialogScrollbar.value.scrollHeight |
|
|
return dialogScrollbar.value.scrollHeight |
|
|
} |
|
|
} |
|
|
const handleScrollTop = ($event) => { |
|
|
const handleScrollTop = ($event) => { |
|
|
scrollTop.value = $event.scrollTop |
|
|
scrollTop.value = $event.scrollTop |
|
|
if ( |
|
|
|
|
|
dialogScrollbar.value.scrollHeight - (scrollTop.value + scrollDiv.value.wrapRef.offsetHeight) <= |
|
|
|
|
|
30 |
|
|
|
|
|
) { |
|
|
|
|
|
scorll.value = true |
|
|
|
|
|
} else { |
|
|
|
|
|
scorll.value = false |
|
|
|
|
|
} |
|
|
|
|
|
emit('scroll', { ...$event, dialogScrollbar: dialogScrollbar.value, scrollDiv: scrollDiv.value }) |
|
|
emit('scroll', { ...$event, dialogScrollbar: dialogScrollbar.value, scrollDiv: scrollDiv.value }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const handleScroll = () => { |
|
|
const handleScroll = () => { |
|
|
if (!props.log && scrollDiv.value) { |
|
|
if (scrollDiv.value) { |
|
|
// 内部高度小于外部高度 就需要出滚动条 |
|
|
// 内部高度小于外部高度 就需要出滚动条 |
|
|
if (scrollDiv.value.wrapRef.offsetHeight < dialogScrollbar.value.scrollHeight) { |
|
|
if (scrollDiv.value.wrapRef.offsetHeight < dialogScrollbar.value.scrollHeight) { |
|
|
// 如果当前滚动条距离最下面的距离在 规定距离 滚动条就跟随 |
|
|
// 如果当前滚动条距离最下面的距离在 规定距离 滚动条就跟随 |
|
|
if (scorll.value) { |
|
|
|
|
|
scrollDiv.value.setScrollTop(getMaxHeight()) |
|
|
scrollDiv.value.setScrollTop(getMaxHeight()) |
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -303,7 +294,8 @@ const handleFileSuccess = (response, file, fileList) => { |
|
|
currentFiles.value.push({file:response.data.file,bucket:response.data.bucket}) |
|
|
currentFiles.value.push({file:response.data.file,bucket:response.data.bucket}) |
|
|
upload.open = false; |
|
|
upload.open = false; |
|
|
upload.isUploading = false; |
|
|
upload.isUploading = false; |
|
|
proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true }); |
|
|
proxy.$modal.msgSuccess(response.msg); |
|
|
|
|
|
// proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true }); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/** 提交上传文件 */ |
|
|
/** 提交上传文件 */ |
|
@ -425,7 +417,9 @@ async function sendChatHandle(event) { |
|
|
if (!event.ctrlKey) { |
|
|
if (!event.ctrlKey) { |
|
|
// 如果没有按下组合键ctrl,则会阻止默认事件 |
|
|
// 如果没有按下组合键ctrl,则会阻止默认事件 |
|
|
event.preventDefault() |
|
|
event.preventDefault() |
|
|
if (inputValue.value.trim() && ((chatList.value.length > 1 && chatList.value[chatList.value.length - 1].isEnd) || chatList.value.length < 2)) { |
|
|
if (inputValue.value.trim() && (chatList.value.length === 0|| |
|
|
|
|
|
(chatList.value[chatList.value.length - 1].isStop || |
|
|
|
|
|
chatList.value[chatList.value.length - 1].isEnd))) { |
|
|
chatList.value.push({ |
|
|
chatList.value.push({ |
|
|
"type": "question", |
|
|
"type": "question", |
|
|
"content": inputValue.value.trim(), |
|
|
"content": inputValue.value.trim(), |
|
@ -434,13 +428,13 @@ async function sendChatHandle(event) { |
|
|
"sessionName": chatList.value.length > 0 ? chatList.value[0].content.substring(0, 20) : inputValue.value.trim().substring(0, 20), |
|
|
"sessionName": chatList.value.length > 0 ? chatList.value[0].content.substring(0, 20) : inputValue.value.trim().substring(0, 20), |
|
|
"file": currentFiles.value |
|
|
"file": currentFiles.value |
|
|
}) |
|
|
}) |
|
|
|
|
|
let question = JSON.parse(JSON.stringify(chatList.value[chatList.value.length - 1])) |
|
|
|
|
|
question.file = JSON.stringify(question.file) |
|
|
|
|
|
await addChat(question) |
|
|
nextTick(() => { |
|
|
nextTick(() => { |
|
|
// 将滚动条滚动到最下面 |
|
|
// 将滚动条滚动到最下面 |
|
|
scrollDiv.value.setScrollTop(getMaxHeight()) |
|
|
scrollDiv.value.setScrollTop(getMaxHeight()) |
|
|
}) |
|
|
}) |
|
|
let question = JSON.parse(JSON.stringify(chatList.value[chatList.value.length - 1])) |
|
|
|
|
|
question.file = JSON.stringify(question.file) |
|
|
|
|
|
await addChat(question) |
|
|
|
|
|
inputValue.value = '' |
|
|
inputValue.value = '' |
|
|
let data = { |
|
|
let data = { |
|
|
"query": inputValue.value.trim(), |
|
|
"query": inputValue.value.trim(), |
|
@ -459,7 +453,11 @@ async function sendChatHandle(event) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function sendChatMessage(data){ |
|
|
function sendChatMessage(data){ |
|
|
postChatMessage(data).then(res=>{ |
|
|
controller.value = new AbortController() |
|
|
|
|
|
postChatMessage(data,{signal:controller.value.signal}).then(res=>{ |
|
|
|
|
|
if (res.status !== 200){ |
|
|
|
|
|
chatList.value.push({"type":"answer","content":[{"type":"text","content":"服务异常,错误码:"+res.status}],"isEnd":true,"isStop":false,"sessionId":chatList.value[0].sessionId,"sessionName":chatList.value[0].sessionName,"operate":'',"thumbDownReason":''}) |
|
|
|
|
|
}else { |
|
|
currentFiles.value = [] |
|
|
currentFiles.value = [] |
|
|
chatList.value.push({"type":"answer","content":[],"isEnd":false,"isStop":false,"sessionId":chatList.value[0].sessionId,"sessionName":chatList.value[0].sessionName, "operate":'',"thumbDownReason":''}) |
|
|
chatList.value.push({"type":"answer","content":[],"isEnd":false,"isStop":false,"sessionId":chatList.value[0].sessionId,"sessionName":chatList.value[0].sessionName, "operate":'',"thumbDownReason":''}) |
|
|
answerList.value.push({"index":chatList.value.length-1, "content":[], "isEnd":false}) |
|
|
answerList.value.push({"index":chatList.value.length-1, "content":[], "isEnd":false}) |
|
@ -470,16 +468,21 @@ function sendChatMessage(data){ |
|
|
answer.content = JSON.stringify(answer.content) |
|
|
answer.content = JSON.stringify(answer.content) |
|
|
addChat(answer) |
|
|
addChat(answer) |
|
|
}) |
|
|
}) |
|
|
|
|
|
} |
|
|
}).catch((e) => { |
|
|
}).catch((e) => { |
|
|
chatList.value.push({"type":"answer","content":[{"type":"text","content":"服务异常"}],"isEnd":true,"isStop":false}) |
|
|
chatList.value.push({"type":"answer","content":[{"type":"text","content":"服务异常"}],"isEnd":true,"isStop":false,"sessionId":chatList.value[0].sessionId,"sessionName":chatList.value[0].sessionName,"operate":"","thumbDownReason":""}) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
watch( |
|
|
watch( |
|
|
chatList, |
|
|
chatList, |
|
|
() => { |
|
|
() => { |
|
|
handleScroll() |
|
|
nextTick(() => { |
|
|
}, |
|
|
// 将滚动条滚动到最下面 |
|
|
{ deep: true, immediate: true } |
|
|
scrollDiv.value.setScrollTop(getMaxHeight()) |
|
|
|
|
|
}) |
|
|
|
|
|
},{ |
|
|
|
|
|
deep:true, immediate:true |
|
|
|
|
|
} |
|
|
) |
|
|
) |
|
|
const getWrite = (reader) => { |
|
|
const getWrite = (reader) => { |
|
|
let tempResult = ''; |
|
|
let tempResult = ''; |
|
@ -533,7 +536,8 @@ const getWrite = (reader) => { |
|
|
answerList.value[answerList.value.length - 1].content.push({"content":chunk.choices[0].delta.content,"type":"text"}) |
|
|
answerList.value[answerList.value.length - 1].content.push({"content":chunk.choices[0].delta.content,"type":"text"}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (!chatList.value[answerList.value[answerList.value.length - 1].index].isStop){ |
|
|
let isStop = chatList.value[chatList.value.length-1].isStop |
|
|
|
|
|
if (!isStop){ |
|
|
chatList.value[chatList.value.length - 1].content = answerList.value[answerList.value.length - 1].content |
|
|
chatList.value[chatList.value.length - 1].content = answerList.value[answerList.value.length - 1].content |
|
|
} |
|
|
} |
|
|
nextTick(() => { |
|
|
nextTick(() => { |
|
@ -543,7 +547,7 @@ const getWrite = (reader) => { |
|
|
if (chunk.isEnd){ |
|
|
if (chunk.isEnd){ |
|
|
answerList.value[answerList.value.length - 1].isEnd = true |
|
|
answerList.value[answerList.value.length - 1].isEnd = true |
|
|
answerList.value[answerList.value.length - 1].time = formatDate(new Date()) |
|
|
answerList.value[answerList.value.length - 1].time = formatDate(new Date()) |
|
|
if (!chatList.value[answerList.value[answerList.value.length - 1].index].isStop){ |
|
|
if (!isStop){ |
|
|
chatList.value[chatList.value.length - 1].isEnd = true |
|
|
chatList.value[chatList.value.length - 1].isEnd = true |
|
|
chatList.value[chatList.value.length - 1].time = formatDate(new Date()) |
|
|
chatList.value[chatList.value.length - 1].time = formatDate(new Date()) |
|
|
} |
|
|
} |
|
@ -565,9 +569,15 @@ const getWrite = (reader) => { |
|
|
|
|
|
|
|
|
const stopChat = (index) => { |
|
|
const stopChat = (index) => { |
|
|
chatList.value[index].isStop = true |
|
|
chatList.value[index].isStop = true |
|
|
|
|
|
if (controller.value !== null){ |
|
|
|
|
|
controller.value.abort() |
|
|
|
|
|
} |
|
|
|
|
|
let answer = JSON.parse(JSON.stringify(chatList.value[index])) |
|
|
|
|
|
answer.content = JSON.stringify(answer.content) |
|
|
|
|
|
addChat(answer) |
|
|
} |
|
|
} |
|
|
const startChat = (index) => { |
|
|
const startChat = (index) => { |
|
|
chatList.value[index].isStop = false |
|
|
regenerationChart(index) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
defineExpose({ |
|
|
defineExpose({ |
|
|