| | |
| | | <div class="header___section"> |
| | | <div class="chatHeader"> |
| | | <div class="chatHeaderBox"> |
| | | <!-- <span class="title">{{agentTitle}}</span>--> |
| | | <a-popover position="bottom" trigger="click"> |
| | | <a-button border> |
| | | <span |
| | |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <a-scrollbar |
| | | <div |
| | | ref="scrollbar" |
| | | id="agentHome" |
| | | id="chatAgentHome" |
| | | class="chat-list" |
| | | style=" |
| | | width: 80%; |
| | |
| | | <div :class="{ chartUserText: theme === 'light' }" |
| | | >{{ sessionDetail.content }} |
| | | </div> |
| | | |
| | | <!-- <div class="uploadFileList fileList"> |
| | | <a-comment |
| | | content="232323" |
| | | style=" |
| | | background: var(--color-bg-2); |
| | | padding: 10px; |
| | | border-radius: 10px; |
| | | font-size: 12px; |
| | | " |
| | | > |
| | | <template #avatar> |
| | | <img :src="getIconByExtension('wps')" alt="" /> |
| | | </template> |
| | | </a-comment> |
| | | </div> --> |
| | | </template> |
| | | </a-comment> |
| | | <a-comment v-else-if="sessionDetail?.role === 'assistant'"> |
| | |
| | | /> |
| | | </template> |
| | | <template #content> |
| | | <!-- <a-card :class="{ chatItemAnswer: theme === 'light' }">--> |
| | | <!-- <div :class="{ light: theme === 'light' }"--> |
| | | <!-- >{{ sessionDetail.content }}--> |
| | | <!-- </div>--> |
| | | <!-- </a-card>--> |
| | | <a-textarea |
| | | v-if="sessionDetail?.content" |
| | | readonly |
| | | auto-size |
| | | v-model="sessionDetail.content" |
| | | :class="{ chatItemAnswer: theme === 'light' }" |
| | | :style="{ |
| | | backgroundColor: theme === 'light' ? '#ffffff' : '#000000', |
| | | }" |
| | | style="border: none" |
| | | > |
| | | </a-textarea> |
| | | <div v-else> |
| | | <!-- <a-textarea |
| | | readonly |
| | | auto-size |
| | | :default-value="chartText(sessionDetail.code, sessionDetail.sql)" |
| | | :class="{ chatItemAnswer: theme === 'light' }" |
| | | :style="{ |
| | | backgroundColor: theme === 'light' ? '#ffffff' : '#000000', |
| | | }" |
| | | style="border: none" |
| | | > |
| | | </a-textarea> --> |
| | | <!-- <codemirror |
| | | v-model="sessionDetail.code" |
| | | placeholder="Code gose here..." |
| | | :style="{ height: '100%' }" |
| | | :autofocus="true" |
| | | :tabSize="2" |
| | | /> --> |
| | | <div class="codeStle"> |
| | | <div class="language">python</div> |
| | | <pre |
| | | style="background: #2c2c36; padding: 10px; margin-top: 0" |
| | | ><code class="language-js line-numbers">{{ sessionDetail.code+ sessionDetail.sql}}</code></pre> |
| | | <div v-if="isExistTip(sessionDetail.content)" :class="{ chartUserText: theme === 'light' }"> |
| | | <div v-for="(item, breakIndex) in breakLine(sessionDetail)"> |
| | | <span v-if="item.preIndex==0"> |
| | | {{ sessionDetail.content.substring(0, item.index) }} |
| | | </span> |
| | | <span v-else> |
| | | {{ sessionDetail.content.substring(item.preIndex+item.preItem.length, item.index) }} |
| | | </span> |
| | | <div class="codeStle"> |
| | | <div class="language">{{ item.item }}</div> |
| | | <pre |
| | | style=" |
| | | background: #2c2c36; |
| | | padding: 10px; |
| | | margin-top: 0; |
| | | margin-bottom: 0; |
| | | " |
| | | ><code class="language-js line-numbers">{{ item?.tip_content }}</code></pre> |
| | | </div> |
| | | </div> |
| | | |
| | | </div> |
| | | <div v-else :class="{ chartUserText: theme === 'light' }">{{ sessionDetail.content }}</div> |
| | | <div> |
| | | <a-image |
| | | v-if="sessionDetail?.image_name" |
| | | :src="getImg(sessionDetail)" |
| | | alt="" |
| | | /> |
| | | <div class="uploadFileList fileList"> |
| | | <div |
| | | class="uploadFileList fileList" |
| | | v-if="sessionDetail?.excel_name" |
| | | > |
| | | <a-comment |
| | | :content="sessionDetail.excel_name" |
| | | style=" |
| | |
| | | >停止生成</div |
| | | > |
| | | <div class="chartStart v-else" @click="stopChat">重新生成</div> --> |
| | | </a-scrollbar> |
| | | </div> |
| | | <div class="chat_bottom"> |
| | | <div class="center-bottom"> |
| | | <a-textarea |
| | |
| | | ></updataFile> --> |
| | | <span v-if="getAent"></span> |
| | | <uploadFile |
| | | v-if="agentObj.id == 'excel_talk' || dialog_id == 'excel_talk'" |
| | | v-if="!getAent" |
| | | ref="fileInput" |
| | | :sessionId="activeSessionId" |
| | | :handleRemove="handleRemove" |
| | | :typeXLse="false" |
| | | @selectFileCallback="selectFileCallback" |
| | | ></uploadFile> |
| | | <a-button |
| | |
| | | > |
| | | <template #avatar> |
| | | <a-spin |
| | | :loading="onFileSelectedLoading" |
| | | v-if="onFileSelectedLoading" |
| | | :loading="item.onFileSelectedLoading" |
| | | v-if="item.onFileSelectedLoading" |
| | | > |
| | | <template #icon> |
| | | <icon-sync /> |
| | | </template> |
| | | <template #tip> |
| | | <div style="font-size: 12px">{{ textName }}</div> |
| | | <div style="font-size: 12px">{{ item.textName }}</div> |
| | | </template> |
| | | </a-spin> |
| | | <!-- <a-button type="text" :loading="onFileSelectedLoading" v-if="onFileSelectedLoading"></a-button>--> |
| | |
| | | <!-- <icon-file style="color: #0960bd" />--> |
| | | <!-- </a-avatar>--> |
| | | <img :src="getIconByExtension(item.name)" alt="" /> |
| | | <div v-show="!item.onFileSelectedLoading" style="font-size: 12px">{{ |
| | | item.textName |
| | | }}</div> |
| | | </template> |
| | | </a-comment> |
| | | <icon-close-circle-fill |
| | |
| | | agentConversationSetApi, |
| | | agentConverDownloadApi, |
| | | downloadFile, |
| | | agentUploadApi, |
| | | } from '@/api/agentSession'; |
| | | agentUploadApi, updateAgentConversation, updateSeniorAgentConversation |
| | | } from "@/api/agentSession"; |
| | | import EventBus from '@/utils/EventBus'; |
| | | import useClipboard from 'vue-clipboard3'; |
| | | import { addSessionApi, getSessionDetailsApi } from '@/api/session'; |
| | |
| | | ], |
| | | }; |
| | | |
| | | const isExistTip = (message: string): boolean => { |
| | | if (/\$([a-z]+)\$/g.test(message)) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | }; |
| | | |
| | | const breakLine = (detail): string[] => { |
| | | let indexs: any[] = []; |
| | | let tip_content: any; |
| | | let preTip = 0; |
| | | let preItem=""; |
| | | let matches = detail.content.match(/\$([a-z]+)\$/g); |
| | | matches?.map((item) => { |
| | | let i = detail.content.indexOf(item); |
| | | if (item == "$metadata$") { |
| | | tip_content = detail.metadata; |
| | | } |
| | | if (item == "$sql$") { |
| | | tip_content = detail.sql; |
| | | } |
| | | if (item == "$code$") { |
| | | tip_content = detail.code; |
| | | } |
| | | indexs.push({ |
| | | index: i, |
| | | item: item, |
| | | preIndex: preTip, |
| | | preItem: preItem, |
| | | tip_content: tip_content, |
| | | len: matches.length |
| | | }); |
| | | preTip = i; |
| | | preItem = item; |
| | | }); |
| | | return indexs; |
| | | }; |
| | | |
| | | const handleSubmit = async ({ values, errors }) => { |
| | | if (errors) return; |
| | | |
| | |
| | | |
| | | prompts.value = session.prompts; |
| | | activeSessionId.value = ''; |
| | | EventBus.emit('queryAgent', uploaditemList.value); |
| | | uploaditemList.value = []; |
| | | console.log(12123); |
| | | getAentId(session.id); |
| | |
| | | isHistory.value = false; |
| | | initPage(); |
| | | }; |
| | | // 调用set方法 |
| | | const agentSet = async () => { |
| | | const res = await agentSetApi({ |
| | | id: agentObj.id, |
| | | title: agentObj.title, |
| | | dsl: agentObj.dsl, |
| | | }); |
| | | // console.log(res,'agentSet'); |
| | | if (res.code == 0) { |
| | | conversation_id.value = res.data.conversation_id; |
| | | agentReset(); |
| | | } |
| | | }; |
| | | // 调用reset方法 |
| | | const agentReset = async () => { |
| | | const res = await agentResetApi({ |
| | | id: agentObj.id, |
| | | }); |
| | | if (res.code == 0) { |
| | | // Message.success('修改成功'); |
| | | agentCompletion(); |
| | | } |
| | | }; |
| | | // 调用completion方法 |
| | | const agentCompletion = async () => { |
| | | const response = await fetch('/api/v1/canvas/completion', { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Authorization': getAuthorization(), |
| | | 'Content-Type': 'application/json', |
| | | }, |
| | | body: JSON.stringify({ |
| | | id: agentObj.id, |
| | | }), |
| | | }); |
| | | refreshScroll(); |
| | | |
| | | const reader = response?.body |
| | | ?.pipeThrough(new TextDecoderStream()) |
| | | .pipeThrough(new EventSourceParserStream()) |
| | | .getReader(); |
| | | currIndex.value = 0; |
| | | while (true) { |
| | | const x = await reader?.read(); |
| | | if (x) { |
| | | const { done, value } = x; |
| | | |
| | | try { |
| | | const val = JSON.parse(value?.data || ''); |
| | | const d = val?.data; |
| | | if (typeof d !== 'boolean') { |
| | | console.info('data:', d); |
| | | if (d?.content) { |
| | | streamStr.value = d.content; |
| | | } else { |
| | | streamStr.value = d.code + d.sql; |
| | | } |
| | | startDisplayStr(); |
| | | } |
| | | } catch (e) { |
| | | console.warn(e); |
| | | } |
| | | if (done) { |
| | | console.info('done'); |
| | | displayedText.value = ''; |
| | | // queryAgentSessionDetail(activeSessionId.value); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | chatDis.value = false; |
| | | loading.value = false; |
| | | inputMsg.value = ''; |
| | | }; |
| | | |
| | | //渲染文字 |
| | | const chartText = (val, sql) => { |
| | | console.log(val + sql, 77); |
| | | return val + '\n' + sql; |
| | | }; |
| | | |
| | | //获取图片地址 |
| | | const getImg = (val) => { |
| | |
| | | |
| | | const getAentId = (id) => { |
| | | if (id == 'excel_talk') { |
| | | console.log(1); |
| | | getAent.value = false; |
| | | } |
| | | if (id == 'questions_talk') { |
| | | console.log(2); |
| | | getAent.value = true; |
| | | } |
| | | }; |
| | |
| | | conversation_id.value = session.id; |
| | | activeSessionId.value = session.id; |
| | | dialog_id.value = session.dialog_id; |
| | | |
| | | EventBus.emit('queryAgent', uploaditemList.value); |
| | | uploaditemList.value = []; |
| | | |
| | | getAentId(session.dialog_id); |
| | | from.name = session.name; |
| | | const { code, data } = await getSessionDetailsApi(session.id); |
| | | |
| | | if (code == 200) { |
| | | sessionDetailList.value = data.message; |
| | | refreshScroll(); //刷新滚动条位置 |
| | | // const res = await getAgentSessionDetailsApi(session.dialog_id); |
| | | // if (res.code == 0) { |
| | | // Object.assign(agentObj, res.data); |
| | | // Object.assign(chatObj, res.data); |
| | | // Object.assign(dsl, res.data.dsl); |
| | | // refreshScroll(); //刷新滚动条位置 |
| | | // } |
| | | } |
| | | queryAgentSessionDetails(activeSessionId.value); |
| | | }; |
| | | |
| | | const { toClipboard } = useClipboard(); |
| | |
| | | |
| | | const sentClick = () => { |
| | | sendMessage('click'); |
| | | |
| | | uploaditemList.value = []; |
| | | }; |
| | | |
| | |
| | | event.preventDefault(); // 阻止默认行为,即不换行 |
| | | } |
| | | |
| | | // chatDis.value = true; |
| | | // loading.value = true; |
| | | // if (!agentObj.id) { |
| | | // Message.warning('请选择会话'); |
| | | // chatDis.value = false; |
| | | // loading.value = false; |
| | | // return; |
| | | // } |
| | | |
| | | // if (displayedText.value) { |
| | | // querySessionList(); |
| | | // } |
| | | |
| | | if (inputMsg.value) { |
| | | // const res = await addSessionApi({ |
| | | // dialog_id: '', |
| | | // conversation_desc: inputMsg.value, |
| | | // }); |
| | | // // console.log(res, "res"); |
| | | // if (res.code == 200) { |
| | | // // console.log(res.data.conversation_id); |
| | | // activeSessionId.value = res.data?.conversation_id; |
| | | // const { code, data } = await getSessionDetailsApi( |
| | | // res.data?.conversation_id |
| | | // ); |
| | | // if (code === 200) { |
| | | // console.log(data, '新建会话详情'); |
| | | // Object.assign(chatObj, data); |
| | | // startChat(inputMsg.value); |
| | | // inputMsg.value = ''; |
| | | // } |
| | | // } else { |
| | | // Message.error('创建会话失败,请重试'); |
| | | // } |
| | | |
| | | // startChat(inputMsg.value); |
| | | // inputMsg.value = ''; |
| | | createSession(''); |
| | | uploaditemList.value = []; |
| | | } else { |
| | | Message.warning('消息不能为空'); |
| | | chatDis.value = false; |
| | |
| | | try { |
| | | loading.value = true; |
| | | chatDis.value = true; |
| | | let name = inputMsg.value; |
| | | |
| | | if (val) { |
| | | name = val[0].name.split('.')[0]; |
| | | } |
| | | |
| | | if (!activeSessionId.value) { |
| | | let message = [ |
| | |
| | | const res = await agentConversationSetApi({ |
| | | id: '', |
| | | app_id: agentObj.id, |
| | | name: inputMsg.value, |
| | | name: name, |
| | | message: message, |
| | | }); |
| | | // console.log(res, "res"); |
| | |
| | | if (!val) { |
| | | startChat(inputMsg.value); |
| | | inputMsg.value = ''; |
| | | uploaditemList.value = []; |
| | | } else { |
| | | loading.value = false; |
| | | chatDis.value = false; |
| | |
| | | try { |
| | | const formData = new FormData(); |
| | | uploaditemList.value = resData; |
| | | uploaditemList.value.map((item) => { |
| | | if (item.name == file[0].file.name) { |
| | | item.onFileSelectedLoading = true; |
| | | item.textName = '上传中'; |
| | | } |
| | | return item; |
| | | }); |
| | | if (!activeSessionId.value) { |
| | | await createSession(1); |
| | | await createSession(resData); |
| | | } |
| | | |
| | | onFileSelectedLoading.value = true; |
| | | textName.value = '上传中'; |
| | | // for (let i = 0; i < file.length; i++) { |
| | | // formData.append('files', file[i].file); |
| | | // formData.append('conversation_id', activeSessionId.value); |
| | | // formData.append('app_id', agentObj.id); |
| | | // } |
| | | // onFileSelectedLoading.value = true; |
| | | // textName.value = '上传中'; |
| | | |
| | | formData.append('files', file[0].file); |
| | | formData.append('conversation_id', activeSessionId.value); |
| | | formData.append('app_id', agentObj.id); |
| | | console.log(formData, 'formData'); |
| | | const { data, code } = await agentUploadApi(formData); |
| | | if (code === 200) { |
| | | onFileSelectedLoading.value = false; |
| | | textName.value = '上传成功'; |
| | | uploaditemList.value.map((item) => { |
| | | item.onFileSelectedLoading = false; |
| | | item.textName = '上传成功'; |
| | | return item; |
| | | }); |
| | | // onFileSelectedLoading.value = false; |
| | | // textName.value = '上传成功'; |
| | | } |
| | | } catch (err) { |
| | | onFileSelectedLoading.value = false; |
| | | textName.value = '上传失败'; |
| | | uploaditemList.value.map((item) => { |
| | | item.onFileSelectedLoading = false; |
| | | item.textName = '上传失败'; |
| | | return item; |
| | | }); |
| | | // onFileSelectedLoading.value = false; |
| | | // textName.value = '上传失败'; |
| | | Message.error('上传失败'); |
| | | } |
| | | }; |
| | |
| | | return type; |
| | | }; |
| | | |
| | | let onFileSelectedLoading = ref(true); |
| | | const textName = ref('上传成功'); |
| | | // let onFileSelectedLoading = ref(true); |
| | | // const textName = ref('上传成功'); |
| | | |
| | | const deleteFile = (item) => { |
| | | console.log(uploaditemList.value); |
| | | uploaditemList.value.splice(item.index, 1); |
| | | EventBus.emit('queryAgent', item); |
| | | }; |
| | | |
| | | const getIconByExtension = computed(() => (extension) => { |
| | | const fileExtension = ref(''); |
| | | fileExtension.value = extension.split('.').pop(); |
| | |
| | | .pipeThrough(new EventSourceParserStream()) |
| | | .getReader(); |
| | | currIndex.value = 0; |
| | | let end_msg={}; |
| | | while (true) { |
| | | const x = await reader?.read(); |
| | | if (x) { |
| | | const { done, value } = x; |
| | | // console.log(x, 999); |
| | | |
| | | console.log(x, 999); |
| | | loading.value = false; |
| | | if (value && value?.event == 'message') { |
| | | try { |
| | | const val = JSON.parse(value?.data || ''); |
| | | const d = val?.data; |
| | | const d = val?.data; |
| | | |
| | | if (typeof d !== 'boolean') { |
| | | console.info('data:', d); |
| | | |
| | | if (d?.content) { |
| | | streamStr.value = d.content; |
| | | } else { |
| | | streamStr.value = d.code; |
| | | let msg = d.content; |
| | | //将d.output中$metadata$替换为d.metadata |
| | | msg = msg.replace('$metadata$', d.metadata); |
| | | //d.content中存在$sql$ |
| | | if (d.content.includes('$sql$')) { |
| | | msg = msg.replace('$sql$', d.sql); |
| | | } |
| | | //d.content中存在$code$ |
| | | if (d.content.includes('$code$')) { |
| | | msg = msg.replace('$code$', d.code); |
| | | } |
| | | end_msg=d; |
| | | streamStr.value = msg; |
| | | } |
| | | |
| | | EventBus.emit('queryAgent', uploaditemList.value); |
| | | startDisplayStr(); |
| | | } |
| | | } catch (e) { |
| | |
| | | |
| | | if (done) { |
| | | console.info('done'); |
| | | // displayedText.value = ''; |
| | | if (isStopChat.value) { |
| | | isStopChat.value = false; |
| | | setChatDataMeg(chatDataMeg); |
| | | } else { |
| | | // queryAgentSessionDetail(activeSessionId.value); |
| | | // EventBus.emit('queryAppUsageList'); |
| | | if (!chatObj?.message) { |
| | | chatObj.message = []; |
| | | } |
| | | chatObj.message.push(end_msg) ; |
| | | await updateSeniorAgentConversation({ |
| | | converson_id: activeSessionId.value, |
| | | message: chatObj.message |
| | | }); |
| | | setChatDataMeg(chatDataMeg); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | chatDis.value = false; |
| | | loading.value = false; |
| | | }; |
| | | |
| | | const stopChat = async () => { |
| | |
| | | |
| | | if (currIndex.value < res.length) { |
| | | displayedText.value += res[currIndex.value]; |
| | | |
| | | currIndex.value++; |
| | | setTimeout(startDisplayStr, 100); |
| | | setTimeout(startDisplayStr, 50); |
| | | refreshScroll(); |
| | | } else { |
| | | displayedText.value = ''; |
| | | queryAgentSessionDetails(activeSessionId.value); |
| | | clearTimeout(timer!); |
| | | timer = null; |
| | | } |
| | |
| | | const scrollbar = ref(null); |
| | | const refreshScroll = () => { |
| | | nextTick(() => { |
| | | const container = document.getElementById('agentHome'); |
| | | scrollbar.value.scrollTop(container.scrollHeight); |
| | | const container = document.getElementById('chatAgentHome'); |
| | | //滚动到scrollbar底端 |
| | | if (container) { |
| | | container.scrollTop = container.scrollHeight; |
| | | } |
| | | |
| | | scrollbar.scrollTop(container.scrollHeight); |
| | | }); |
| | | }; |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | :deep(.arco-spin-loading .arco-spin-mask-icon) { |
| | | left: 10%; |
| | | } |
| | | } |
| | | } |
| | | .header___section { |