From 8189c098dba177425bcdb24d0a8a827f37b23e79 Mon Sep 17 00:00:00 2001 From: liudong <liudong> Date: 星期六, 24 八月 2024 13:48:43 +0800 Subject: [PATCH] agent名称修改 --- src/views/sessionManager/components/agentSession.vue | 151 +++++++++++++++++++++++++++++++++++--------------- 1 files changed, 105 insertions(+), 46 deletions(-) diff --git a/src/views/sessionManager/components/agentSession.vue b/src/views/sessionManager/components/agentSession.vue index 093bc27..9f193ca 100644 --- a/src/views/sessionManager/components/agentSession.vue +++ b/src/views/sessionManager/components/agentSession.vue @@ -9,7 +9,13 @@ trigger="click" > <a-button border - >{{agentTitle}} + > + <span style=" + width: 100px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + ">{{ from.name }}</span> <icon-down style="margin-left: 4px" /> </a-button> <template #content> @@ -75,7 +81,7 @@ auto-size v-model="sessionDetail.content" :class="{ chatItemAnswer: theme === 'light' }" - :style="{backgroundColor: theme === 'light' ? '#ffffff' : '#000000'}" + :style="{ backgroundColor: theme === 'light' ? '#ffffff' : '#000000'}" style="border: none" > </a-textarea> @@ -141,8 +147,8 @@ maxRows: 5, }" /> - <div class="btn-send"> - <!-- <icon-send size="32" /> --> + <div style="width: 100%;display: flex;justify-content: space-between"> + <span></span> <a-button :disabled="chatDis" @click="sentClick" @@ -154,11 +160,24 @@ </a-button > </div> +<!-- <div class="btn-send">--> +<!-- <!– <icon-send size="32" /> –>--> +<!-- <a-button--> +<!-- :disabled="chatDis"--> +<!-- @click="sentClick"--> +<!-- type="text"--> +<!-- style="border-radius: 24px"--> +<!-- :loading="loading"--> +<!-- >--> +<!-- <icon-send size="32" style="color: #0960bd;"/>--> +<!-- </a-button--> +<!-- >--> +<!-- </div>--> </div> <a-modal v-model:visible="visible" title="淇敼鍚嶇О" @before-open="handleOpened" @cancel="handleCancel" :footer="false" title-align="start"> - <a-form ref="formRef" :rules="rules" :model="agentObj" @submit="handleSubmit" > + <a-form ref="formRef" :rules="rules" :model="from" @submit="handleSubmit" > <a-form-item field="name" label="鍚嶇О"> - <a-input v-model="agentTitle" placeholder="璇疯緭鍏ュ悕绉�"/> + <a-input v-model="from.name" placeholder="璇疯緭鍏ュ悕绉�"/> </a-form-item> <a-form-item> <div style="width: 100%;text-align: right"> @@ -180,7 +199,7 @@ import { agentResetApi, agentSetApi, getAgentSessionDetailsApi } from "@/api/agentSession"; import EventBus from '@/utils/EventBus'; import useClipboard from "vue-clipboard3"; -import { addSessionApi } from "@/api/session"; +import { addSessionApi, getSessionDetailsApi } from "@/api/session"; const props = defineProps({ modalObj: Object, }); @@ -202,6 +221,7 @@ const streamStr = ref(''); const inputMsg = ref(''); const activeSessionId = ref(''); +const conversation_id = ref(''); const fieldNames = { value: 'id', label: 'name' }; const agentObj = reactive({}); const agentList = ref([]); @@ -213,9 +233,14 @@ const theme = computed(() => { return appStore.theme; }); +let from = reactive({ + name:'鏈懡鍚嶄細璇�', +}); const visible = ref(false); - +let isHistory = ref(false);//鏄惁鏄巻鍙茶褰� +let dsl = reactive({}); +const chatDataMeg = reactive({}); const rules = { @@ -229,12 +254,16 @@ const handleSubmit = async({values, errors}) => { if(errors) return; - agentObj.name = agentTitle.value; - const { code, data } = await addSessionApi(agentObj); + console.log(agentObj, 'agentObj'); + let chatData = { + id:conversation_id.value, + conversation_id:conversation_id.value, + name: from.name + } + const { code, data } = await addSessionApi(chatData); if (data) { Message.success("淇敼鎴愬姛"); handleCancel() - queryAgentSessionDetail(agentObj.id); } } @@ -259,14 +288,11 @@ }; const createNewAgent = async (session) => { + console.log(session,'鏂板缓agent浼氳瘽瀵硅薄'); Object.assign(agentObj, session); + isHistory.value = false; initPage(); - - } - - - // 璋冪敤set鏂规硶 const agentSet = async () => { const res = await agentSetApi({ @@ -274,10 +300,9 @@ title: agentObj.title, dsl: agentObj.dsl, }); - console.log(res,'agentSet'); + // console.log(res,'agentSet'); if (res.code == 0) { - // sessionDetailList.value = res.data.dsl.messages; - // Message.success('淇敼鎴愬姛'); + conversation_id.value = res.data.conversation_id; agentReset(); } } @@ -341,14 +366,33 @@ inputMsg.value = ''; } // 璋冪敤get鏂规硶 - const queryAgentSessionDetail = async (id) => { const { code, data } = await getAgentSessionDetailsApi(id); if (code == 0) { - console.log(data,'浼氳瘽璇︽儏'); + console.log(data,'agent浼氳瘽璇︽儏'); + Object.assign(chatObj, data); sessionDetailList.value = data.dsl.messages; - agentTitle.value = `鍜�${data.title}鐨勪細璇漙 || '鏈懡鍚嶄細璇�'; + agentTitle.value = `${data.title}` || '鏈懡鍚嶄細璇�'; + from.name = `${data.title}` || '鏈懡鍚嶄細璇�'; refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃� + } +}; + +// 鍘嗗彶璁板綍璺宠浆鑾峰彇agent浼氳瘽璇︽儏 +const querySessionDetail = async (session) => { + conversation_id.value = session.id; + from.name = session.name; + const { code, data } = await getSessionDetailsApi(session.id); + if (code == 200) { + sessionDetailList.value = data.message.messages; + const res = await getAgentSessionDetailsApi(session.dialog_id); + if (res.code == 0) { + console.log(res.data,'agent浼氳瘽璇︽儏'); + Object.assign(agentObj, res.data); + Object.assign(chatObj, res.data); + Object.assign(dsl, res.data.dsl); + refreshScroll(); //鍒锋柊婊氬姩鏉′綅缃� + } } }; @@ -404,13 +448,19 @@ const startChat = async(valMsg)=>{ - sessionDetailList.value.push({ content: valMsg, role: 'user', }); sessionDetailList.value.push({ role: 'last' }); refreshScroll(); + let chatStr = { + id: agentObj.id, + message: valMsg, + } + if(isHistory.value){ + chatStr.dsl = dsl; + } const response = await fetch( '/api/v1/canvas/completion', { @@ -419,10 +469,7 @@ 'Authorization': getAuthorization(), 'Content-Type': 'application/json', }, - body: JSON.stringify({ - id: agentObj.id, - message: valMsg, - }), + body: JSON.stringify(chatStr), } ); @@ -450,8 +497,13 @@ if (done) { console.info('done'); displayedText.value = ''; - queryAgentSessionDetail(agentObj.id); - EventBus.emit('queryAppUsageList'); + if (isStopChat.value) { + isStopChat.value = false; + setChatDataMeg(chatDataMeg); + } else { + queryAgentSessionDetail(agentObj.id); + EventBus.emit('queryAppUsageList'); + } break; } } @@ -461,11 +513,12 @@ } const stopChat=async()=>{ - // const { code, data } = await stopChatApi(activeSessionId.value); + // const { code, data } = await stopChatApi(agentObj.id); // if (code === 200) { // Message.success("宸插仠姝�"); - // queryNewSessionDetail(activeSessionId.value); // } + loading.value = false; + chatDis.value = false; isStopChat.value = true; console.log('stopChat'); console.log(displayedText.value, 'displayedText'); @@ -482,20 +535,26 @@ sessionDetailList.value = sessionDetailList.value.splice(0, sessionDetailList.value.length-2).concat(lastArr); console.log(sessionDetailList.value, 'sessionDetailList2'); console.log(chatObj, 'chatObj瀵硅薄'); - chatObj.message = chatObj.message.concat(lastArr); - // clearTimeout(timer!); - // timer = null; - // const { code, data } = await addSessionApi(chatObj); - // if (data) { - // //鍋滄瀹氭椂鍣� - // clearTimeout(timer!); - // timer = null; - // displayedText.value = ""; - // queryNewSessionDetail(activeSessionId.value); - // } - + chatObj.dsl.messages = chatObj.dsl.messages.concat(lastArr); + Object.assign(chatDataMeg, { + id: chatObj.id, + conversation_id: chatObj.id, + message: sessionDetailList.value, + }); } + + +const setChatDataMeg = async (chatData) => { + const { code, data } = await addSessionApi(chatData); + if (data) { + //鍋滄瀹氭椂鍣� + clearTimeout(timer!); + timer = null; + // displayedText.value = ""; + queryAgentSessionDetail(chatObj.id); + } +}; const handleShiftEnter = (event) => { event.preventDefault(); @@ -536,8 +595,8 @@ createNewAgent(data); }); EventBus.on('queryAgentSessionDetail', (data) => { - Object.assign(agentObj, data); - queryAgentSessionDetail(data.id); + isHistory.value = true; + querySessionDetail(data); }); }); onBeforeUnmount(() => { @@ -665,7 +724,7 @@ .btn-send { position: absolute !important; - right: 10px; + right: 4px; top: 80px; z-index: 10; } -- Gitblit v1.8.0