Add /api/clear-references + ๐ ์ด๊ธฐํ button on right pane
Browse files- src/kpaa/server.py +31 -0
src/kpaa/server.py
CHANGED
|
@@ -619,6 +619,22 @@ def create_app() -> FastAPI:
|
|
| 619 |
async def api_last_refs() -> dict[str, Any]:
|
| 620 |
return dict(_last_refs)
|
| 621 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 622 |
@app.get("/api/chat")
|
| 623 |
async def api_chat(q: str = Query(..., min_length=1, max_length=2000)):
|
| 624 |
"""SSE: token + references + done events. EventSource ํธํ."""
|
|
@@ -796,6 +812,10 @@ _SPLIT_HTML = """<!doctype html>
|
|
| 796 |
<header class="right-header">
|
| 797 |
<h1>์ฐธ๊ณ ํ ์๋ฃ <span class="pulse" id="pulse"></span></h1>
|
| 798 |
<span class="muted" id="refs-count"></span>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 799 |
</header>
|
| 800 |
<div class="meta-line" id="meta">Open WebUI์์ ์ง๋ฌธํ๋ฉด LLM์ด ๋ณธ ๊ทผ๊ฑฐ๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค (1์ด๋ง๋ค ๊ฐฑ์ ).</div>
|
| 801 |
<div class="refs-list" id="refs">
|
|
@@ -911,6 +931,17 @@ async function poll() {
|
|
| 911 |
}
|
| 912 |
setInterval(poll, 1000);
|
| 913 |
poll();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 914 |
</script>
|
| 915 |
</body></html>"""
|
| 916 |
|
|
|
|
| 619 |
async def api_last_refs() -> dict[str, Any]:
|
| 620 |
return dict(_last_refs)
|
| 621 |
|
| 622 |
+
@app.post("/api/clear-references")
|
| 623 |
+
async def api_clear_refs() -> dict[str, str]:
|
| 624 |
+
"""์ฐ์ธก ์ฐธ๊ณ ์๋ฃ ํจ๋ ์ด๊ธฐํ โ Open WebUI ์ ์ฑํ
๋ฑ์์ ์ฌ์ฉ."""
|
| 625 |
+
_last_refs.update({
|
| 626 |
+
"ts": time.time(), # ๊ฐฑ์ ํด์ ํด๋ง์ด ๋ณ๊ฒฝ ๊ฐ์งํ๋๋ก
|
| 627 |
+
"query": "",
|
| 628 |
+
"intents": [],
|
| 629 |
+
"jo_targets": [],
|
| 630 |
+
"elapsed_ms": 0,
|
| 631 |
+
"excerpts": [],
|
| 632 |
+
"cited_citations": [],
|
| 633 |
+
"llm_excerpt_citations": [],
|
| 634 |
+
"geungeo_indices_in_answer": [],
|
| 635 |
+
})
|
| 636 |
+
return {"status": "cleared"}
|
| 637 |
+
|
| 638 |
@app.get("/api/chat")
|
| 639 |
async def api_chat(q: str = Query(..., min_length=1, max_length=2000)):
|
| 640 |
"""SSE: token + references + done events. EventSource ํธํ."""
|
|
|
|
| 812 |
<header class="right-header">
|
| 813 |
<h1>์ฐธ๊ณ ํ ์๋ฃ <span class="pulse" id="pulse"></span></h1>
|
| 814 |
<span class="muted" id="refs-count"></span>
|
| 815 |
+
<button id="clear-btn" title="์ ๊ฒ์ โ ์ฐ์ธก ์ฐธ๊ณ ์๋ฃ ์ด๊ธฐํ"
|
| 816 |
+
style="margin-left:auto; padding:4px 10px; border-radius:6px; border:1px solid var(--border); background:var(--card-bg); color:var(--text); cursor:pointer; font-size:0.78em;">
|
| 817 |
+
๐ ์ด๊ธฐํ
|
| 818 |
+
</button>
|
| 819 |
</header>
|
| 820 |
<div class="meta-line" id="meta">Open WebUI์์ ์ง๋ฌธํ๋ฉด LLM์ด ๋ณธ ๊ทผ๊ฑฐ๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค (1์ด๋ง๋ค ๊ฐฑ์ ).</div>
|
| 821 |
<div class="refs-list" id="refs">
|
|
|
|
| 931 |
}
|
| 932 |
setInterval(poll, 1000);
|
| 933 |
poll();
|
| 934 |
+
|
| 935 |
+
// ์ด๊ธฐํ ๋ฒํผ โ ๋ฐฑ์๋์ _last_refs ๋ฅผ ๋น์ฐ๊ณ ์ฐ์ธก ํจ๋ ์ฆ์ ๋น์.
|
| 936 |
+
document.getElementById("clear-btn").addEventListener("click", async () => {
|
| 937 |
+
try {
|
| 938 |
+
await fetch("/api/clear-references", { method: "POST", cache: "no-store" });
|
| 939 |
+
} catch (_) {}
|
| 940 |
+
// ์ฆ์ UI ๋น์ฐ๊ธฐ (๋ค์ polling ์ผ๋ก๋ ์ ๋น ๋ฐ์ดํฐ ๋์ฐฉ)
|
| 941 |
+
refsEl.innerHTML = '<div class="refs-empty">์ ๊ฒ์ ๋๊ธฐ ์คโฆ</div>';
|
| 942 |
+
refsCountEl.textContent = "";
|
| 943 |
+
metaEl.textContent = "Open WebUI์์ ์ง๋ฌธํ๋ฉด LLM์ด ๋ณธ ๊ทผ๊ฑฐ๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค.";
|
| 944 |
+
});
|
| 945 |
</script>
|
| 946 |
</body></html>"""
|
| 947 |
|