2025-12-09 16:21:18 +08:00
|
|
|
<template>
|
2026-01-15 06:01:34 +08:00
|
|
|
<a-modal
|
|
|
|
|
v-model:open="visible"
|
|
|
|
|
title="自动生成评估基准"
|
|
|
|
|
width="600px"
|
|
|
|
|
:confirmLoading="generating"
|
2026-05-19 14:52:54 +08:00
|
|
|
:ok-button-props="{ disabled: generating }"
|
|
|
|
|
:cancel-button-props="{ disabled: generating }"
|
|
|
|
|
:mask-closable="!generating"
|
|
|
|
|
:closable="!generating"
|
2026-01-15 06:01:34 +08:00
|
|
|
@ok="handleGenerate"
|
|
|
|
|
@cancel="handleCancel"
|
2025-12-09 16:21:18 +08:00
|
|
|
>
|
2026-01-15 06:01:34 +08:00
|
|
|
<a-form ref="formRef" :model="formState" :rules="rules" layout="vertical">
|
|
|
|
|
<a-form-item label="基准名称" name="name">
|
|
|
|
|
<a-input v-model:value="formState.name" placeholder="请输入评估基准名称" />
|
|
|
|
|
</a-form-item>
|
2025-12-09 16:21:18 +08:00
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
<a-form-item label="描述" name="description">
|
|
|
|
|
<a-textarea
|
|
|
|
|
v-model:value="formState.description"
|
|
|
|
|
placeholder="请输入评估基准描述(可选)"
|
|
|
|
|
:rows="3"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
2025-12-10 22:48:53 +08:00
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
<a-form-item label="生成参数" name="params" :extra="extraText">
|
2025-12-09 16:21:18 +08:00
|
|
|
<a-row :gutter="16">
|
|
|
|
|
<a-col :span="12">
|
2026-01-15 06:01:34 +08:00
|
|
|
<a-form-item
|
|
|
|
|
label="问题数量"
|
|
|
|
|
name="count"
|
|
|
|
|
:labelCol="{ span: 24 }"
|
|
|
|
|
:wrapperCol="{ span: 24 }"
|
|
|
|
|
>
|
2025-12-09 16:21:18 +08:00
|
|
|
<a-input-number
|
2026-01-15 06:01:34 +08:00
|
|
|
v-model:value="formState.count"
|
|
|
|
|
:min="1"
|
|
|
|
|
:max="100"
|
2025-12-09 16:21:18 +08:00
|
|
|
style="width: 100%"
|
2026-01-15 06:01:34 +08:00
|
|
|
placeholder="生成问题数量"
|
2025-12-09 16:21:18 +08:00
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
<a-col :span="12">
|
2026-01-15 06:01:34 +08:00
|
|
|
<a-form-item
|
|
|
|
|
label="相似chunks数量"
|
|
|
|
|
name="neighbors_count"
|
|
|
|
|
:labelCol="{ span: 24 }"
|
|
|
|
|
:wrapperCol="{ span: 24 }"
|
|
|
|
|
>
|
2025-12-09 16:21:18 +08:00
|
|
|
<a-input-number
|
2026-01-15 06:01:34 +08:00
|
|
|
v-model:value="formState.neighbors_count"
|
|
|
|
|
:min="0"
|
|
|
|
|
:max="10"
|
2025-12-09 16:21:18 +08:00
|
|
|
style="width: 100%"
|
2026-05-06 22:12:09 +08:00
|
|
|
placeholder="每次参考的chunks总数"
|
2025-12-09 16:21:18 +08:00
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
2026-05-19 14:52:54 +08:00
|
|
|
<a-col :span="12">
|
|
|
|
|
<a-form-item
|
|
|
|
|
label="构建并发数"
|
|
|
|
|
name="concurrency_count"
|
|
|
|
|
:labelCol="{ span: 24 }"
|
|
|
|
|
:wrapperCol="{ span: 24 }"
|
|
|
|
|
extra="同时生成评估题目的 worker 数,过高可能触发模型服务限流"
|
|
|
|
|
>
|
|
|
|
|
<a-input-number
|
|
|
|
|
v-model:value="formState.concurrency_count"
|
|
|
|
|
:min="1"
|
|
|
|
|
:max="20"
|
|
|
|
|
style="width: 100%"
|
|
|
|
|
placeholder="默认 10"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
2025-12-09 16:21:18 +08:00
|
|
|
</a-row>
|
2026-01-15 06:01:34 +08:00
|
|
|
</a-form-item>
|
2025-12-09 16:21:18 +08:00
|
|
|
|
2026-05-06 22:12:09 +08:00
|
|
|
<a-form-item
|
|
|
|
|
label="LLM模型配置"
|
|
|
|
|
name="llm_model_spec"
|
|
|
|
|
:rules="[{ required: true, message: '请选择LLM模型' }]"
|
|
|
|
|
>
|
|
|
|
|
<ModelSelectorComponent
|
|
|
|
|
:model_spec="formState.llm_model_spec"
|
|
|
|
|
placeholder="选择用于生成问题的LLM模型"
|
|
|
|
|
@select-model="handleSelectLLMModel"
|
|
|
|
|
/>
|
2026-01-15 06:01:34 +08:00
|
|
|
</a-form-item>
|
2025-12-11 01:34:49 +08:00
|
|
|
</a-form>
|
2026-01-15 06:01:34 +08:00
|
|
|
</a-modal>
|
2025-12-09 16:21:18 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-01-15 06:01:34 +08:00
|
|
|
import { ref, reactive, computed, watch, h } from 'vue'
|
|
|
|
|
import { message } from 'ant-design-vue'
|
|
|
|
|
import { evaluationApi } from '@/apis/knowledge_api'
|
2026-05-06 22:12:09 +08:00
|
|
|
import { useConfigStore } from '@/stores/config'
|
2026-01-15 06:01:34 +08:00
|
|
|
import ModelSelectorComponent from '@/components/ModelSelectorComponent.vue'
|
2026-05-06 22:12:09 +08:00
|
|
|
|
|
|
|
|
const configStore = useConfigStore()
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
visible: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
databaseId: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: true
|
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
})
|
2025-12-09 16:21:18 +08:00
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
const emit = defineEmits(['update:visible', 'success'])
|
2025-12-09 16:21:18 +08:00
|
|
|
|
2026-05-06 22:12:09 +08:00
|
|
|
// 默认基准名称
|
|
|
|
|
const defaultBenchmarkName = () => {
|
|
|
|
|
const today = new Date().toISOString().slice(0, 10)
|
2026-05-21 23:06:33 +08:00
|
|
|
const suffix = Array.from(
|
|
|
|
|
{ length: 4 },
|
|
|
|
|
() => '0123456789abcdefghijklmnopqrstuvwxyz'[Math.floor(Math.random() * 36)]
|
|
|
|
|
).join('')
|
2026-05-06 22:12:09 +08:00
|
|
|
return `Test-${today}-${suffix}`
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-09 16:21:18 +08:00
|
|
|
// 响应式数据
|
2026-01-15 06:01:34 +08:00
|
|
|
const formRef = ref()
|
|
|
|
|
const generating = ref(false)
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
const formState = reactive({
|
2026-05-06 22:12:09 +08:00
|
|
|
name: defaultBenchmarkName(),
|
2025-12-09 16:21:18 +08:00
|
|
|
description: '',
|
|
|
|
|
count: 10,
|
2026-05-06 22:12:09 +08:00
|
|
|
neighbors_count: 1,
|
2026-05-19 14:52:54 +08:00
|
|
|
concurrency_count: 10,
|
2026-05-06 22:12:09 +08:00
|
|
|
llm_model_spec: configStore.config?.default_model || ''
|
2026-01-15 06:01:34 +08:00
|
|
|
})
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
// 表单验证规则
|
|
|
|
|
const rules = {
|
|
|
|
|
name: [
|
|
|
|
|
{ required: true, message: '请输入基准名称', trigger: 'blur' },
|
|
|
|
|
{ min: 2, max: 100, message: '基准名称长度应在2-100个字符之间', trigger: 'blur' }
|
|
|
|
|
],
|
2026-05-19 14:52:54 +08:00
|
|
|
count: [{ required: true, message: '请输入生成问题数量', trigger: 'blur' }],
|
|
|
|
|
concurrency_count: [{ required: true, message: '请输入构建并发数', trigger: 'blur' }]
|
2026-01-15 06:01:34 +08:00
|
|
|
}
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
// 双向绑定visible
|
|
|
|
|
const visible = computed({
|
|
|
|
|
get: () => props.visible,
|
|
|
|
|
set: (val) => emit('update:visible', val)
|
2026-01-15 06:01:34 +08:00
|
|
|
})
|
2025-12-09 16:21:18 +08:00
|
|
|
|
2025-12-14 18:13:46 +08:00
|
|
|
// 说明文本
|
2026-01-15 06:01:34 +08:00
|
|
|
const extraText = computed(() =>
|
|
|
|
|
h('span', {}, [
|
|
|
|
|
'需要了解评估基准生成原理?查看',
|
|
|
|
|
h(
|
|
|
|
|
'a',
|
|
|
|
|
{
|
2026-03-27 02:00:22 +08:00
|
|
|
href: 'https://xerrors.github.io/Yuxi/intro/evaluation.html',
|
2026-01-15 06:01:34 +08:00
|
|
|
target: '_blank',
|
|
|
|
|
rel: 'noopener noreferrer'
|
|
|
|
|
},
|
|
|
|
|
'使用说明'
|
|
|
|
|
)
|
|
|
|
|
])
|
|
|
|
|
)
|
2025-12-14 18:13:46 +08:00
|
|
|
|
2025-12-09 16:21:18 +08:00
|
|
|
// 生成基准
|
|
|
|
|
const handleGenerate = async () => {
|
2026-05-19 14:52:54 +08:00
|
|
|
if (generating.value) return
|
|
|
|
|
|
2025-12-09 16:21:18 +08:00
|
|
|
try {
|
|
|
|
|
// 表单验证
|
2026-01-15 06:01:34 +08:00
|
|
|
await formRef.value.validate()
|
2025-12-09 16:21:18 +08:00
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
generating.value = true
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
|
name: formState.name,
|
|
|
|
|
description: formState.description,
|
|
|
|
|
count: formState.count,
|
2025-12-10 22:48:53 +08:00
|
|
|
neighbors_count: formState.neighbors_count,
|
2026-05-19 14:52:54 +08:00
|
|
|
concurrency_count: formState.concurrency_count,
|
2026-05-06 22:12:09 +08:00
|
|
|
llm_model_spec: formState.llm_model_spec
|
2026-01-15 06:01:34 +08:00
|
|
|
}
|
2025-12-09 16:21:18 +08:00
|
|
|
|
2026-05-19 14:52:54 +08:00
|
|
|
const response = await evaluationApi.generateDataset(props.databaseId, params)
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
if (response.message === 'success') {
|
2026-05-19 14:52:54 +08:00
|
|
|
message.success('生成任务已提交')
|
|
|
|
|
visible.value = false
|
|
|
|
|
resetForm()
|
2026-01-15 06:01:34 +08:00
|
|
|
emit('success')
|
2025-12-09 16:21:18 +08:00
|
|
|
} else {
|
2026-05-19 14:52:54 +08:00
|
|
|
generating.value = false
|
2026-01-15 06:01:34 +08:00
|
|
|
message.error(response.message || '生成失败')
|
2025-12-09 16:21:18 +08:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
console.error('生成失败:', error)
|
|
|
|
|
generating.value = false
|
2026-05-19 14:52:54 +08:00
|
|
|
message.error('生成失败')
|
2025-12-09 16:21:18 +08:00
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
}
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
// 取消操作
|
|
|
|
|
const handleCancel = () => {
|
2026-05-19 14:52:54 +08:00
|
|
|
if (generating.value) return
|
2026-01-15 06:01:34 +08:00
|
|
|
visible.value = false
|
|
|
|
|
resetForm()
|
|
|
|
|
}
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
// 重置表单
|
|
|
|
|
const resetForm = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
formRef.value?.resetFields()
|
2025-12-09 16:21:18 +08:00
|
|
|
Object.assign(formState, {
|
2026-05-06 22:12:09 +08:00
|
|
|
name: defaultBenchmarkName(),
|
2025-12-09 16:21:18 +08:00
|
|
|
description: '',
|
|
|
|
|
count: 10,
|
2026-05-06 22:12:09 +08:00
|
|
|
neighbors_count: 1,
|
2026-05-19 14:52:54 +08:00
|
|
|
concurrency_count: 10,
|
2026-05-06 22:12:09 +08:00
|
|
|
llm_model_spec: configStore.config?.default_model || ''
|
2026-01-15 06:01:34 +08:00
|
|
|
})
|
|
|
|
|
generating.value = false
|
|
|
|
|
}
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
// 选择LLM模型
|
|
|
|
|
const handleSelectLLMModel = (modelSpec) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
formState.llm_model_spec = modelSpec
|
|
|
|
|
}
|
2025-12-09 16:21:18 +08:00
|
|
|
|
|
|
|
|
// 监听visible变化
|
|
|
|
|
watch(visible, (val) => {
|
2026-05-19 14:52:54 +08:00
|
|
|
if (val && !generating.value) {
|
2026-01-15 06:01:34 +08:00
|
|
|
resetForm()
|
2025-12-09 16:21:18 +08:00
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
})
|
2025-12-09 16:21:18 +08:00
|
|
|
</script>
|