yangyin
2024-07-02 4d513546eedc4738cf1b7b73425bffd4c60cc6b0
src/components/chat/Chat.vue
@@ -31,18 +31,16 @@
</template>
<script setup lang="ts">
import { computed, nextTick, onMounted, ref, watch } from 'vue';
import { ElMessage } from 'element-plus';
import { computed, nextTick, ref, watch } from 'vue';
import useClipboard from 'vue-clipboard3';
import Loding from './components/Loding.vue';
import { RecordSet } from './model/Record';
import type { ChatContent } from './model/types';
import { AnswerType, RoleEnum, answerTypeMapCom, roleImageMap, type ChatMessage } from './model/types';
import { GetHistoryAnswer, QueryHistoryDetail, QuestionAi } from '/@/api/ai/chat';
import PlayBar from '/@/components/chat/components/playBar/PlayBar.vue';
import router from '/@/router';
import { activeChatRoom, activeRoomId } from '/@/stores/chatRoom';
import { ElMessage } from 'element-plus';
import { content } from 'html2canvas/dist/types/css/property-descriptors/content';
import { activeChatRoom, activeLLMId, activeRoomId, activeSampleId, activeSectionAId } from '/@/stores/chatRoom';
let isTalking = ref(false);
let messageContent = ref<ChatContent>({
@@ -98,12 +96,26 @@
};
const questionAi = async (text) => {
   const res = await QuestionAi({
   if (!currentSectionId) {
      ElMessage.warning('发送失败,未确定应用场景!');
   }
   const params = {
      question: text,
      // FIXME: 暂时这样
      section_a_id: 'undefined',
      section_a_id: currentSectionId,
      history_group_id: activeRoomId.value,
   });
   } as any;
   if (currentSampleId) {
      params.sample_id = currentSampleId;
   }
   if (currentLLMId) {
      params.llm_id = currentLLMId;
   }
   const res = await QuestionAi(params);
   // const res = {
   //    json_ok: true,
   //    question: '昨日五一广场压力',
@@ -133,7 +145,10 @@
   if (!chatListDom.value) return;
   chatListDom.value.lastElementChild?.scrollIntoView();
};
let currentSectionId = null;
let currentSampleId = null;
let currentLLMId = null;
const getAnswerById = async (historyId: string) => {
   return await GetHistoryAnswer({
      history_id: historyId,
@@ -144,6 +159,17 @@
   if (activeChatRoom.value.isInitial) {
      activeChatRoom.value.title = messageContent.value.values;
      activeChatRoom.value.isInitial = false;
      if (activeSampleId.value) {
         currentSampleId = activeSampleId.value;
      }
      if (activeLLMId.value) {
         currentLLMId = activeLLMId.value;
      }
      if (activeSectionAId.value) {
         currentSectionId = activeSectionAId.value;
      }
   }
   try {
      isTalking.value = true;
@@ -167,12 +193,11 @@
   }
};
const appendLastMessageContent = (content: ChatContent) => {
   if(messageList.value.at(-1)){
   if (messageList.value.at(-1)) {
      messageList.value.at(-1).content = content;
   }
};
let currentSectionId = '';
watch(
   () => activeRoomId.value,
   async (val) => {
@@ -187,7 +212,6 @@
            type: AnswerType.Text,
            values: activeChatRoom.value.title,
         };
         console.log("🚀 ~ activeChatRoom.value.title:", activeChatRoom.value.title)
         sendChatMessage();
      } else {
         const res = await QueryHistoryDetail({
@@ -203,6 +227,7 @@
            } as ChatMessage;
         });
         currentSectionId = res?.details?.[0]?.section_a_id;
         currentSampleId = res?.details?.[0]?.sample_id;
         const resList = await Promise.all((res.details ?? []).map((item) => getAnswerById(item.history_id)));
         let i = 0;