yinbangzhong
2024-08-08 4ace68af4236a1be8b57dbcfc185871eda76fed9
会话实时显示
4个文件已修改
106 ■■■■ 已修改文件
config/vite.config.prod.ts 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
package.json 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/session/sessionRecordsManager/index.vue 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yarn.lock 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
config/vite.config.prod.ts
@@ -14,29 +14,6 @@
      configArcoResolverPlugin(),
      configImageminPlugin(),
    ],
    server: {
      open: true, // 项目启动后,自动打开
      fs: {
        strict: true,
      },
      proxy: {
        '/base': {
          target: 'http://192.168.20.116:8089',
          changeOrigin: true,
          ws: true,
        },
        '/api': {
          target: 'http://192.168.20.116:8089',
          changeOrigin: true,
          ws: true,
        },
        '/api/v1': {
          target: 'http://192.168.20.116:8089',
          changeOrigin: true,
          ws: true,
        },
      },
    },
    build: {
      rollupOptions: {
        output: {
package.json
@@ -15,17 +15,9 @@
    "prepare": "husky install"
  },
  "lint-staged": {
    "*.{js,ts,jsx,tsx}": [
    ],
    "*.vue": [
    ],
    "*.{less,css}": [
    ]
    "*.{js,ts,jsx,tsx}": [],
    "*.vue": [],
    "*.{less,css}": []
  },
  "pnpm": {
    "overrides": {
@@ -41,6 +33,7 @@
    "axios": "^0.24.0",
    "dayjs": "^1.11.5",
    "echarts": "^5.4.0",
    "eventsource-parser": "^2.0.1",
    "js-base64": "^3.7.5",
    "jsencrypt": "^3.3.2",
    "lodash": "^4.17.21",
src/views/session/sessionRecordsManager/index.vue
@@ -306,6 +306,7 @@
  import { useAppStore } from '@/store';
  import { computed, nextTick, onMounted, reactive, ref } from 'vue';
  import { Message } from '@arco-design/web-vue';
  import { EventSourceParserStream } from 'eventsource-parser/stream';
  import moment from 'moment';
  import AddSession from '@/views/session/sessionManager/components/addSession.vue';
  import {
@@ -314,6 +315,8 @@
    getSessionDetailsApi,
    sessionListApi,
  } from '@/api/session';
  import { getAuthorization } from "@/utils/auth";
  const sessionDetailList = ref([]); //根据会话id出来的会话详情
  const sessionList = ref([]); //会话列表
@@ -353,30 +356,49 @@
      return;
    }
    if (inputMsg.value) {
      const data = await chatApi({
        conversation_id: activeSessionId.value,
        messages: inputMsg.value,
      sessionDetailList.value.push({ "content": inputMsg.value, "role": "user" });
      sessionDetailList.value.push({  "role": "last" });
      refreshScroll();
      const response = await fetch("/api/tech/cloudminds/query?modeltype=localragflow", {
        method: 'POST',
        headers: {
          'Authorization': getAuthorization(),
          'Content-Type': 'application/json',
        },
        body: JSON.stringify({
          conversation_id: activeSessionId.value,
          messages: inputMsg.value,
        }),
      });
      if (data) {
        chatDis.value = false;
        // inputMsg.value = '';
        // querySessionDetail({ id: activeSessionId.value });
      }
      const res = await getSessionDetailsApi(activeSessionId.value);
      if (res.code === 200) {
        sessionDetailList.value = res.data.message.map((item, index) => {
          if (index === res.data.message.length - 1) {
            item.role = 'last';
            displayedText.value = '';
            currIndex.value = 0;
            streamStr.value = item.content;
            startDisplayStr();
      const reader = response?.body
        ?.pipeThrough(new TextDecoderStream())
        .pipeThrough(new EventSourceParserStream())
        .getReader();
      currIndex.value = 0;
      while (true) {
        const x = await reader?.read();
        if (x) {
          const { done, value } = x;
          try {
            const val = JSON.parse(value?.data || '');
            const d = val?.data;
            if (typeof d !== "boolean") {
              console.info("data:", d);
              streamStr.value = d.content;
              startDisplayStr();
            }
          } catch (e) {
            console.warn(e);
          }
          return item;
        });
        refreshScroll();
          if (done) {
            console.info('done');
            break;
          }
        }
      }
      chatDis.value=false;
      inputMsg.value = '';
    } else {
      Message.warning('消息不能为空');
@@ -428,6 +450,7 @@
      displayedText.value += res[currIndex.value];
      currIndex.value++;
      setTimeout(startDisplayStr, 100);
      refreshScroll();
    } else {
      clearTimeout(timer!);
      timer = null;
yarn.lock
@@ -3253,6 +3253,11 @@
  resolved "https://registry.npmmirror.com/eventemitter3/-/eventemitter3-5.0.1.tgz"
  integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==
eventsource-parser@^2.0.1:
  version "2.0.1"
  resolved "https://registry.npmmirror.com/eventsource-parser/-/eventsource-parser-2.0.1.tgz#6464341d64de5bea9f31d8063dd312b616146c7a"
  integrity sha512-gMaRLm5zejEH9mNXC54AnIteFI9YwL/q5JKMdBnoG+lEI1JWVGFVk0Taaj9Xb5SKgzIBDZoQX5IzMe44ILWODg==
exec-buffer@^3.0.0:
  version "3.2.0"
  resolved "https://registry.npmmirror.com/exec-buffer/-/exec-buffer-3.2.0.tgz"