Browse Source

智能助手优化

master
xueyinfei 4 weeks ago
parent
commit
7802e53588
  1. 52
      vue-fastapi-frontend/src/views/aichat/aichat.vue

52
vue-fastapi-frontend/src/views/aichat/aichat.vue

@ -66,19 +66,6 @@
<i class="ri-loader-2-line loading-icon"></i> <i class="ri-loader-2-line loading-icon"></i>
<span style="font-size: 14px;color: #409EFF">回复中...</span> <span style="font-size: 14px;color: #409EFF">回复中...</span>
</div> </div>
<!-- <el-button-->
<!-- type="primary"-->
<!-- v-if="chatList.length>0 && chatList[chatList.length-1].isStop && !chatList[chatList.length-1].isEnd"-->
<!-- @click="startChat(chatList.length-1)"-->
<!-- link-->
<!-- >重新生成-->
<!-- </el-button>-->
<!-- <el-button type="primary" v-else-if="chatList.length>0 && !chatList[chatList.length-1].isEnd" @click="stopChat(chatList.length-1)" link-->
<!-- >停止回答-->
<!-- </el-button>-->
<el-button type="primary" v-if="currentJobId !== ''" link @click="stopChat(chatList.length-1)"
>停止回答
</el-button>
</div> </div>
</div> </div>
<div v-if="currentError !== ''"> <div v-if="currentError !== ''">
@ -175,6 +162,7 @@
</el-popover> </el-popover>
<div class="operate flex align-center"> <div class="operate flex align-center">
<el-button <el-button
v-if="!asking"
text text
class="sent-button" class="sent-button"
:disabled="isDisabledChart || loading" :disabled="isDisabledChart || loading"
@ -183,6 +171,11 @@
<img v-show="isDisabledChart || loading" src="@/assets/aichat/icon_send.svg" alt="" /> <img v-show="isDisabledChart || loading" src="@/assets/aichat/icon_send.svg" alt="" />
<img v-show="!isDisabledChart && !loading" src="@/assets/aichat/icon_send_colorful.svg" alt="" /> <img v-show="!isDisabledChart && !loading" src="@/assets/aichat/icon_send_colorful.svg" alt="" />
</el-button> </el-button>
<el-button v-if="asking" link @click="stopChat">
<div style="width: 30px;height: 30px;border-radius: 50%;border:2px solid rgba(73,113,245,.5);text-align: center;line-height: 26px">
<i class="ri-stop-large-fill" style="color: #4971f5"></i>
</div>
</el-button>
<el-popover <el-popover
popper-style="z-index:3000;width:300px" popper-style="z-index:3000;width:300px"
title="自动审批配置" title="自动审批配置"
@ -316,6 +309,7 @@ const currentMachine = ref([])
const currentFiles = ref([]) const currentFiles = ref([])
const currentError = ref('') const currentError = ref('')
const currentJobId = ref('') const currentJobId = ref('')
const asking = ref(false)
const lastQuestion = ref({}) const lastQuestion = ref({})
const upload = reactive({ const upload = reactive({
// //
@ -333,7 +327,6 @@ const upload = reactive({
const isDisabledChart = computed( const isDisabledChart = computed(
() => !(inputValue.value.trim()) () => !(inputValue.value.trim())
) )
const emit = defineEmits(['scroll']) const emit = defineEmits(['scroll'])
function setScrollBottom() { function setScrollBottom() {
@ -585,7 +578,7 @@ async function sendChatHandle(event) {
if (inputValue.value.trim() && (chatList.value.length === 0|| if (inputValue.value.trim() && (chatList.value.length === 0||
(chatList.value[chatList.value.length - 1].isStop || (chatList.value[chatList.value.length - 1].isStop ||
chatList.value[chatList.value.length - 1].isEnd))) { chatList.value[chatList.value.length - 1].isEnd))) {
chatList.value.push({ lastQuestion.value = {
"chatId": uuidv4(), "chatId": uuidv4(),
"type": "question", "type": "question",
"content": inputValue.value.trim(), "content": inputValue.value.trim(),
@ -593,10 +586,8 @@ async function sendChatHandle(event) {
"sessionId": Cookies.get("chatSessionId"), "sessionId": Cookies.get("chatSessionId"),
"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])) asking.value = true
question.file = JSON.stringify(question.file)
await addChat(question)
nextTick(() => { nextTick(() => {
// //
scrollDiv.value.setScrollTop(getMaxHeight()) scrollDiv.value.setScrollTop(getMaxHeight())
@ -608,10 +599,9 @@ async function sendChatHandle(event) {
"session_id": Cookies.get("chatSessionId"), "session_id": Cookies.get("chatSessionId"),
"doc": currentFiles.value "doc": currentFiles.value
} }
if (chatList.value.length > 1){ if (chatList.value.length > 0){
// 1 chatList , >1
//checkpointer //checkpointer
data.checkpointer = chatList.value[chatList.value.length - 2].content.checkpointer data.checkpointer = chatList.value[chatList.value.length - 1].content.checkpointer
} }
currentQuestion.value = data currentQuestion.value = data
inputValue.value = '' inputValue.value = ''
@ -630,6 +620,10 @@ function sendChatMessage(data){
// chatList.value.push({"chatId":uuidv4(),"type":"answer","content":[{"type":"text","content":":"+res.status}],"isEnd":true,"isStop":false,"sessionId":chatList.value[0].sessionId,"sessionName":chatList.value[0].sessionName,"operate":'',"thumbDownReason":''}) // chatList.value.push({"chatId":uuidv4(),"type":"answer","content":[{"type":"text","content":":"+res.status}],"isEnd":true,"isStop":false,"sessionId":chatList.value[0].sessionId,"sessionName":chatList.value[0].sessionName,"operate":'',"thumbDownReason":''})
currentError.value = "服务异常,错误码:"+res.status +",请联系管理员!" currentError.value = "服务异常,错误码:"+res.status +",请联系管理员!"
}else { }else {
chatList.value.push(lastQuestion.value)
let question = JSON.parse(JSON.stringify(lastQuestion.value))
question.file = JSON.stringify(question.file)
addChat(question).then(()=>{
currentError.value = '' currentError.value = ''
currentChatData.value = {} currentChatData.value = {}
currentFiles.value = [] currentFiles.value = []
@ -637,6 +631,7 @@ function sendChatMessage(data){
const reader = res.body.getReader() const reader = res.body.getReader()
const write = getWrite(reader) const write = getWrite(reader)
reader.read().then(write).then(()=> { reader.read().then(write).then(()=> {
asking.value = false
let answer = JSON.parse(JSON.stringify(chatList.value[chatList.value.length - 1])) let answer = JSON.parse(JSON.stringify(chatList.value[chatList.value.length - 1]))
answer.content = JSON.stringify(answer.content) answer.content = JSON.stringify(answer.content)
answer.interrupt = answer.interrupt ? JSON.stringify(answer.interrupt): null answer.interrupt = answer.interrupt ? JSON.stringify(answer.interrupt): null
@ -684,19 +679,19 @@ function sendChatMessage(data){
reqData.action = action[i].action reqData.action = action[i].action
} }
} }
asking.value = true
sendChatMessage(reqData) sendChatMessage(reqData)
} }
} }
} }
}) })
})
} }
}).catch((e) => { }).catch((e) => {
currentError.value = "服务异常,请联系系统管理员!" currentError.value = "服务异常,请联系系统管理员!"
}) })
} }
watch( watch(
chatList, chatList,
() => { () => {
@ -789,18 +784,21 @@ const getWrite = (reader) => {
return write_stream; return write_stream;
}; };
const stopChat = (index) => { const stopChat = () => {
if (currentJobId.value !== ''){ if (currentJobId.value !== ''){
cancelJob({job_id:currentJobId.value}) cancelJob({job_id:currentJobId.value})
} }
chatList.value[index].isStop = true if (chatList.value.length > 0 || chatList.value[chatList.value.length - 1].type === 'answer'){
chatList.value[chatList.value.length - 1].isStop = true
}
if (controller.value !== null){ if (controller.value !== null){
controller.value.abort() controller.value.abort()
} }
let answer = JSON.parse(JSON.stringify(chatList.value[index])) let answer = JSON.parse(JSON.stringify(chatList.value[chatList.value.length - 1]))
answer.content = JSON.stringify(answer.content) answer.content = JSON.stringify(answer.content)
addChat(answer) addChat(answer)
currentJobId.value = '' currentJobId.value = ''
asking.value = false
} }
// const startChat = (index) => { // const startChat = (index) => {

Loading…
Cancel
Save