feat: 嵌入模型下拉仅显示 embedding 模型
This commit is contained in:
+12
-31
@@ -291,7 +291,7 @@ async function handleDocUpload(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 填充嵌入模型下拉
|
* 填充嵌入模型下拉(仅显示嵌入模型)
|
||||||
*/
|
*/
|
||||||
async function populateEmbedModels() {
|
async function populateEmbedModels() {
|
||||||
const select = document.querySelector('#selectEmbedModel');
|
const select = document.querySelector('#selectEmbedModel');
|
||||||
@@ -302,41 +302,22 @@ async function populateEmbedModels() {
|
|||||||
const data = await api.listModels();
|
const data = await api.listModels();
|
||||||
select.innerHTML = '<option value="">选择嵌入模型...</option>';
|
select.innerHTML = '<option value="">选择嵌入模型...</option>';
|
||||||
if (data.models) {
|
if (data.models) {
|
||||||
// 推荐的嵌入模型优先显示
|
const embedKeywords = ['embed', 'nomic', 'mxbai', 'bge', 'e5', 'snowflake', 'arctic'];
|
||||||
const embedKeywords = ['embed', 'nomic', 'mxbai', 'bge', 'e5', 'snowflake'];
|
const embedModels = data.models.filter(m =>
|
||||||
const recommended = [];
|
embedKeywords.some(kw => m.name.toLowerCase().includes(kw))
|
||||||
const others = [];
|
);
|
||||||
|
|
||||||
for (const m of data.models) {
|
embedModels.forEach(m => {
|
||||||
const name = m.name.toLowerCase();
|
|
||||||
if (embedKeywords.some(kw => name.includes(kw))) {
|
|
||||||
recommended.push(m);
|
|
||||||
} else {
|
|
||||||
others.push(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (recommended.length > 0) {
|
|
||||||
const optgroup = document.createElement('optgroup');
|
|
||||||
optgroup.label = '推荐(嵌入模型)';
|
|
||||||
recommended.forEach(m => {
|
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
opt.value = m.name;
|
opt.value = m.name;
|
||||||
opt.textContent = m.name;
|
const size = m.size ? ` (${formatSize(m.size)})` : '';
|
||||||
optgroup.appendChild(opt);
|
opt.textContent = m.name + size;
|
||||||
|
select.appendChild(opt);
|
||||||
});
|
});
|
||||||
select.appendChild(optgroup);
|
|
||||||
}
|
|
||||||
|
|
||||||
const optgroup2 = document.createElement('optgroup');
|
if (embedModels.length === 0) {
|
||||||
optgroup2.label = '其他模型';
|
select.innerHTML = '<option value="">未检测到嵌入模型,请先 ollama pull</option>';
|
||||||
others.forEach(m => {
|
}
|
||||||
const opt = document.createElement('option');
|
|
||||||
opt.value = m.name;
|
|
||||||
opt.textContent = m.name;
|
|
||||||
optgroup2.appendChild(opt);
|
|
||||||
});
|
|
||||||
select.appendChild(optgroup2);
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('[KB] 加载模型列表失败:', err);
|
console.warn('[KB] 加载模型列表失败:', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user