zhangxiao
2024-08-07 594c3f2509277de4eeac71f1fa252cda17891f6f
src/views/dmx/knowledgeLib/tool.vue
@@ -39,16 +39,11 @@
              @submit="handleSubmit"
            >
              <a-divider style="margin-top: 10px" />
              <a-form-item
                field="slider"
                label="块token数"
                :rules="[
                  { type: 'number', min: 1, message: 'slider is min than 1' },
                ]"
              >
              <a-form-item field="slider" label="块Token数">
                <a-slider
                  v-model="form.chunk_token_num"
                  :max="1000"
                  :min="0"
                  :max="2048"
                  show-input
                />
              </a-form-item>
@@ -73,37 +68,30 @@
                    placeholder="请填写提示词"
                  />
                </a-form-item>
                <a-form-item
                  field="slider"
                  label="最大token数"
                  :rules="[
                    { type: 'number', min: 5, message: 'slider is min than 5' },
                  ]"
                >
                <a-form-item field="slider" label="最大token数">
                  <a-slider
                    v-model="form.max_token"
                    :min="1"
                    :max="1000"
                    :min="0"
                    :max="2048"
                    show-input
                  />
                </a-form-item>
                <a-form-item
                  field="slider"
                  label="阈值"
                  :rules="[
                    { type: 'number', min: 5, message: 'slider is min than 5' },
                  ]"
                >
                  <a-slider v-model="form.threshold" show-tooltip show-input />
                <a-form-item field="slider" label="阈值">
                  <a-slider
                    v-model="form.threshold"
                    :step="0.01"
                    :min="0"
                    :max="1"
                    show-input
                  />
                </a-form-item>
                <a-form-item
                  field="slider"
                  label="最大聚类数"
                  :rules="[
                    { type: 'number', min: 5, message: 'slider is min than 5' },
                  ]"
                >
                  <a-slider v-model="form.max_cluster" :max="1000" show-input />
                <a-form-item field="slider" label="最大聚类数">
                  <a-slider
                    v-model="form.max_cluster"
                    :min="1"
                    :max="1024"
                    show-input
                  />
                </a-form-item>
                <a-form-item
                  field="slider"
@@ -185,7 +173,12 @@
                  </a-space>
                  <a-divider style="margin: 10px 0" />
                  <p>
                    <a-button type="text" class="button" style="color: #2a2a2b">
                    <a-button
                      type="text"
                      class="button"
                      style="color: #2a2a2b"
                      @click="addBlock(1)"
                    >
                      <template #icon>
                        <icon-check-circle />
                      </template>
@@ -193,7 +186,12 @@
                    </a-button>
                  </p>
                  <p>
                    <a-button type="text" class="button" style="color: #2a2a2b">
                    <a-button
                      type="text"
                      class="button"
                      style="color: #2a2a2b"
                      @click="addBlock(0)"
                    >
                      <template #icon>
                        <icon-close-circle />
                      </template>
@@ -202,7 +200,12 @@
                  </p>
                  <a-divider style="margin: 10px 0" />
                  <p>
                    <a-button type="text" class="button" style="color: #2a2a2b">
                    <a-button
                      type="text"
                      class="button"
                      style="color: #2a2a2b"
                      @click="addBlock(3)"
                    >
                      <template #icon>
                        <icon-delete />
                      </template>
@@ -211,10 +214,28 @@
                  </p>
                </template>
              </a-popover>
              <a-space
                direction="vertical"
                size="large"
                style="margin-right: 10px"
                class="space_search"
                v-show="!isBtn"
              >
                <a-input-search
                  :style="{ width: '220px' }"
                  v-model="form.keywords"
                  @input="getList()"
                  allow-clear
                  @clear.stop="getList()"
                  placeholder="搜索"
                />
              </a-space>
              <a-button
                type="outline"
                class="button"
                style="margin-right: 10px"
                v-show="isBtn"
                @click.stop="isBtn = !isBtn"
              >
                <template #icon>
                  <icon-search />
