Forráskód Böngészése

历史记录后台接口对接

songxy 2 hónapja
szülő
commit
b2d36fc724

+ 4 - 0
ais_search_zj/web/src/api/manager.js

@@ -1,6 +1,10 @@
 import http from "@/utils/http";
 
 export default {
+  create: async (data) => await http.post('/ai/chat/create', { ...data }, false),
+  list: async (creator, times) => await http.get(encodeURI(`/ai/chat/list?creator=${creator}&createTime[0]=${times[0]}&createTime[1]=${times[1]}`), null, false),
+  delete: async (data) => await http.get('/ai/chat/delete', { ...data }, false),
+  getQuestionList: async (data) => await http.get('/ai/question/getList-by-chatId', { ...data }, false),
   // 问题采集
   collect: async (data) => await http.post('/ai/question/collect', { ...data }, false),
   // 上报埋点必须要使用此方法来做同步请求,axios 异步请求无法发送

+ 1 - 0
ais_search_zj/web/src/views/ai-home/index.scss

@@ -59,6 +59,7 @@
                       font-size: 15px;
                       color: #222222;
                       padding: 8px 0px;
+                      cursor: pointer;
                     }
                   }
                 }

+ 92 - 37
ais_search_zj/web/src/views/ai-home/index.vue

@@ -18,30 +18,14 @@
               </div>
               <div class="history_box" v-show="visibleMap['history']">
                 <ul>
-                  <li>
-                    <span class="title">今天</span>
-                    <ul>
-                      <li>什么是闲置土地</li>
-                      <li>什么是闲置土地</li>
-                      <li>什么是闲置土地</li>
-                    </ul>
-                  </li>
-                  <li>
-                    <span class="title">昨天</span>
-                    <ul>
-                      <li>什么是闲置土地</li>
-                      <li>什么是闲置土地</li>
-                      <li>什么是闲置土地</li>
-                    </ul>
-                  </li>
-                  <li>
-                    <span class="title">30天内</span>
-                    <ul>
-                      <li>什么是闲置土地</li>
-                      <li>什么是闲置土地</li>
-                      <li>什么是闲置土地</li>
-                    </ul>
-                  </li>
+                  <template  v-for="(session, index) in sessionLists">
+                    <li :key="index" v-if="session['datas'].length > 0">
+                      <span class="title">{{session['title']}}</span>
+                      <ul>
+                        <li v-for="(item, cindex) in session['datas']" :key="cindex" @click="switchSession(item)">{{item['tittle']}}</li>
+                      </ul>
+                    </li>
+                  </template>
                 </ul>
               </div>
             </div>
@@ -383,6 +367,7 @@ import {
   UpOutlined,
   DownOutlined
 } from "@ant-design/icons-vue";
+import dayjs from 'dayjs';
 import { fetchEventSource } from '@microsoft/fetch-event-source';
 import PDFViewer from '@/components/pdf/PdfCanvas.vue';
 import WordViewer from '@/components/pdf/WordViewer.vue';
@@ -396,7 +381,7 @@ import { useUserStore } from '@/stores';
 import DraggableSplitter from "./components/DraggableSplitter.vue";
 
 let ctr = null;
