zhangxiao
2024-08-30 c02bff2911f720d54388f4abb6456ec1777f8a96
src/views/sessionManager/components/seniorAgentSession.vue
@@ -37,7 +37,7 @@
  </div>
  <a-scrollbar
    ref="scrollbar"
    id="agentHome"
    id="chatAgentHome"
    class="chat-list"
    style="
      width: 80%;
@@ -125,8 +125,17 @@
            <div class="codeStle">
              <div class="language">python</div>
              <pre
                style="
                  background: #2c2c36;
                  padding: 10px;
                  margin-top: 0;
                  margin-bottom: 0;
                "
              ><code class="language-js line-numbers">{{ sessionDetail.code}}</code></pre>
              <div class="language">SQL</div>
              <pre
                style="background: #2c2c36; padding: 10px; margin-top: 0"
              ><code class="language-js line-numbers">{{ sessionDetail.code+ sessionDetail.sql}}</code></pre>
              ><code class="language-js line-numbers">{{sessionDetail.sql}}</code></pre>
            </div>
            <a-image
@@ -134,7 +143,10 @@
              :src="getImg(sessionDetail)"
              alt=""
            />
            <div class="uploadFileList fileList">
            <div
              class="uploadFileList fileList"
              v-if="sessionDetail?.excel_name"
            >
              <a-comment
                :content="sessionDetail.excel_name"
                style="
@@ -219,7 +231,7 @@
          />
        </template>
        <template #content>
          <a-spin :loading="onFileSelectedLoading" dot>
          <a-spin :loading="loading" dot style="width: 100%">
            <a-textarea
              readonly
              auto-size
@@ -283,7 +295,7 @@
        ></updataFile> -->
        <span v-if="getAent"></span>
        <uploadFile
          v-if="agentObj.id == 'excel_talk' || dialog_id == 'excel_talk'"
          v-if="!getAent"
          ref="fileInput"
          :sessionId="activeSessionId"
          @selectFileCallback="selectFileCallback"
@@ -596,6 +608,7 @@
        id: agentObj.id,
      }),
    });
    refreshScroll();
    const reader = response?.body
      ?.pipeThrough(new TextDecoderStream())
@@ -612,7 +625,11 @@
          const d = val?.data;
          if (typeof d !== 'boolean') {
            console.info('data:', d);
            streamStr.value = d.content;
            if (d?.content) {
              streamStr.value = d.content;
            } else {
              streamStr.value = d.code + d.sql;
            }
            startDisplayStr();
          }
        } catch (e) {
@@ -629,6 +646,7 @@
    chatDis.value = false;
    loading.value = false;
    inputMsg.value = '';
    uploaditemList.value = [];
  };
  //渲染文字
@@ -676,11 +694,9 @@
  const getAentId = (id) => {
    if (id == 'excel_talk') {
      console.log(1);
      getAent.value = false;
    }
    if (id == 'questions_talk') {
      console.log(2);
      getAent.value = true;
    }
  };
@@ -716,6 +732,7 @@
  const sentClick = () => {
    sendMessage('click');
    uploaditemList.value = [];
  };
@@ -734,44 +751,9 @@
          event.preventDefault(); // 阻止默认行为,即不换行
        }
        // chatDis.value = true;
        // loading.value = true;
        // if (!agentObj.id) {
        //   Message.warning('请选择会话');
        //   chatDis.value = false;
        //   loading.value = false;
        //   return;
        // }
        // if (displayedText.value) {
        //   querySessionList();
        // }
        if (inputMsg.value) {
          //   const res = await addSessionApi({
          //     dialog_id: '',
          //     conversation_desc: inputMsg.value,
          //   });
          //   // console.log(res, "res");
          //   if (res.code == 200) {
          //     // console.log(res.data.conversation_id);
          //     activeSessionId.value = res.data?.conversation_id;
          //     const { code, data } = await getSessionDetailsApi(
          //       res.data?.conversation_id
          //     );
          //     if (code === 200) {
          //       console.log(data, '新建会话详情');
          //       Object.assign(chatObj, data);
          //       startChat(inputMsg.value);
          //       inputMsg.value = '';
          //     }
          //   } else {
          //     Message.error('创建会话失败,请重试');
          //   }
          //   startChat(inputMsg.value);
          //   inputMsg.value = '';
          createSession('');
          uploaditemList.value = [];
        } else {
          Message.warning('消息不能为空');
          chatDis.value = false;
@@ -785,6 +767,11 @@
    try {
      loading.value = true;
      chatDis.value = true;
      let name = inputMsg.value;
      if (val) {
        name = val[0].name.split('.')[0];
      }
      if (!activeSessionId.value) {
        let message = [
@@ -792,15 +779,11 @@
            content: sessionDetailList.value[0].content,
            role: 'assistant',
          },
          {
            content: inputMsg.value,
            role: 'user',
          },
        ];
        const res = await agentConversationSetApi({
          id: '',
          app_id: agentObj.id,
          name: inputMsg.value,
          name: name,
          message: message,
        });
        // console.log(res, "res");
@@ -811,6 +794,7 @@
          if (!val) {
            startChat(inputMsg.value);
            inputMsg.value = '';
            uploaditemList.value = [];
          } else {
            loading.value = false;
            chatDis.value = false;
@@ -852,7 +836,7 @@
      const formData = new FormData();
      uploaditemList.value = resData;
      if (!activeSessionId.value) {
        await createSession(1);
        await createSession(resData);
      }
      onFileSelectedLoading.value = true;
@@ -963,7 +947,13 @@
            if (typeof d !== 'boolean') {
              console.info('data:', d);
              streamStr.value = d.content;
              if (d?.content) {
                streamStr.value = d.content;
              } else {
                streamStr.value = d.code;
              }
              startDisplayStr();
            }
          } catch (e) {
@@ -1044,6 +1034,7 @@
    if (timer) {
      clearTimeout(timer!);
    }
    const res = streamStr.value;
    // 将数组中的字符串拼接起来
@@ -1064,7 +1055,7 @@
  const scrollbar = ref(null);
  const refreshScroll = () => {
    nextTick(() => {
      const container = document.getElementById('agentHome');
      const container = document.getElementById('chatAgentHome');
      scrollbar.value.scrollTop(container.scrollHeight);
    });
  };