diff --git a/frontend/src/api/initialization/index.ts b/frontend/src/api/initialization/index.ts index ee0d7a5a..fb5718ba 100644 --- a/frontend/src/api/initialization/index.ts +++ b/frontend/src/api/initialization/index.ts @@ -213,6 +213,27 @@ export function checkRemoteModel(modelConfig: { }); } +// 测试 Embedding 模型(本地/远程)是否可用 +export function testEmbeddingModel(modelConfig: { + source: 'local' | 'remote'; + modelName: string; + baseUrl?: string; + apiKey?: string; + dimension?: number; +}): Promise<{ available: boolean; message?: string; dimension?: number }> { + return new Promise((resolve, reject) => { + post('/api/v1/initialization/embedding/test', modelConfig) + .then((response: any) => { + resolve(response.data || {}); + }) + .catch((error: any) => { + console.error('测试Embedding模型失败:', error); + reject(error); + }); + }); +} + + export function checkRerankModel(modelConfig: { modelName: string; baseUrl: string; diff --git a/frontend/src/views/initialization/InitializationConfig.vue b/frontend/src/views/initialization/InitializationConfig.vue index db04ad35..3a71413b 100644 --- a/frontend/src/views/initialization/InitializationConfig.vue +++ b/frontend/src/views/initialization/InitializationConfig.vue @@ -238,11 +238,23 @@
- +
+ + + 检测维度 + +
@@ -415,7 +427,7 @@
- @@ -512,7 +524,7 @@
- +
@@ -550,7 +562,7 @@
-
@@ -765,8 +777,9 @@ import { type DownloadTask, checkRerankModel, testMultimodalFunction, - listOllamaModels -} from '@/api/initialization'; + listOllamaModels, + testEmbeddingModel + } from '@/api/initialization'; const router = useRouter(); type TFormRef = { @@ -919,6 +932,9 @@ const multimodalTest = reactive({ const imageUpload = ref(null); +// Embedding 维度检测状态 +const embeddingDimDetecting = ref(false); + // 左侧导航区段 type Section = { id: string; label: string }; const sections: Section[] = [ @@ -2226,6 +2242,49 @@ const checkAllConfiguredModels = async () => { const onDimensionInput = (event: any) => { formData.embedding.dimension = Number(event.target.value); }; + +// 检测并自动填写 Embedding 维度 +const detectEmbeddingDimension = async () => { + if (hasFiles.value) return; + // 校验必填:模型来源 + 模型名称;若远程还需 BaseURL + const source = (formData.embedding.source || '').trim(); + const modelName = (formData.embedding.modelName || '').trim(); + const baseUrl = (formData.embedding.baseUrl || '').trim(); + + if (!source || !modelName || (source === 'remote' && !baseUrl)) { + // 触发对应字段校验提示 + const fields: string[] = ['embedding.source', 'embedding.modelName']; + if (source === 'remote') fields.push('embedding.baseUrl'); + try { await form.value?.validate(fields); } catch {} + MessagePlugin.warning('请先完整填写Embedding配置'); + return; + } + + embeddingDimDetecting.value = true; + try { + const res = await testEmbeddingModel({ + source: source as 'local' | 'remote', + modelName, + baseUrl: source === 'remote' ? baseUrl : undefined, + apiKey: formData.embedding.apiKey || undefined, + dimension: formData.embedding.dimension || undefined, + }); + const available = !!res.available; + const message = res.message || ''; + const dim = Number(res.dimension || 0); + if (available && dim > 0) { + formData.embedding.dimension = dim; + MessagePlugin.success(`检测成功,维度已自动填写为 ${dim}`); + } else { + MessagePlugin.error(message || '检测失败'); + } + } catch (e: any) { + const msg = e?.message || '检测失败,请检查配置'; + MessagePlugin.error(msg); + } finally { + embeddingDimDetecting.value = false; + } +};