فهرست منبع

换一批功能修改

songxy 3 ماه پیش
والد
کامیت
85a34e3cf1
1فایلهای تغییر یافته به همراه22 افزوده شده و 5 حذف شده
  1. 22 5
      ais_search_zj/web/src/views/ai-search/ai-search.vue

+ 22 - 5
ais_search_zj/web/src/views/ai-search/ai-search.vue

@@ -1579,20 +1579,37 @@ for example:
 
   fetch(window.AppGlobalConfig.knowledgeServer + '/chat/chat', requestOptions)
     .then((response) => {
-      console.log(response)
       return response.json()
     })
-    .then((msg) => {
+    .then((msgStr) => {
+      const msg = JSON.parse(msgStr)
       const str = msg.choices[0]?.message?.content;
-      console.log(str)
       if (str) {
-        recommendedQuestions = JSON.parse(str);
+        const str1 = str.slice(str.indexOf("</think>") + 7)
+        recommendedQuestions = formatRecommendedQuestions(str1);
         questions.value = recommendedQuestions.slice(0, 5);
       }
     })
     .catch((error) => console.error(error));
 };
-
+const formatRecommendedQuestions = (str) => {
+  return str
+    .replace(/`|$$|$$|"|,/g, '')  // 清除引号、反引号、方括号和逗号
+    .split('\n')                  // 按换行分割
+    .map(line => line.trim())     // 去除首尾空格
+    .filter(line => {             // 双条件过滤
+      return (
+        line.length > 0 &&         // 过滤空行
+        /^\d+[、.]/.test(line)     // 匹配"1、"或"1."开头
+      )
+    })
+    .map(line => {
+      // 统一标点为中文顿号并保留末尾空格
+      return line
+        .replace(/^\d+\./, m => m.replace('.', '、')) // 英文标点转中文
+        .replace(/\s*$/, '   ')                       // 强制保留末尾3空格
+    });
+}
 const changeRecommendedQuestions = () => {
   recommendedQuestionsIndex++;
   if (recommendedQuestionsIndex % 2 === 0) {