UnisKB/ui/src/views/hit-test/index.vue

331 lines
9.3 KiB
Vue
Raw Normal View History

2023-12-28 09:30:52 +00:00
<template>
<div class="hit-test">
<LayoutContainer>
<template #header>
<h3>
命中测试
<el-text type="info" class="ml-4">针对用户提问调试段落匹配情况保障回答效果</el-text>
</h3>
</template>
<div class="hit-test__main p-16" v-loading="loading">
2023-12-29 07:13:30 +00:00
<div class="question-title clearfix" v-if="questionTitle">
2023-12-28 09:30:52 +00:00
<div class="avatar">
<AppAvatar>
<img src="@/assets/user-icon.svg" style="width: 54%" alt="" />
</AppAvatar>
</div>
<div class="content">
2023-12-29 07:13:30 +00:00
<h4 class="text break-all">{{ questionTitle }}</h4>
2023-12-28 09:30:52 +00:00
</div>
</div>
<el-scrollbar>
<div class="hit-test-height">
<el-empty v-if="paragraphDetail.length == 0" description="暂无数据" />
<el-row v-else>
<el-col
:xs="24"
:sm="12"
2024-03-05 11:01:24 +00:00
:md="12"
2023-12-28 09:30:52 +00:00
:lg="8"
:xl="6"
v-for="(item, index) in paragraphDetail"
:key="index"
class="p-8"
>
<CardBox
shadow="hover"
:title="item.title || '-'"
:description="item.content"
class="document-card cursor"
:class="item.is_active ? '' : 'disabled'"
:showIcon="false"
@click="editParagraph(item)"
>
2024-01-02 09:32:41 +00:00
<template #icon>
2024-03-04 08:20:54 +00:00
<AppAvatar class="mr-12 avatar-light" :size="22">
{{ index + 1 + '' }}</AppAvatar>
2024-01-02 09:32:41 +00:00
</template>
2024-03-04 07:26:13 +00:00
<div class="active-button primary">{{ item.similarity?.toFixed(3) }}</div>
2023-12-28 09:30:52 +00:00
<template #footer>
<div class="footer-content flex-between">
2023-12-29 07:13:30 +00:00
<el-text>
<el-icon>
<Document />
</el-icon>
{{ item?.document_name }}
</el-text>
<div v-if="item.trample_num || item.star_num">
<span v-if="item.star_num">
<AppIcon iconName="app-like-color"></AppIcon>
{{ item.star_num }}
</span>
<span v-if="item.trample_num" class="ml-4">
<AppIcon iconName="app-oppose-color"></AppIcon>
{{ item.trample_num }}
</span>
</div>
2023-12-28 09:30:52 +00:00
</div>
</template>
</CardBox>
</el-col>
</el-row>
</div>
</el-scrollbar>
</div>
2023-12-29 07:13:30 +00:00
<ParagraphDialog ref="ParagraphDialogRef" :title="title" @refresh="refresh" />
2023-12-28 09:30:52 +00:00
</LayoutContainer>
<div class="hit-test__operate p-24 pt-0">
2024-03-01 03:06:09 +00:00
<el-popover :visible="popoverVisible" placement="right-end" :width="180" trigger="click">
2023-12-28 09:30:52 +00:00
<template #reference>
2024-01-22 06:25:53 +00:00
<el-button icon="Setting" class="mb-8" @click="settingChange('open')"></el-button>
2023-12-28 09:30:52 +00:00
</template>
2024-02-26 07:34:21 +00:00
<div class="mb-16">
2024-03-01 03:06:09 +00:00
<div class="title mb-8">相似度高于</div>
2024-02-26 07:34:21 +00:00
<el-input-number
v-model="cloneForm.similarity"
:min="0"
:max="1"
:precision="3"
:step="0.1"
controls-position="right"
2024-03-01 03:06:09 +00:00
style="width: 145px"
2024-02-26 07:34:21 +00:00
/>
</div>
<div class="mb-16">
2024-03-04 06:16:25 +00:00
<div class="title mb-8">返回分段数 TOP</div>
2024-03-01 03:06:09 +00:00
2024-02-26 07:34:21 +00:00
<el-input-number
v-model="cloneForm.top_number"
:min="1"
:max="10"
controls-position="right"
2024-03-01 03:06:09 +00:00
style="width: 145px"
2024-02-26 07:34:21 +00:00
/>
</div>
<div class="text-right">
<el-button @click="popoverVisible = false">取消</el-button>
<el-button type="primary" @click="settingChange('close')"></el-button>
2023-12-28 09:30:52 +00:00
</div>
</el-popover>
<div class="operate-textarea flex">
<el-input
ref="quickInputRef"
v-model="inputValue"
type="textarea"
placeholder="请输入"
:autosize="{ minRows: 1, maxRows: 8 }"
@keydown.enter="sendChatHandle($event)"
/>
<div class="operate">
<el-button
text
class="sent-button"
:disabled="isDisabledChart || loading"
@click="sendChatHandle"
>
<img v-show="isDisabledChart || loading" src="@/assets/icon_send.svg" alt="" />
<img
v-show="!isDisabledChart && !loading"
src="@/assets/icon_send_colorful.svg"
alt=""
/>
</el-button>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { reactive, ref, onMounted, computed } from 'vue'
import { useRoute } from 'vue-router'
2024-01-22 06:25:53 +00:00
import { cloneDeep } from 'lodash'
2023-12-28 09:30:52 +00:00
import datasetApi from '@/api/dataset'
2023-12-29 07:13:30 +00:00
import applicationApi from '@/api/application'
import ParagraphDialog from '@/views/paragraph/component/ParagraphDialog.vue'
2024-01-02 09:32:41 +00:00
import { arraySort } from '@/utils/utils'
2023-12-29 07:13:30 +00:00
2023-12-28 09:30:52 +00:00
const route = useRoute()
const {
2023-12-29 07:13:30 +00:00
params: { id }
2023-12-28 09:30:52 +00:00
} = route as any
const ParagraphDialogRef = ref()
const loading = ref(false)
const paragraphDetail = ref<any[]>([])
const title = ref('')
const inputValue = ref('')
2024-01-22 06:25:53 +00:00
const formInline = ref({
2024-01-17 08:29:37 +00:00
similarity: 0.6,
2023-12-28 09:30:52 +00:00
top_number: 5
})
2024-01-22 06:25:53 +00:00
const cloneForm = ref<any>({})
2023-12-28 09:30:52 +00:00
const popoverVisible = ref(false)
2023-12-29 07:13:30 +00:00
const questionTitle = ref('')
2023-12-28 09:30:52 +00:00
const isDisabledChart = computed(() => !inputValue.value)
2023-12-29 07:13:30 +00:00
const isApplication = computed(() => {
const { meta } = route as any
return meta?.activeMenu.includes('application')
})
const isDataset = computed(() => {
const { meta } = route as any
return meta?.activeMenu.includes('dataset')
})
2024-01-22 06:25:53 +00:00
function settingChange(val: string) {
if (val === 'open') {
popoverVisible.value = true
cloneForm.value = cloneDeep(formInline.value)
} else if (val === 'close') {
popoverVisible.value = false
formInline.value = cloneDeep(cloneForm.value)
}
}
2023-12-28 09:30:52 +00:00
function editParagraph(row: any) {
title.value = '分段详情'
ParagraphDialogRef.value.open(row)
}
function sendChatHandle(event: any) {
if (!event.ctrlKey) {
// 如果没有按下组合键ctrl则会阻止默认事件
event.preventDefault()
if (!isDisabledChart.value && !loading.value) {
getHitTestList()
}
} else {
// 如果同时按下ctrl+回车键,则会换行
inputValue.value += '\n'
}
}
function getHitTestList() {
const obj = {
query_text: inputValue.value,
2024-01-22 07:33:48 +00:00
similarity: formInline.value.similarity,
top_number: formInline.value.top_number
2023-12-28 09:30:52 +00:00
}
2023-12-29 07:13:30 +00:00
if (isDataset.value) {
datasetApi.getDatasetHitTest(id, obj, loading).then((res) => {
2024-01-02 09:32:41 +00:00
paragraphDetail.value = res.data && arraySort(res.data, 'comprehensive_score', true)
2023-12-29 07:13:30 +00:00
questionTitle.value = inputValue.value
inputValue.value = ''
})
} else if (isApplication.value) {
applicationApi.getApplicationHitTest(id, obj, loading).then((res) => {
2024-01-02 09:32:41 +00:00
paragraphDetail.value = res.data && arraySort(res.data, 'comprehensive_score', true)
2023-12-29 07:13:30 +00:00
questionTitle.value = inputValue.value
inputValue.value = ''
})
}
2023-12-28 09:30:52 +00:00
}
function refresh(data: any) {
if (data) {
2024-03-04 07:26:13 +00:00
const obj = paragraphDetail.value.filter((v) => v.id === data.id)[0]
obj.content = data.content
obj.title = data.title
2023-12-28 09:30:52 +00:00
} else {
paragraphDetail.value = []
getHitTestList()
}
}
onMounted(() => {})
</script>
<style lang="scss" scoped>
.hit-test {
.question-title {
.avatar {
float: left;
}
.content {
padding-left: 40px;
.text {
padding: 6px 0;
}
}
}
&__operate {
.operate-textarea {
box-shadow: 0px 6px 24px 0px rgba(31, 35, 41, 0.08);
background-color: #ffffff;
border-radius: 8px;
border: 1px solid #ffffff;
box-sizing: border-box;
&:has(.el-textarea__inner:focus) {
border: 1px solid var(--el-color-primary);
}
:deep(.el-textarea__inner) {
border-radius: 8px !important;
box-shadow: none;
resize: none;
padding: 12px 16px;
}
.operate {
padding: 6px 10px;
.sent-button {
max-height: none;
.el-icon {
font-size: 24px;
}
}
:deep(.el-loading-spinner) {
margin-top: -15px;
.circular {
width: 31px;
height: 31px;
}
}
}
}
}
}
.hit-test {
&__header {
position: absolute;
right: calc(var(--app-base-px) * 3);
}
.hit-test-height {
height: calc(var(--app-main-height) - 170px);
}
.document-card {
height: 210px;
background: var(--app-layout-bg-color);
border: 1px solid var(--app-layout-bg-color);
&:hover {
background: #ffffff;
border: 1px solid var(--el-border-color);
}
&.disabled {
background: var(--app-layout-bg-color);
border: 1px solid var(--app-layout-bg-color);
:deep(.description) {
color: var(--app-border-color-dark);
}
:deep(.title) {
color: var(--app-border-color-dark);
}
}
:deep(.description) {
-webkit-line-clamp: 5 !important;
height: 110px;
}
.active-button {
position: absolute;
right: 16px;
top: 16px;
}
}
}
</style>