Страница /ask.html: поле ввода, примеры запросов, ответ агента с пояснением «понял так». Запрос идёт в GET /ask, ядро подгружает модуль агента и выполняет его. Критичная правка: ядро было однопоточным (HTTPServer). Агент вызывает ядро по HTTP изнутри обработчика — сервер ждал сам себя, соединения копились (Recv-Q 6), все запросы отдавали 000. Переведено на ThreadingHTTPServer. На панели появились ссылки на интерактивный граф и страницу агента.
91 lines
3.8 KiB
HTML
91 lines
3.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Агент по медиатеке</title>
|
|
<style>
|
|
:root { --bg:#0d1117; --fg:#c9d1d9; --dim:#8b949e; --line:#30363d; --acc:#58a6ff; }
|
|
* { box-sizing: border-box; }
|
|
body { margin:0; background:var(--bg); color:var(--fg);
|
|
font:15px/1.6 -apple-system,"Segoe UI",Roboto,sans-serif; }
|
|
.wrap { max-width:820px; margin:0 auto; padding:32px 20px 80px; }
|
|
h1 { font-size:20px; margin:0 0 6px; }
|
|
.sub { color:var(--dim); font-size:13px; margin-bottom:24px; }
|
|
form { display:flex; gap:10px; }
|
|
input[type=text] { flex:1; background:#161b22; border:1px solid var(--line);
|
|
color:var(--fg); border-radius:8px; padding:12px 14px; font-size:15px; outline:none; }
|
|
input[type=text]:focus { border-color:var(--acc); }
|
|
button { background:var(--acc); color:#0d1117; border:0; border-radius:8px;
|
|
padding:12px 20px; font-size:15px; font-weight:600; cursor:pointer; }
|
|
button:disabled { opacity:.5; cursor:default; }
|
|
.chips { display:flex; flex-wrap:wrap; gap:8px; margin:14px 0 26px; }
|
|
.chip { background:#161b22; border:1px solid var(--line); color:var(--dim);
|
|
border-radius:999px; padding:6px 12px; font-size:13px; cursor:pointer; }
|
|
.chip:hover { border-color:var(--acc); color:var(--fg); }
|
|
#out { margin-top:8px; }
|
|
.card { background:#161b22; border:1px solid var(--line); border-radius:10px;
|
|
padding:16px 18px; margin-bottom:14px; }
|
|
.plan { color:var(--dim); font-size:12px; margin-top:10px;
|
|
border-top:1px dashed var(--line); padding-top:10px; }
|
|
pre { margin:0; white-space:pre-wrap; font-family:inherit; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="wrap">
|
|
<h1>Агент по медиатеке</h1>
|
|
<div class="sub">Понимает вопрос словами и отвечает по графу контента</div>
|
|
<form id="f">
|
|
<input id="q" type="text" placeholder="например: фильмы Нолана про космос с высоким рейтингом" autofocus>
|
|
<button id="b">Спросить</button>
|
|
</form>
|
|
<div class="chips" id="chips"></div>
|
|
<div id="out"></div>
|
|
</div>
|
|
<script>
|
|
const EXAMPLES = [
|
|
"фильмы Нолана",
|
|
"когда были фильмы про искусственный интеллект",
|
|
"похоже на Дюну",
|
|
"высокорейтинговые фильмы 80-х",
|
|
"фильмография Keanu Reeves",
|
|
"настроение эпичное",
|
|
"что экранизировали у Frank Herbert"
|
|
];
|
|
|
|
const chips = document.getElementById("chips");
|
|
EXAMPLES.forEach(t => {
|
|
const el = document.createElement("span");
|
|
el.className = "chip"; el.textContent = t;
|
|
el.onclick = () => { document.getElementById("q").value = t; ask(); };
|
|
chips.appendChild(el);
|
|
});
|
|
|
|
const out = document.getElementById("out");
|
|
const btn = document.getElementById("b");
|
|
document.getElementById("f").addEventListener("submit", e => { e.preventDefault(); ask(); });
|
|
|
|
async function ask(){
|
|
const q = document.getElementById("q").value.trim();
|
|
if (!q) return;
|
|
btn.disabled = true;
|
|
out.innerHTML = '<div class="card" style="color:#8b949e">думаю…</div>';
|
|
try {
|
|
const r = await fetch("ask?q=" + encodeURIComponent(q));
|
|
const d = await r.json();
|
|
if (d.error) throw new Error(d.error);
|
|
out.innerHTML = '<div class="card"><pre>' + escapeHtml(d.answer || "") +
|
|
'</pre><div class="plan">понял так: ' + escapeHtml(d.plan || "") + '</div></div>';
|
|
} catch (e) {
|
|
out.innerHTML = '<div class="card" style="color:#f85149">Ошибка: ' + escapeHtml(String(e)) + '</div>';
|
|
} finally { btn.disabled = false; }
|
|
}
|
|
|
|
function escapeHtml(s){
|
|
return String(s).replace(/[&<>]/g, c => ({"&":"&","<":"<",">":">"}[c]))
|
|
.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>');
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|