-
+const userStore = useUserStore();
 const visibleMap = reactive({
   history: true,
   tool: true
@@ -415,10 +400,12 @@ const historys = ref([])
 let historyIndex = -1;
 const cQuestion = ref('')
 
+const isSessionNew = ref(true)
 const startNewSessionHandle = () => {
   cQuestion.value = ''
   historys.value = []
   historyIndex = -1
+  isSessionNew.value = true
 }
 
 const onKeydownHandle = (e) => {
@@ -657,6 +644,7 @@ const quest = async (isFllow) => {
   const id = questHistories.value.length;
   historys.value[historyIndex].currentResponse = {
     loading: true,
+    time: 0,
     hintTxt: '',
     question: question.value,
     id,
@@ -667,6 +655,10 @@ const quest = async (isFllow) => {
     docs: []
   };
   activeIndex.value = 0;
+  if (isSessionNew.value) {
+    sessionCreate();
+    isSessionNew.value = false
+  }
   getQuestionKeyWords();
   if (activeTab.value === 'net') {
     questionUrl = '/chat/bing_chat';
@@ -786,6 +778,7 @@ const handleKnowledgeResponse = (msg, id) => {
         endTime.value = Date.now();
         var time = ((endTime.value - startTime.value) / 1000).toFixed(0);
         historys.value[historyIndex].currentResponse.hintTxt = `已深度思考(用时 ${time} 秒)`;
+        historys.value[historyIndex].currentResponse.time = time;
         historys.value[historyIndex].currentResponse.loading = false;
         aiLoading.value=true;
         historys.value[historyIndex].currentResponse.originAnswer = rData.choices[0]?.delta?.content.replaceAll(
@@ -1041,17 +1034,87 @@ const getNum = (str) => {
   }
 };
 
+const sessionId = ref('');
+const sessionCreate = () => {
+  const sendData = {
+    tittle: historys.value[historyIndex].currentResponse.question,
+    creator: userStore.user.syUser.Id
+  }
+  ManagerAPI.create(sendData).then((res) => {
+    if (res.data) {
+      sessionId.value = res.data
+    }
+  });
+}
+const sessionLists = reactive([
+  {
+    title: '今天',
+    times: [
+      dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
+      dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss')
+    ],
+    datas: []
+  },
+  {
+    title: '昨天',
+    times: [
+      dayjs().subtract(1, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss'),
+      dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD HH:mm:ss')
+    ],
+    datas: []
+  },
+  {
+    title: '30天内',
+    times: [
+      dayjs().subtract(30, 'day').startOf('day').format('YYYY-MM-DD HH:mm:ss'),
+      dayjs().subtract(2, 'day').endOf('day').format('YYYY-MM-DD HH:mm:ss')
+    ],
+    datas: []
+  }
+])
+const sessionList = async (times) => {
+  const res = await ManagerAPI.list(userStore.user.syUser.Id, times);
+  return res.data
+}
+sessionLists.forEach(async (session) => {
+  session['datas'] = await sessionList(session['times'])
+})
+const getQuestionList = async (chatId) => {
+  const res = await ManagerAPI.getQuestionList({
+    chatId
+  });
+  return res.data
+}
+const switchSession = async (item) => {
+  const results = await getQuestionList(item['id'])
+  historys.value = []
+  results.forEach((item) => {
+    historys.value.push({
+      question: item['question'],
+      dsChecked: true,
+      sourceVisible: false,
+      currentResponse: {
+        loading: false,
+        hintTxt: `已深度思考(用时 ${item['thinkTime']} 秒)`,
+        msg: item['answer'],
+        docs: item['answerSources'] || []
+      }
+    })
+    historyIndex = results.length - 1;
+  })
+}
 // 埋点采集数据
 const collectQuestion = () => {
-  const { question, originAnswer, keywords = [] } = historys.value[historyIndex].currentResponse;
-  const userStore = useUserStore();
+  const { question, originAnswer, docs, time, keywords = [] } = historys.value[historyIndex].currentResponse;
   const param = {
     question,
     answer: originAnswer,
+    answerSources: docs,
+    thinkTime: time,
     questionType: askType.value === 'zcfg' ? '政策法规' : '土地市场',
     keywords: Array.isArray(keywords) ? keywords.join(',') : keywords,
-    user: '游客',
-    userId: '-1'
+    creator: userStore.user.syUser.Id,
+    chatId: sessionId.value
   };
   if (userStore.isLogin) {
     const { id = '-1', displayName = '游客' } = userStore?.user?.user || {};
@@ -1133,20 +1196,12 @@ const splitWords = (word) => {
   return [];
 };
 
-
-const changeActiveTab = (tab) => {
-  activeTab.value = tab;
-};
-
 const stopAI = () => {
   if (ctr) {
     ctr.abort();
   }
 };
 
-
-defineExpose({ changeActiveTab, stopAI });
-
 </script>
 
 <style lang="scss" scoped>