@@ -234,69 +255,50 @@
                    size="large"
                    @change="onChangeavailable"
                  >
                    <a-radio value="">所有</a-radio>
                    <a-radio value="1">启用</a-radio>
                    <a-radio value="0">禁用</a-radio>
                    <a-radio :value="''">所有</a-radio>
                    <a-radio :value="1">启用</a-radio>
                    <a-radio :value="0">禁用</a-radio>
                  </a-radio-group>
                </template>
              </a-popover>
              <addDetails :item="item"></addDetails>
              <addDetails
                :item="item"
                @canplaythrough="canplaythrough"
              ></addDetails>
            </div>
          </div>
          <a-divider style="margin-top: 10px" />
          <div class="groupMain">
            <a-checkbox-group v-model="data" @change="handleChange">
              <div
                class="groupList"
                :style="{ background: keyBg == '1' ? '#eff8ff' : 'white' }"
              >
                <a-checkbox value="1"></a-checkbox>
            <a-spin :loading="isLoading" :tip="tip">
              <a-checkbox-group v-model="data" @change="handleChange">
                <div
                  class="groupList-content"
                  @click="groupListContentClick('1')"
                  @dblclick="contentClick(1)"
                  class="groupList"
                  :class="{
                    groupActive: keyBg == '1',
                    groupNoActive: keyBg != '1',
                  }"
                  v-for="(item, index) in listData"
                  :key="index"
                >
                  而 stable version 是最新稳定版,经过充分测试和验证,bug 较少,
                  适合用于生产环境。其版本号通常为双数,如 1.26。legacy versions
                  则是之前发布的稳定版,对于需要
                  特定旧版本的兼容性或安全性支持的用户有用,但一般不
                  推荐用于新项目,除非有特殊需求。在实际使用中,如果追求最新功能
                  且愿意面对可能存在的一些不稳定因素,可以尝试使用主线版本进行测试和研究;如果是用于生产环境
                  <a-checkbox :value="item.chunk_id"></a-checkbox>
                  <div
                    class="groupList-content emphaRed"
                    @click="groupListContentClick('1')"
                    @dblclick="contentClick(1)"
                    v-html="item.content_with_weight"
                  >
                  </div>
                  <div class="groupList-right">
                    <a-switch
                      v-model="item.available_int"
                      :checked-value="1"
                      :unchecked-value="0"
                      @change="handleChangeStatus(item)"
                    />
                  </div>
                </div>
                <div class="groupList-right">
                  <a-switch
                    v-model="switchType"
                    checked-value="1"
                    unchecked-value="0"
                    @change="handleChangeStatus()"
                  />
                </div>
              </div>
              <div
                class="groupList"
                :style="{ background: keyBg == '2' ? '#eff8ff' : 'white' }"
              >
                <a-checkbox value="1"></a-checkbox>
                <div
                  class="groupList-content"
                  @click="groupListContentClick('2')"
                  @dblclick="contentClick(1)"
                >
                  而 stable version 是最新稳定版,经过充分测试和验证,bug 较少,
                  适合用于生产环境。其版本号通常为双数,如 1.26。legacy versions
                  则是之前发布的稳定版,对于需要
                </div>
                <div class="groupList-right">
                  <a-switch
                    v-model="switchType"
                    checked-value="1"
                    unchecked-value="0"
                    @change="handleChangeStatus()"
                  />
                </div>
              </div>
            </a-checkbox-group>
              </a-checkbox-group>
            </a-spin>
          </div>
        </div>
        <eidtDetails ref="eidtDil"></eidtDetails>
@@ -306,9 +308,22 @@
</template>
<script lang="ts" setup>
  import { onMounted, onBeforeMount, reactive, ref, computed } from 'vue';
  import {
    onMounted,
    onBeforeMount,
    reactive,
    ref,
    computed,
    watch,
  } from 'vue';
  import { Message } from '@arco-design/web-vue';
  import { kbdocumentchangeparser } from '@/api/kbList';
  import {
    kbdocumentchangeparser,
    achunkCreate,
    queryChunkList,
    chunkSwitch,
    chunkRm,
  } from '@/api/kbList';
  import addDetails from '@/views/dmx/knowledgeLib/addDetails.vue';
  import eidtDetails from '@/views/dmx/knowledgeLib/eidtDetails.vue';
  const visible = ref(false);
