settings.js
3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 设置:运行参数 + 本体类型编辑
window.SettingsView = (function(){
const LABELS={
QWEN_MODEL:"对话模型", EMBED_MODEL:"向量模型", EMBED_DIM:"向量维度",
LLM_BASE_URL:"OpenAI兼容地址(留空=用DashScope)",
CHUNK_SIZE:"分块大小(字符)", CHUNK_OVERLAP:"分块重叠(字符)", GLEANING_ROUNDS:"补抽轮数",
EXTRACT_CONCURRENCY:"抽取并发数(并行调用LLM,加速核心)", EMBED_CONCURRENCY:"向量化并发批数",
MAX_HOPS:"单轮最大跳数", MAX_ROUNDS:"深挖最大轮数", TOP_K:"每轮证据条数",
HYBRID_ALPHA:"向量权重(0-1,其余为BM25)", SIM_THRESHOLD:"实体合并相似度阈值",
LINK_THRESHOLD:"实体链接最低分", THEME:"主题"
};
const ORDER=["QWEN_MODEL","EMBED_MODEL","EMBED_DIM","LLM_BASE_URL","CHUNK_SIZE","CHUNK_OVERLAP",
"GLEANING_ROUNDS","EXTRACT_CONCURRENCY","EMBED_CONCURRENCY","MAX_HOPS","MAX_ROUNDS","TOP_K",
"HYBRID_ALPHA","SIM_THRESHOLD","LINK_THRESHOLD","THEME"];
async function load(){
const cfg=await OT.api("/api/config");
const form=document.getElementById("config-form"); form.innerHTML="";
ORDER.forEach(k=>{
if(cfg[k]===undefined) return;
const div=document.createElement("div");
div.innerHTML=`<label>${LABELS[k]||k}</label><input type="text" data-key="${k}" value="${OT.esc(cfg[k])}"/>`;
form.appendChild(div);
});
const onto=await OT.api("/api/ontology");
document.getElementById("entity-types").value=(onto.entity_types||[]).join("\n");
document.getElementById("relation-types").value=(onto.relation_types||[]).join("\n");
}
function parseList(s){ return s.split(/[\n,,、]/).map(x=>x.trim()).filter(Boolean); }
document.getElementById("btn-save-config").addEventListener("click",async()=>{
const items={}; document.querySelectorAll("#config-form input").forEach(i=>items[i.dataset.key]=i.value);
const hint=document.getElementById("config-hint"); hint.textContent="保存中…";
try{ await OT.api("/api/config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({items})});
hint.textContent="已保存 ✓(下次抽取/检索生效)"; if(window.loadInfo) loadInfo(); }
catch(e){ hint.textContent="保存失败:"+e.message; }
});
document.getElementById("btn-save-ontology").addEventListener("click",async()=>{
const payload={entity_types:parseList(document.getElementById("entity-types").value),
relation_types:parseList(document.getElementById("relation-types").value)};
const hint=document.getElementById("ontology-hint"); hint.textContent="保存中…";
try{ await OT.api("/api/ontology",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(payload)});
hint.textContent="已保存 ✓"; }catch(e){ hint.textContent="保存失败:"+e.message; }
});
document.getElementById("btn-clear-graph").addEventListener("click",async()=>{
if(!confirm("确定清空当前图谱与索引?(不删除 MySQL 文档记录)")) return;
await OT.api("/api/graph/clear",{method:"POST"});
if(window.GraphView) window.GraphView.markDirty();
if(window.loadInfo) loadInfo();
alert("已清空。");
});
return { load };
})();