fix: 嵌入模型检测改用 /api/show capabilities 判断

This commit is contained in:
thzxx
2026-04-04 23:24:16 +08:00
parent 582661146b
commit ebaacb5631
+17 -6
View File
@@ -291,7 +291,7 @@ async function handleDocUpload(e) {
}
/**
* 填充嵌入模型下拉(仅显示嵌入模型
* 填充嵌入模型下拉(通过 /api/show 检测 embedding 能力
*/
async function populateEmbedModels() {
const select = document.querySelector('#selectEmbedModel');
@@ -301,12 +301,24 @@ async function populateEmbedModels() {
try {
const data = await api.listModels();
select.innerHTML = '<option value="">选择嵌入模型...</option>';
if (data.models) {
const embedKeywords = ['embed', 'nomic', 'mxbai', 'bge', 'e5', 'snowflake', 'arctic'];
const embedModels = data.models.filter(m =>
embedKeywords.some(kw => m.name.toLowerCase().includes(kw))
if (!data.models || data.models.length === 0) {
select.innerHTML = '<option value="">未安装任何模型</option>';
return;
}
// 并发检测每个模型的 capabilities
const checks = await Promise.allSettled(
data.models.map(async (m) => {
const info = await api.showModel(m.name);
const caps = info.capabilities || [];
return { name: m.name, size: m.size, isEmbed: caps.includes('embedding') };
})
);
const embedModels = checks
.filter(r => r.status === 'fulfilled' && r.value.isEmbed)
.map(r => r.value);
embedModels.forEach(m => {
const opt = document.createElement('option');
opt.value = m.name;
@@ -318,7 +330,6 @@ async function populateEmbedModels() {
if (embedModels.length === 0) {
select.innerHTML = '<option value="">未检测到嵌入模型,请先 ollama pull</option>';
}
}
} catch (err) {
console.warn('[KB] 加载模型列表失败:', err);
}