Browse Source

实现愿生追问模式

songxy 1 tháng trước cách đây
mục cha
commit
2df9cbe767
1 tập tin đã thay đổi với 28 bổ sung94 xóa
  1. 28 94
      ais_search_zj/web/src/views/ai-home/index.vue

+ 28 - 94
ais_search_zj/web/src/views/ai-home/index.vue

@@ -110,10 +110,10 @@
                                                         history.currentResponse.streamMsg.indexOf('###')
                                                       )
                                                     : history.currentResponse.streamMsg
-                                                  : history.currentResponse.msg.indexOf('###') > -1
+                                                  : history.currentResponse.msg.indexOf('</think>') > -1
                                                   ? history.currentResponse.msg.substring(
                                                       0,
-                                                      history.currentResponse.msg.indexOf('###')
+                                                      history.currentResponse.msg.indexOf('</think>')
                                                     )
                                                   : history.currentResponse.msg
                                               "
@@ -136,8 +136,8 @@
                                                 )
                                               : ''
                                             : history.dsChecked
-                                            ? history.currentResponse.msg.indexOf('###') > -1
-                                              ? history.currentResponse.msg.substring(history.currentResponse.msg.indexOf('###'))
+                                            ? history.currentResponse.msg.indexOf('</think>') > -1
+                                              ? history.currentResponse.msg.substring(history.currentResponse.msg.indexOf('</think>'))
                                               : ''
                                             : history.currentResponse.msg
                                         "
@@ -680,7 +680,6 @@ const quest = async (isFllow) => {
     sessionCreate();
     isSessionNew.value = false
   }
-  getQuestionKeyWords();
   if (activeTab.value === 'net') {
     questionUrl = '/chat/bing_chat';
   } else if(activeTab.value === 'knowledge'){
@@ -710,7 +709,7 @@ const quest = async (isFllow) => {
       search_type: answerType.value,
       score_threshold: 0.5,
       model: historys.value[historyIndex].dsChecked ? 'deepseek-r1' : '',
-      history: isFllow ? getFlowHistory() : [],
+      history: [],
       stream: true,
       prompt_name: 'rag_context_qa.md',
       return_direct: false
@@ -718,20 +717,32 @@ const quest = async (isFllow) => {
   } else if (activeTab.value === 'original') {
     body = {
       query: question.value,
-      history: isFllow ? getFlowHistory() : [],
+      history: [],
       stream: true
     }
   }
-  if (activeTab.value === 'knowledge' && isFllow) {
-    if (questHistories.value.length > 0) {
-      body.history_keyword = questHistories.value[questHistories.value.length - 1].keywords;
-      const arrs = historys.value.map((history) => {
-        return {
-            "role": "user",
-            "content": history.question
-          }
-      })
-      body.history = arrs
+  if (isFllow) {
+    if (activeTab.value === 'knowledge') {
+      if (questHistories.value.length > 0) {
+        body.history_keyword = questHistories.value[questHistories.value.length - 1].keywords;
+        const arrs = historys.value.map((history) => {
+          return {
+              "role": "user",
+              "content": history.question
+            }
+        })
+        body.history = arrs
+      }
+    } else if (activeTab.value === 'original') {
+      for (let i = 0; i < historys.value.length; i++){
+        const history = historys.value[i]
+        if (history && history['currentResponse'] && history['currentResponse']['msg']) {
+          body.history.push([
+            history['currentResponse']['question'],
+            history['currentResponse']['msg'].substring(history['currentResponse']['msg'].indexOf('</think>')+8)
+          ])
+        }
+      }
     }
   }
   if (activeTab.value !== 'net' && answerType.value !== '0') {
@@ -777,16 +788,6 @@ const quest = async (isFllow) => {
   });
 };
 
-const getFlowHistory = () => {
-  const lastHistory = [...questHistories.value].splice(-1);
-  const parm = [];
-  lastHistory.forEach((item) => {
-    parm.push({ role: 'user', content: item.question });
-  });
-
-  return parm;
-};
-
 const handleKnowledgeResponse = (msg, id) => {
   if (!msg || !msg.data) {
     return;
@@ -1186,73 +1187,6 @@ const collectQuestion = () => {
   });
 };
 
-const questions = ref([]);
-
-const getQuestionKeyWords = async () => {
-  return;
-  const { question } = historys.value[historyIndex].currentResponse;
-  const myHeaders = new Headers();
-  myHeaders.append('Content-Type', 'application/json');
-  questions.value = [];
-  const raw = JSON.stringify({
-    query: `请从以下文本中提取核心关键词,确保关键词简洁明了且准确反映文本的主要内容。 请按照以下格式输出:关键词:关键词1,关键词2。文本如下:“${question}”`,
-    stream: false
-  });
-
-  const requestOptions = {
-    method: 'POST',
-    headers: myHeaders,
-    body: raw,
-    redirect: 'follow'
-  };
-
-  const rootUrl = modelType.value === '1' ? window.AppGlobalConfig.aisChat : window.AppGlobalConfig.aiServer
-  return fetch(rootUrl + '/chat/chat', requestOptions)
-    .then((response) => response.json())
-    .then((msgStr) => {
-      const msg = JSON.parse(msgStr)
-      activeIndex.value = 1;
-      const str = msg.choices[0]?.message?.content;
-      if (str) {
-        const str1 = str.slice(str.indexOf("</think>")+7)
-        const keywords = splitWords(str1).slice(0, 3);
-        historys.value[historyIndex].currentResponse.keywords = keywords;
-      }
-    })
-    .catch((error) => console.error(error));
-};
-
-const splitWords = (word) => {
-  if (word) {
-    word = word
-      .replaceAll('核心词为:', '')
-      .replaceAll('问题核心词:', '')
-      .replaceAll('>', '')
-      .replaceAll('。', '')
-      .trim();
-
-    if (word.indexOf('\n\n') !== -1) {
-      return word.split('\n\n');
-    }
-
-    if (word.indexOf(',') !== -1) {
-      return word.split(',');
-    }
-
-    if (word.indexOf('、') !== -1) {
-      return word.split('、');
-    }
-
-    if (word.indexOf(',') !== -1) {
-      return word.split(',');
-    }
-
-    return [word];
-  }
-
-  return [];
-};
-
 const stopAI = () => {
   if (ctr) {
     ctr.abort();