316 lines
7.9 KiB
HTML
316 lines
7.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Sechenov — Claude Chat</title>
|
|
<style>
|
|
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
background: #0f0f0f;
|
|
color: #e8e8e8;
|
|
height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
header {
|
|
padding: 12px 20px;
|
|
border-bottom: 1px solid #222;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 16px;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
header h1 { font-size: 16px; font-weight: 600; color: #fff; }
|
|
|
|
select {
|
|
background: #1e1e1e;
|
|
border: 1px solid #333;
|
|
color: #e8e8e8;
|
|
padding: 5px 10px;
|
|
border-radius: 6px;
|
|
font-size: 13px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
select:focus { outline: none; border-color: #555; }
|
|
|
|
#status {
|
|
margin-left: auto;
|
|
font-size: 12px;
|
|
color: #666;
|
|
}
|
|
|
|
main {
|
|
flex: 1;
|
|
display: flex;
|
|
gap: 0;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.pane {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.pane + .pane { border-left: 1px solid #222; }
|
|
|
|
.pane-label {
|
|
padding: 8px 16px;
|
|
font-size: 11px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.08em;
|
|
color: #555;
|
|
border-bottom: 1px solid #1a1a1a;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
textarea {
|
|
flex: 1;
|
|
background: #0f0f0f;
|
|
color: #e8e8e8;
|
|
border: none;
|
|
padding: 16px;
|
|
font-size: 14px;
|
|
line-height: 1.6;
|
|
resize: none;
|
|
font-family: inherit;
|
|
}
|
|
|
|
textarea:focus { outline: none; }
|
|
textarea::placeholder { color: #444; }
|
|
|
|
#output {
|
|
flex: 1;
|
|
padding: 16px;
|
|
overflow-y: auto;
|
|
font-size: 14px;
|
|
line-height: 1.7;
|
|
white-space: pre-wrap;
|
|
word-break: break-word;
|
|
color: #d4d4d4;
|
|
}
|
|
|
|
#output.empty { color: #444; font-style: italic; }
|
|
|
|
footer {
|
|
padding: 12px 20px;
|
|
border-top: 1px solid #222;
|
|
display: flex;
|
|
gap: 10px;
|
|
align-items: center;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
button {
|
|
padding: 8px 20px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: background 0.15s;
|
|
}
|
|
|
|
#sendBtn {
|
|
background: #2563eb;
|
|
color: #fff;
|
|
}
|
|
|
|
#sendBtn:hover { background: #1d4ed8; }
|
|
#sendBtn:disabled { background: #1e3a5f; color: #5a7fa8; cursor: not-allowed; }
|
|
|
|
#clearBtn {
|
|
background: #1e1e1e;
|
|
color: #999;
|
|
border: 1px solid #333;
|
|
}
|
|
|
|
#clearBtn:hover { background: #252525; }
|
|
|
|
.spinner {
|
|
display: none;
|
|
width: 14px; height: 14px;
|
|
border: 2px solid #333;
|
|
border-top-color: #2563eb;
|
|
border-radius: 50%;
|
|
animation: spin 0.7s linear infinite;
|
|
}
|
|
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
|
|
.loading .spinner { display: inline-block; }
|
|
|
|
/* Markdown-like rendering */
|
|
#output code {
|
|
background: #1a1a1a;
|
|
padding: 1px 5px;
|
|
border-radius: 3px;
|
|
font-family: 'Fira Code', 'Consolas', monospace;
|
|
font-size: 13px;
|
|
color: #ce9178;
|
|
}
|
|
|
|
#output pre {
|
|
background: #1a1a1a;
|
|
border: 1px solid #2a2a2a;
|
|
border-radius: 6px;
|
|
padding: 12px;
|
|
overflow-x: auto;
|
|
margin: 8px 0;
|
|
}
|
|
|
|
#output pre code {
|
|
background: none;
|
|
padding: 0;
|
|
color: #d4d4d4;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<h1>Claude Chat</h1>
|
|
<select id="modelSel">
|
|
<option value="sonnet">Sonnet 4.6</option>
|
|
<option value="haiku">Haiku 4.5</option>
|
|
</select>
|
|
<span id="status"></span>
|
|
</header>
|
|
|
|
<main>
|
|
<div class="pane">
|
|
<div class="pane-label">Запрос</div>
|
|
<textarea id="input" placeholder="Вставьте текст сюда..."></textarea>
|
|
</div>
|
|
<div class="pane">
|
|
<div class="pane-label">Ответ</div>
|
|
<div id="output" class="empty">Ответ появится здесь...</div>
|
|
</div>
|
|
</main>
|
|
|
|
<footer>
|
|
<button id="sendBtn">Отправить</button>
|
|
<button id="clearBtn">Очистить</button>
|
|
<div class="spinner" id="spinner"></div>
|
|
<span id="timer" style="margin-left:4px;font-size:12px;color:#555;"></span>
|
|
</footer>
|
|
|
|
<script>
|
|
const inputEl = document.getElementById('input');
|
|
const outputEl = document.getElementById('output');
|
|
const sendBtn = document.getElementById('sendBtn');
|
|
const clearBtn = document.getElementById('clearBtn');
|
|
const modelSel = document.getElementById('modelSel');
|
|
const statusEl = document.getElementById('status');
|
|
const spinnerEl = document.getElementById('spinner');
|
|
const timerEl = document.getElementById('timer');
|
|
|
|
let timerInterval = null;
|
|
let startTime = null;
|
|
|
|
function setLoading(on) {
|
|
sendBtn.disabled = on;
|
|
spinnerEl.style.display = on ? 'inline-block' : 'none';
|
|
if (on) {
|
|
startTime = Date.now();
|
|
timerInterval = setInterval(() => {
|
|
timerEl.textContent = ((Date.now() - startTime) / 1000).toFixed(1) + 's';
|
|
}, 100);
|
|
} else {
|
|
clearInterval(timerInterval);
|
|
}
|
|
}
|
|
|
|
function renderMarkdown(text) {
|
|
// Simple: escape html, then apply basic markdown
|
|
let html = text
|
|
.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
|
|
// Code blocks
|
|
html = html.replace(/```[\w]*\n?([\s\S]*?)```/g, (_, code) =>
|
|
`<pre><code>${code.trim()}</code></pre>`);
|
|
// Inline code
|
|
html = html.replace(/`([^`]+)`/g, '<code>$1</code>');
|
|
// Bold
|
|
html = html.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
|
|
|
return html;
|
|
}
|
|
|
|
async function send() {
|
|
const text = inputEl.value.trim();
|
|
if (!text) return;
|
|
|
|
outputEl.className = '';
|
|
outputEl.innerHTML = '';
|
|
setLoading(true);
|
|
statusEl.textContent = 'Генерирую...';
|
|
|
|
let fullText = '';
|
|
|
|
try {
|
|
const resp = await fetch('/api/chat', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ text, model: modelSel.value }),
|
|
});
|
|
|
|
const reader = resp.body.getReader();
|
|
const decoder = new TextDecoder();
|
|
let buf = '';
|
|
|
|
while (true) {
|
|
const { done, value } = await reader.read();
|
|
if (done) break;
|
|
buf += decoder.decode(value, { stream: true });
|
|
|
|
const parts = buf.split('\n\n');
|
|
buf = parts.pop();
|
|
|
|
for (const part of parts) {
|
|
if (!part.startsWith('data: ')) continue;
|
|
const raw = part.slice(6).trim();
|
|
if (raw === '[DONE]') continue;
|
|
try {
|
|
const obj = JSON.parse(raw);
|
|
if (obj.error) {
|
|
outputEl.innerHTML += `<span style="color:#f87171">${obj.error}</span>`;
|
|
} else if (obj.text) {
|
|
fullText += obj.text;
|
|
outputEl.innerHTML = renderMarkdown(fullText);
|
|
outputEl.scrollTop = outputEl.scrollHeight;
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
outputEl.innerHTML = `<span style="color:#f87171">Ошибка: ${e.message}</span>`;
|
|
} finally {
|
|
setLoading(false);
|
|
statusEl.textContent = fullText ? `${fullText.length} символов` : '';
|
|
}
|
|
}
|
|
|
|
sendBtn.addEventListener('click', send);
|
|
|
|
inputEl.addEventListener('keydown', (e) => {
|
|
if (e.ctrlKey && e.key === 'Enter') send();
|
|
});
|
|
|
|
clearBtn.addEventListener('click', () => {
|
|
inputEl.value = '';
|
|
outputEl.innerHTML = 'Ответ появится здесь...';
|
|
outputEl.className = 'empty';
|
|
statusEl.textContent = '';
|
|
timerEl.textContent = '';
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|