Selaa lähdekoodia

实现换一批功能

songxy 3 kuukautta sitten
vanhempi
commit
df082e1cc8

+ 23 - 10
ais_search_zj/web/src/views/ai-search/ai-search.vue

@@ -1553,9 +1553,7 @@ const getRecommendedQuestion = async (b = false) => {
   }
   recommendedQuestionsIndex = 0;
   const raw = JSON.stringify({
-    messages: [
-      {
-        content: `你会收到一个用户提问,请根据问题延伸出10个子问题。
+    query: `你会收到一个用户提问,请根据问题延伸出10个子问题。
 
 在你回答问题的时候,还需要注意推荐给用户的问题必须以列表的形式返回。
 for example:
@@ -1568,11 +1566,7 @@ for example:
 ]
 
 以下是用户提问:${question}`,
-        role: 'user'
-      }
-    ],
     // model: 'qwen1.5-chat',
-    model: 'qwen2.5-instruct',
     stream: false
   });
 
@@ -1587,16 +1581,35 @@ for example:
     .then((response) => {
       return response.json()
     })
-    .then((msg) => {
+    .then((msgStr) => {
+      const msg = JSON.parse(msgStr)
       const str = msg.choices[0]?.message?.content;
       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) {

+ 1 - 0
ais_search_zj/web/src/views/zcdb/smartComparison.vue

@@ -136,6 +136,7 @@ const handleChange = (info, type) => {
       id: id,
       f_title: name,
       f_type: 'temp',
+      file: info.file.originFileObj,
       size: info.file.size,
       fileName: fileName,
       url: url