CzRger 3 månader sedan
förälder
incheckning
61b7732715

+ 10 - 2
src/views/smart-ask-answer/assistant/chat.vue

@@ -59,7 +59,7 @@ import audioCom from './component/audio/index.vue'
 import {get, post, ssePost} from './dify/base'
 import {useRouter} from "vue-router";
 import {isValue, YMDHms} from "@/utils/czr-util";
-import {updateFeedback} from "@/views/smart-ask-answer/assistant/dify/share";
+import {fetchSuggestedQuestions, updateFeedback} from "@/views/smart-ask-answer/assistant/dify/share";
 import {staticConQueryQuestionslist} from "@/views/smart-ask-answer/assistant/cms/api";
 
 const emit = defineEmits(['getText'])
@@ -79,6 +79,7 @@ const state: any = reactive({
   goodMap: new Map(),
   badMap: new Map(),
   autoList: [],
+  chatConfig: {}
 })
 const ref_text = ref()
 const ref_chatMsg = ref()
@@ -101,7 +102,8 @@ const onSend = (text = '') => {
     const answer = reactive({
       type: 'answer',
       content: '',
-      messageId: ''
+      messageId: '',
+      suggest: []
     })
     state.chats.push(answer)
     ssePost(`/installed-apps/${window.czrConfig.dify.appId}/chat-messages`, {
@@ -126,6 +128,11 @@ const onSend = (text = '') => {
         answer.messageId = messageEnd.message_id
         state.params.parent_message_id = messageEnd.message_id
         state.loading = false
+        if (state.chatConfig?.suggested_questions_after_answer?.enabled) {
+          fetchSuggestedQuestions(state.params.parent_message_id, true, window.czrConfig.dify.appId).then((res: any) => {
+            answer.suggest = res.data
+          })
+        }
       },
       onMessageReplace: (messageReplace) => {
       },
@@ -159,6 +166,7 @@ const onAudio = (text) => {
 }
 const initChat = () => {
   get(`/installed-apps/${window.czrConfig.dify.appId}/parameters`).then((res: any) => {
+    state.chatConfig = res
     if (res.opening_statement) {
       state.chats = [
         {

+ 22 - 1
src/views/smart-ask-answer/assistant/component/answer/index.vue

@@ -18,7 +18,7 @@
             <thinkCom :content="part.content"/>
           </template>
           <template v-else>
-            <div class="answer-markdown" v-html="md.render(part.content)"/>
+            <div class="answer-markdown" v-html="md.render(part.content.replace(/^<think>/, ''))"/>
             <div class="answer-operation">
               <el-tooltip content="播放" placement="top">
                 <div class="answer-operation-item __hover" @click="speak(part.content)">
@@ -65,6 +65,14 @@
                 </template>
               </template>
             </div>
+            <template v-if="item.suggest?.length > 0">
+              <div class="answer-suggest">
+                相似问题
+                <template v-for="sug in item.suggest">
+                  <div class="__hover" @click="$emit('setText', {text: sug, send: true})">{{sug}}</div>
+                </template>
+              </div>
+            </template>
 <!--            <div class="answer-markdown" v-html="DOMPurify.sanitize(marked.parse(part.content))"/>-->
           </template>
         </template>
@@ -192,5 +200,18 @@ const onCopy = (text) => {
       justify-content: center;
     }
   }
+  .answer-suggest {
+    margin-top: 14px;
+    padding-top: 14px;
+    border-top: 1px solid #D8DAE5;
+    display: flex;
+    flex-direction: column;
+    gap: 2px;
+    font-size: 14px;
+    color: #9A9CA6;
+    >div {
+      color: #1D64FD;
+    }
+  }
 }
 </style>