@@ -334,15 +349,33 @@
    };
  });
  const isBtn = ref(true);
  const closeSlelct = () => {
    window.addEventListener('click', (event) => {
      if (!event.target.closest('.space_search') && !isBtn.value) {
        isBtn.value = true;
        // form.keywords = '';
      }
    });
  };
  watch(isBtn, (val) => {
    if (!val) {
      closeSlelct();
    }
  });
  const form = reactive({
    parser_id: props.item.parser_id,
    doc_id: props.item.id,
    max_token: 698,
    threshold: 30,
    threshold: 0.3,
    max_cluster: 233,
    random_seed: 1500,
    chunk_token_num: 128,
    use_raptor: false,
    keywords: '',
    pages: {},
    prompt:
      '请总结以下段落。 小心数字,不要编造。 段落如下:\n' +
@@ -358,6 +391,9 @@
      },
    ],
  };
  const listData = ref([]);
  const formatter = (value) => {
    return value / 100;
  };
@@ -430,11 +466,14 @@
  const onRadioChange = () => {
    console.log(radio.value);
  };
  //批量操作
  const handleChangeAll = (value) => {
    indeterminate.value = false;
    if (value) {
      checkedAll.value = true;
      data.value = ['1', '2', '3'];
      listData.value.forEach((item) => {
        data.value.push(item.chunk_id);
      });
    } else {
      checkedAll.value = false;
      data.value = [];
@@ -442,15 +481,33 @@
  };
  const handleChange = (values) => {
    if (values.length === 3) {
      checkedAll.value = true;
      indeterminate.value = false;
    } else if (values.length === 0) {
      checkedAll.value = false;
      indeterminate.value = false;
    data.value = values;
  };
  //批量启用删除禁用
  const addBlock = (type) => {
    if (data.value.length == 0) {
      Message.error('请选择要操作的数据');
      return;
    }
    if (type == 3) {
      deleteChunk();
    } else {
      checkedAll.value = false;
      indeterminate.value = true;
      let params = {
        chunk_ids: data.value,
        available_int: type,
        doc_id: props.item.id,
      };
      chunkSwitch(params).then((res) => {
        if (res.code == 0) {
          Message.success('操作成功');
          getList();
          checkedAll.value = false;
          data.value = [];
        } else {
          Message.error('操作失败');
        }
      });
    }
  };
@@ -459,15 +516,81 @@
  };
  const onChangeavailable = () => {
    console.log(available_int.value);
    getList();
  };
  const handleChangeStatus = () => {
    console.log(switchType.value);
  const handleChangeStatus = (val) => {
    updateChunkStatus(val);
  };
  const isLoading = ref(true);
  // 自定义加载提示文本
  const tip = '加载中,请稍候...';
  //获取列表
  const getList = () => {
    let params = {
      doc_id: props.item.id,
      keywords: form.keywords,
      page: 1,
      size: 10000,
    };
    if (available_int.value !== '') {
      params.available_int = available_int.value;
    }
    queryChunkList(params).then((res) => {
      if (res.code == 0) {
        listData.value = res.data.chunks;
        isLoading.value = false;
        listData.value = listData.value.map((item) => {
          item.available_int = parseInt(item.available_int);
          return item;
        });
      }
    });
  };
  //更新列表
  const canplaythrough = () => {
    getList();
  };
  //启用禁用
  const updateChunkStatus = (val) => {
    let params = {
      chunk_ids: [val.chunk_id],
      available_int: val.available_int,
      doc_id: props.item.id,
    };
    chunkSwitch(params).then((res) => {
      console.log(res);
      if (res.code == 0) {
        Message.success('更新成功');
        getList();
      } else {
        Message.error('更新失败');
      }
    });
  };
  //删除
  const deleteChunk = () => {
    let params = {
      chunk_ids: data.value,
      doc_id: props.item.id,
    };
    chunkRm(params).then((res) => {
      console.log(res);
      if (res.code == 0) {
        Message.success('删除成功');
        getList();
      } else {
        Message.error('删除失败');
      }
    });
  };
  onBeforeMount(() => {});
  onMounted(() => {});
  onMounted(() => {
    getList();
  });
</script>
<style scoped lang="less">
@@ -504,11 +627,22 @@
        box-sizing: border-box;
        margin: 0;
        padding: 0;
        color: rgba(0, 0, 0, 0.88);
        color: #2a2a2b;
        font-size: 14px;
        font-family: Inter;
        position: relative;
      }
    }
  }
  :deep(.emphaRed em) {
    color: red !important;
  }
  .groupActive {
    background: #eff8ff;
  }
  .groupNoActive {
    background: var(--color-bg-1);
    color: var(--color-text-1);
  }
</style>