Browse Source

feat: 修复二次回复预设问题请求失败bug

zhouyuhao 6 months ago
parent
commit
8bc008fda6
1 changed files with 14 additions and 5 deletions
  1. 14 5
      src/views/AIRobotChat/src/AIRobotChat.vue

+ 14 - 5
src/views/AIRobotChat/src/AIRobotChat.vue

@@ -20,7 +20,6 @@ const md = new MarkdownIt({
 })
 
 const renderedMessage = (content) => {
-  // console.log('content', content)
   if (!content) {
     return ''
   }
@@ -124,14 +123,20 @@ const serial_no = ref()
 const is_FixedAnswer = ref(true) // 是否为预设问题 true是自由问题 false是预设问题
 const aiChat = (question, isPresetQuestion) => {
   serial_no.value = userStore.userInfo?.uname + Date.now().toString()
+  let fixed_faq = ''
+  if (!is_FixedAnswer.value) {
+    fixed_faq = messages.value[messages.value.length - 2].content
+  } else if (isPresetQuestion) {
+    fixed_faq = question
+  }
   $api
     .aiChat({
       serial_no: serial_no.value,
       prompt: sessionStorage.getItem('prompt'),
-      question_type: isPresetQuestion || !is_FixedAnswer ? 'Predefined Question' : 'Free Question',
-      // question_type: 'Free Question',
+      question_type:
+        isPresetQuestion || !is_FixedAnswer.value ? 'Predefined Question' : 'Free Question',
       question_content: question,
-      fixed_faq: !is_FixedAnswer ? messages.value[messages.value.length - 2].content : ''
+      fixed_faq: fixed_faq
     })
     .then((res) => {
       if (isPause.value) {
@@ -140,7 +145,11 @@ const aiChat = (question, isPresetQuestion) => {
       if (res.code === 200) {
         clearInterval(progressInterval.value)
 
-        is_FixedAnswer.value = res.data.is_fixedAnswer_end || false
+        is_FixedAnswer.value =
+          res.data.is_fixedAnswer_end !== null || res.data.is_fixedAnswer_end !== undefined
+            ? res.data.is_fixedAnswer_end
+            : true
+        console.log('is_FixedAnswer.value', is_FixedAnswer.value)
         const { data } = res.data
         messages.value[messages.value.length - 1] = {
           id: serial_no.value,