feat: 添加AI问题生成功能,支持配置生成数量并在前端展示生成的问题
This commit is contained in:
@@ -107,6 +107,10 @@ export interface KBModelConfigRequest {
|
||||
nodes: Node[]
|
||||
relations: Relation[]
|
||||
}
|
||||
questionGeneration?: {
|
||||
enabled: boolean
|
||||
questionCount: number
|
||||
}
|
||||
}
|
||||
|
||||
export function updateKBConfig(kbId: string, config: KBModelConfigRequest): Promise<any> {
|
||||
|
||||
@@ -185,6 +185,32 @@ const getChunkMeta = (item: any) => {
|
||||
return parts.join(' · ');
|
||||
};
|
||||
|
||||
// 解析生成的问题
|
||||
const getGeneratedQuestions = (item: any): string[] => {
|
||||
if (!item || !item.metadata) return [];
|
||||
try {
|
||||
const metadata = typeof item.metadata === 'string' ? JSON.parse(item.metadata) : item.metadata;
|
||||
return metadata.generated_questions || [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
// 展开状态管理
|
||||
const expandedChunks = ref<Set<number>>(new Set());
|
||||
|
||||
const toggleQuestions = (index: number) => {
|
||||
if (expandedChunks.value.has(index)) {
|
||||
expandedChunks.value.delete(index);
|
||||
} else {
|
||||
expandedChunks.value.add(index);
|
||||
}
|
||||
// 触发响应式更新
|
||||
expandedChunks.value = new Set(expandedChunks.value);
|
||||
};
|
||||
|
||||
const isExpanded = (index: number) => expandedChunks.value.has(index);
|
||||
|
||||
const downloadFile = () => {
|
||||
downKnowledgeDetails(props.details.id)
|
||||
.then((result) => {
|
||||
@@ -272,17 +298,44 @@ const handleDetailsScroll = () => {
|
||||
|
||||
<div v-if="details.md.length == 0" class="no_content">{{ $t('common.noData') }}</div>
|
||||
<div v-else class="chunk-list">
|
||||
<div
|
||||
class="chunk-item"
|
||||
<div class="chunk-item"
|
||||
v-for="(item, index) in details.md"
|
||||
:key="index"
|
||||
:class="getChunkClass(index)"
|
||||
>
|
||||
<div class="chunk-header">
|
||||
<span class="chunk-index">{{ $t('knowledgeBase.segment') || '片段' }} {{ index + 1 }}</span>
|
||||
<span class="chunk-meta">{{ getChunkMeta(item) }}</span>
|
||||
<div class="chunk-header-right">
|
||||
<t-tag
|
||||
v-if="getGeneratedQuestions(item).length > 0"
|
||||
size="small"
|
||||
theme="success"
|
||||
variant="light"
|
||||
>
|
||||
{{ $t('knowledgeBase.questions') || '问题' }} {{ getGeneratedQuestions(item).length }}
|
||||
</t-tag>
|
||||
<span class="chunk-meta">{{ getChunkMeta(item) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-content" v-html="processMarkdown(item.content)"></div>
|
||||
|
||||
<!-- 生成的问题展示 -->
|
||||
<div v-if="getGeneratedQuestions(item).length > 0" class="questions-section">
|
||||
<div class="questions-toggle" @click="toggleQuestions(index)">
|
||||
<t-icon :name="isExpanded(index) ? 'chevron-down' : 'chevron-right'" size="14px" />
|
||||
<span>{{ $t('knowledgeBase.generatedQuestions') || '生成的问题' }} ({{ getGeneratedQuestions(item).length }})</span>
|
||||
</div>
|
||||
<div v-show="isExpanded(index)" class="questions-list">
|
||||
<div
|
||||
v-for="(question, qIndex) in getGeneratedQuestions(item)"
|
||||
:key="qIndex"
|
||||
class="question-item"
|
||||
>
|
||||
<t-icon name="help-circle" size="14px" class="question-icon" />
|
||||
<span>{{ question }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -493,12 +546,65 @@ const handleDetailsScroll = () => {
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.chunk-header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.chunk-meta {
|
||||
color: #00000066;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
|
||||
// 生成的问题样式
|
||||
.questions-section {
|
||||
margin-top: 12px;
|
||||
padding-top: 10px;
|
||||
border-top: 1px dashed #e0e0e0;
|
||||
}
|
||||
|
||||
.questions-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
cursor: pointer;
|
||||
color: #059669;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
padding: 4px 0;
|
||||
transition: color 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
color: #07c05f;
|
||||
}
|
||||
}
|
||||
|
||||
.questions-list {
|
||||
margin-top: 8px;
|
||||
padding-left: 4px;
|
||||
}
|
||||
|
||||
.question-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
padding: 6px 8px;
|
||||
margin-bottom: 4px;
|
||||
background: #f0fdf4;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
color: #1d2129;
|
||||
line-height: 1.5;
|
||||
|
||||
.question-icon {
|
||||
color: #059669;
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.md-content {
|
||||
word-break: break-word;
|
||||
line-height: 1.6;
|
||||
|
||||
@@ -92,6 +92,8 @@ export default {
|
||||
createTime: 'Create Time',
|
||||
characters: 'chars',
|
||||
segment: 'Segment',
|
||||
questions: 'Questions',
|
||||
generatedQuestions: 'Generated Questions',
|
||||
notInitialized: 'Knowledge base is not initialized. Please configure models in settings before uploading files',
|
||||
getInfoFailed: 'Failed to get knowledge base information, file upload is not possible',
|
||||
missingId: 'Knowledge base ID is missing',
|
||||
@@ -1001,7 +1003,13 @@ export default {
|
||||
},
|
||||
advanced: {
|
||||
title: 'Advanced Settings',
|
||||
description: 'Configure multimodal features',
|
||||
description: 'Configure question generation, multimodal features',
|
||||
questionGeneration: {
|
||||
label: 'AI Question Generation',
|
||||
description: 'Generate related questions for each chunk using LLM during document parsing to improve retrieval recall. Enabling this will increase document parsing time.',
|
||||
countLabel: 'Question Count',
|
||||
countDescription: 'Number of questions to generate per document chunk (1-10)',
|
||||
},
|
||||
multimodal: {
|
||||
label: 'Multimodal Feature',
|
||||
description: 'Enable understanding of multimodal content such as images and videos',
|
||||
|
||||
@@ -92,6 +92,8 @@ export default {
|
||||
createTime: 'Время создания',
|
||||
characters: 'символов',
|
||||
segment: 'Фрагмент',
|
||||
questions: 'Вопросы',
|
||||
generatedQuestions: 'Сгенерированные вопросы',
|
||||
notInitialized: 'База знаний не инициализирована. Пожалуйста, настройте модели в разделе настроек перед загрузкой файлов',
|
||||
getInfoFailed: 'Не удалось получить информацию о базе знаний, загрузка файла невозможна',
|
||||
missingId: 'Отсутствует ID базы знаний',
|
||||
@@ -1095,7 +1097,13 @@ export default {
|
||||
},
|
||||
advanced: {
|
||||
title: 'Расширенные настройки',
|
||||
description: 'Настройте мультимодальные возможности',
|
||||
description: 'Настройте генерацию вопросов и мультимодальные возможности',
|
||||
questionGeneration: {
|
||||
label: 'AI генерация вопросов',
|
||||
description: 'Генерация связанных вопросов для каждого фрагмента с помощью LLM при парсинге документа для улучшения полноты поиска. Включение увеличит время парсинга документа.',
|
||||
countLabel: 'Количество вопросов',
|
||||
countDescription: 'Количество вопросов для генерации на фрагмент документа (1-10)',
|
||||
},
|
||||
multimodal: {
|
||||
label: 'Мультимодальная функция',
|
||||
description: 'Включите понимание мультимедийного контента, такого как изображения и видео',
|
||||
|
||||
@@ -91,6 +91,8 @@ export default {
|
||||
createTime: "创建时间",
|
||||
characters: "字符",
|
||||
segment: "片段",
|
||||
questions: "问题",
|
||||
generatedQuestions: "生成的问题",
|
||||
docActionUnsupported: "当前知识库类型不支持该操作",
|
||||
notInitialized:
|
||||
"该知识库尚未完成初始化配置,请先前往设置页面配置模型信息后再上传文件",
|
||||
@@ -1334,7 +1336,13 @@ export default {
|
||||
},
|
||||
advanced: {
|
||||
title: "高级设置",
|
||||
description: "配置多模态等高级功能",
|
||||
description: "配置问题生成、多模态等高级功能",
|
||||
questionGeneration: {
|
||||
label: "AI 问题生成",
|
||||
description: "解析文档时调用大模型为每个分块生成相关问题,提高检索召回率。启用后会增加文档解析耗时。",
|
||||
countLabel: "生成问题数量",
|
||||
countDescription: "每个文档分块生成的问题数量(1-10)",
|
||||
},
|
||||
multimodal: {
|
||||
label: "多模态功能",
|
||||
description: "启用图片、视频等多模态内容的理解能力",
|
||||
|
||||
@@ -144,8 +144,10 @@
|
||||
ref="advancedSettingsRef"
|
||||
v-if="formData"
|
||||
:multimodal="formData.multimodalConfig"
|
||||
:question-generation="formData.questionGenerationConfig"
|
||||
:all-models="allModels"
|
||||
@update:multimodal="handleMultimodalUpdate"
|
||||
@update:question-generation="handleQuestionGenerationUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -296,6 +298,10 @@ const initFormData = (type: 'document' | 'faq' = 'document') => {
|
||||
type: string
|
||||
}>
|
||||
},
|
||||
questionGenerationConfig: {
|
||||
enabled: false,
|
||||
questionCount: 3
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,6 +383,10 @@ const loadKBData = async () => {
|
||||
})),
|
||||
relations: kb.extract_config?.relations || []
|
||||
},
|
||||
questionGenerationConfig: {
|
||||
enabled: kb.question_generation_config?.enabled || false,
|
||||
questionCount: kb.question_generation_config?.question_count || 3
|
||||
},
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load knowledge base data:', error)
|
||||
@@ -406,6 +416,12 @@ const handleMultimodalUpdate = (config: any) => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleQuestionGenerationUpdate = (config: any) => {
|
||||
if (formData.value) {
|
||||
formData.value.questionGenerationConfig = { ...config }
|
||||
}
|
||||
}
|
||||
|
||||
const handleNodeExtractUpdate = (config: any) => {
|
||||
if (formData.value) {
|
||||
formData.value.nodeExtractConfig = { ...config }
|
||||
@@ -514,6 +530,14 @@ const buildSubmitData = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 添加问题生成配置
|
||||
if (formData.value.questionGenerationConfig?.enabled) {
|
||||
data.question_generation_config = {
|
||||
enabled: true,
|
||||
question_count: formData.value.questionGenerationConfig.questionCount || 3
|
||||
}
|
||||
}
|
||||
|
||||
if (formData.value.type === 'faq') {
|
||||
data.faq_config = {
|
||||
index_mode: formData.value.faqConfig?.indexMode || 'question_only',
|
||||
@@ -598,6 +622,10 @@ const handleSubmit = async () => {
|
||||
tags: data.extract_config?.tags || [],
|
||||
nodes: data.extract_config?.nodes || [],
|
||||
relations: data.extract_config?.relations || []
|
||||
},
|
||||
questionGeneration: {
|
||||
enabled: data.question_generation_config?.enabled || false,
|
||||
questionCount: data.question_generation_config?.question_count || 3
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,42 @@
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- Question Generation feature -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.questionGeneration.label') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.questionGeneration.description') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
v-model="localQuestionGeneration.enabled"
|
||||
@change="handleQuestionGenerationToggle"
|
||||
size="large"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Question Generation configuration -->
|
||||
<div v-if="localQuestionGeneration.enabled" class="subsection">
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.advanced.questionGeneration.countLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.advanced.questionGeneration.countDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input-number
|
||||
v-model="localQuestionGeneration.questionCount"
|
||||
:min="1"
|
||||
:max="10"
|
||||
:step="1"
|
||||
theme="normal"
|
||||
@change="handleQuestionGenerationChange"
|
||||
style="width: 120px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Multimodal feature -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
@@ -241,8 +277,14 @@ interface MultimodalConfig {
|
||||
}
|
||||
}
|
||||
|
||||
interface QuestionGenerationConfig {
|
||||
enabled: boolean
|
||||
questionCount: number
|
||||
}
|
||||
|
||||
interface Props {
|
||||
multimodal: MultimodalConfig
|
||||
questionGeneration?: QuestionGenerationConfig
|
||||
allModels?: any[]
|
||||
}
|
||||
|
||||
@@ -250,9 +292,13 @@ const props = defineProps<Props>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:multimodal': [value: MultimodalConfig]
|
||||
'update:questionGeneration': [value: QuestionGenerationConfig]
|
||||
}>()
|
||||
|
||||
const localMultimodal = ref<MultimodalConfig>({ ...props.multimodal })
|
||||
const localQuestionGeneration = ref<QuestionGenerationConfig>(
|
||||
props.questionGeneration || { enabled: false, questionCount: 3 }
|
||||
)
|
||||
|
||||
const vllmSelectorRef = ref()
|
||||
const isMinioEnabled = ref(false)
|
||||
@@ -287,6 +333,25 @@ watch(() => props.multimodal, (newVal) => {
|
||||
localMultimodal.value = { ...newVal }
|
||||
}, { deep: true })
|
||||
|
||||
watch(() => props.questionGeneration, (newVal) => {
|
||||
if (newVal) {
|
||||
localQuestionGeneration.value = { ...newVal }
|
||||
}
|
||||
}, { deep: true })
|
||||
|
||||
// Handle question generation toggle
|
||||
const handleQuestionGenerationToggle = () => {
|
||||
if (!localQuestionGeneration.value.enabled) {
|
||||
localQuestionGeneration.value.questionCount = 3
|
||||
}
|
||||
emit('update:questionGeneration', localQuestionGeneration.value)
|
||||
}
|
||||
|
||||
// Handle question generation config change
|
||||
const handleQuestionGenerationChange = () => {
|
||||
emit('update:questionGeneration', localQuestionGeneration.value)
|
||||
}
|
||||
|
||||
// Handle multimodal toggle
|
||||
const handleMultimodalToggle = () => {
|
||||
// Reset related configuration when multimodal is disabled
|
||||
|
||||
Reference in New Issue
Block a user