mirror of
https://github.com/hwanny1128/HGZero.git
synced 2026-06-13 00:09:10 +00:00
feat: 실시간 용어설명 조회 기능 추가
This commit is contained in:
@@ -0,0 +1,573 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>SSE 용어 검색 테스트</title>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
padding: 20px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 2em;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.controls {
|
||||
padding: 30px;
|
||||
border-bottom: 2px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.input-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.input-group input {
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 2px solid #e0e0e0;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.input-group input:focus {
|
||||
outline: none;
|
||||
border-color: #667eea;
|
||||
}
|
||||
|
||||
.button-group {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
button {
|
||||
flex: 1;
|
||||
padding: 12px 24px;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.btn-connect {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-connect:hover {
|
||||
background: #5568d3;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
||||
}
|
||||
|
||||
.btn-disconnect {
|
||||
background: #f44336;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-disconnect:hover {
|
||||
background: #da190b;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(244, 67, 54, 0.4);
|
||||
}
|
||||
|
||||
.btn-clear {
|
||||
background: #9e9e9e;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-clear:hover {
|
||||
background: #757575;
|
||||
}
|
||||
|
||||
.btn-check {
|
||||
background: #2196f3;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-check:hover {
|
||||
background: #0d47a1;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(33, 150, 243, 0.4);
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
transform: none !important;
|
||||
}
|
||||
|
||||
.status {
|
||||
padding: 20px 30px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: #f8f9fa;
|
||||
border-bottom: 2px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.status-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.status-indicator {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
.status-indicator.connected {
|
||||
background: #4caf50;
|
||||
}
|
||||
|
||||
.status-indicator.disconnected {
|
||||
background: #f44336;
|
||||
animation: none;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.5; }
|
||||
}
|
||||
|
||||
.content {
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
.results {
|
||||
max-height: 500px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
padding: 20px;
|
||||
margin-bottom: 15px;
|
||||
border-radius: 8px;
|
||||
background: #f8f9fa;
|
||||
border-left: 4px solid #667eea;
|
||||
animation: slideIn 0.3s ease-out;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-20px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
.result-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.result-time {
|
||||
color: #666;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.result-text {
|
||||
color: #333;
|
||||
margin-bottom: 15px;
|
||||
padding: 10px;
|
||||
background: white;
|
||||
border-radius: 5px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.terms {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.term-card {
|
||||
padding: 15px;
|
||||
background: white;
|
||||
border-radius: 5px;
|
||||
border: 1px solid #e0e0e0;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.term-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.term-name {
|
||||
font-weight: 600;
|
||||
color: #667eea;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.term-definition {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.term-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.term-category {
|
||||
background: #667eea;
|
||||
color: white;
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.term-score {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 60px 20px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.empty-state svg {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
margin-bottom: 20px;
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
.log-item {
|
||||
padding: 8px 12px;
|
||||
margin-bottom: 5px;
|
||||
border-radius: 4px;
|
||||
font-size: 13px;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
.log-connected {
|
||||
background: #e8f5e9;
|
||||
color: #2e7d32;
|
||||
}
|
||||
|
||||
.log-term-result {
|
||||
background: #e3f2fd;
|
||||
color: #1565c0;
|
||||
}
|
||||
|
||||
.log-heartbeat {
|
||||
background: #f3e5f5;
|
||||
color: #7b1fa2;
|
||||
}
|
||||
|
||||
.log-error {
|
||||
background: #ffebee;
|
||||
color: #c62828;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🔍 SSE 용어 검색 테스트</h1>
|
||||
<p>실시간 용어 검색 결과를 확인하세요</p>
|
||||
</div>
|
||||
|
||||
<div class="controls">
|
||||
<div class="input-group">
|
||||
<label for="serverUrl">RAG 서버 URL</label>
|
||||
<input type="text" id="serverUrl" value="http://localhost:8000" placeholder="http://localhost:8000">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<label for="sessionId">세션 ID (Meeting ID)</label>
|
||||
<input type="text" id="sessionId" value="meeting-124" placeholder="meeting-124">
|
||||
</div>
|
||||
<div class="button-group">
|
||||
<button class="btn-connect" onclick="connect()">🔌 연결</button>
|
||||
<button class="btn-disconnect" onclick="disconnect()" disabled>🔌 연결 해제</button>
|
||||
<button class="btn-check" onclick="checkStatus()">🔍 연결 상태 확인</button>
|
||||
<button class="btn-clear" onclick="clearResults()">🗑️ 결과 지우기</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status">
|
||||
<div class="status-item">
|
||||
<span class="status-indicator disconnected" id="statusIndicator"></span>
|
||||
<span id="statusText">연결 안됨</span>
|
||||
</div>
|
||||
<div class="status-item">
|
||||
<span>수신: <strong id="messageCount">0</strong>개</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
<h2 style="margin-bottom: 20px;">📊 용어 검색 결과</h2>
|
||||
<div class="results" id="results">
|
||||
<div class="empty-state">
|
||||
<svg viewBox="0 0 24 24" fill="currentColor">
|
||||
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/>
|
||||
</svg>
|
||||
<p>연결 후 용어 검색 결과가 여기에 표시됩니다</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 style="margin: 30px 0 20px 0;">📝 로그</h2>
|
||||
<div class="results" id="logs" style="max-height: 200px;">
|
||||
<div class="empty-state" style="padding: 30px;">
|
||||
<p>로그가 여기에 표시됩니다</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let eventSource = null;
|
||||
let messageCount = 0;
|
||||
|
||||
function connect() {
|
||||
const serverUrl = document.getElementById('serverUrl').value;
|
||||
const sessionId = document.getElementById('sessionId').value;
|
||||
|
||||
if (!serverUrl || !sessionId) {
|
||||
alert('서버 URL과 세션 ID를 입력해주세요');
|
||||
return;
|
||||
}
|
||||
|
||||
const url = `${serverUrl}/api/rag/terms/stream/${sessionId}`;
|
||||
|
||||
addLog('연결 시도 중...', 'connected');
|
||||
|
||||
eventSource = new EventSource(url);
|
||||
|
||||
// 연결 성공
|
||||
eventSource.addEventListener('connected', (e) => {
|
||||
const data = JSON.parse(e.data);
|
||||
updateStatus(true);
|
||||
addLog(`연결 성공: ${JSON.stringify(data)}`, 'connected');
|
||||
});
|
||||
|
||||
// 용어 검색 결과 수신
|
||||
eventSource.addEventListener('term_result', (e) => {
|
||||
const data = JSON.parse(e.data);
|
||||
messageCount++;
|
||||
document.getElementById('messageCount').textContent = messageCount;
|
||||
addResult(data);
|
||||
addLog(`용어 결과 수신: ${data.total_count}개`, 'term-result');
|
||||
});
|
||||
|
||||
// Heartbeat
|
||||
eventSource.addEventListener('heartbeat', (e) => {
|
||||
addLog('Heartbeat 수신', 'heartbeat');
|
||||
});
|
||||
|
||||
// 에러 처리
|
||||
eventSource.onerror = (error) => {
|
||||
console.error('SSE 에러:', error);
|
||||
addLog('연결 에러 발생', 'error');
|
||||
updateStatus(false);
|
||||
};
|
||||
|
||||
// UI 업데이트
|
||||
document.querySelector('.btn-connect').disabled = true;
|
||||
document.querySelector('.btn-disconnect').disabled = false;
|
||||
}
|
||||
|
||||
function disconnect() {
|
||||
if (eventSource) {
|
||||
eventSource.close();
|
||||
eventSource = null;
|
||||
updateStatus(false);
|
||||
addLog('연결 해제됨', 'error');
|
||||
}
|
||||
|
||||
document.querySelector('.btn-connect').disabled = false;
|
||||
document.querySelector('.btn-disconnect').disabled = true;
|
||||
}
|
||||
|
||||
function updateStatus(connected) {
|
||||
const indicator = document.getElementById('statusIndicator');
|
||||
const text = document.getElementById('statusText');
|
||||
|
||||
if (connected) {
|
||||
indicator.className = 'status-indicator connected';
|
||||
text.textContent = '연결됨';
|
||||
} else {
|
||||
indicator.className = 'status-indicator disconnected';
|
||||
text.textContent = '연결 안됨';
|
||||
}
|
||||
}
|
||||
|
||||
function addResult(data) {
|
||||
const resultsDiv = document.getElementById('results');
|
||||
|
||||
// 빈 상태 제거
|
||||
const emptyState = resultsDiv.querySelector('.empty-state');
|
||||
if (emptyState) {
|
||||
emptyState.remove();
|
||||
}
|
||||
|
||||
const resultItem = document.createElement('div');
|
||||
resultItem.className = 'result-item';
|
||||
|
||||
const now = new Date().toLocaleTimeString('ko-KR');
|
||||
|
||||
let termsHtml = '';
|
||||
if (data.terms && data.terms.length > 0) {
|
||||
termsHtml = '<div class="terms">';
|
||||
data.terms.forEach(term => {
|
||||
termsHtml += `
|
||||
<div class="term-card">
|
||||
<div class="term-name">${term.term_name}</div>
|
||||
<div class="term-definition">${term.definition}</div>
|
||||
<div class="term-meta">
|
||||
<span class="term-category">${term.category}</span>
|
||||
<span class="term-score">점수: ${term.relevance_score.toFixed(3)}</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
termsHtml += '</div>';
|
||||
} else {
|
||||
termsHtml = '<p style="color: #999;">매칭되는 용어가 없습니다</p>';
|
||||
}
|
||||
|
||||
resultItem.innerHTML = `
|
||||
<div class="result-header">
|
||||
<strong>세그먼트: ${data.segment_id}</strong>
|
||||
<span class="result-time">${now}</span>
|
||||
</div>
|
||||
<div class="result-text">"${data.text}..."</div>
|
||||
${termsHtml}
|
||||
`;
|
||||
|
||||
resultsDiv.insertBefore(resultItem, resultsDiv.firstChild);
|
||||
}
|
||||
|
||||
function addLog(message, type) {
|
||||
const logsDiv = document.getElementById('logs');
|
||||
|
||||
// 빈 상태 제거
|
||||
const emptyState = logsDiv.querySelector('.empty-state');
|
||||
if (emptyState) {
|
||||
emptyState.remove();
|
||||
}
|
||||
|
||||
const logItem = document.createElement('div');
|
||||
logItem.className = `log-item log-${type}`;
|
||||
|
||||
const now = new Date().toLocaleTimeString('ko-KR');
|
||||
logItem.textContent = `[${now}] ${message}`;
|
||||
|
||||
logsDiv.insertBefore(logItem, logsDiv.firstChild);
|
||||
|
||||
// 최대 50개까지만 유지
|
||||
while (logsDiv.children.length > 50) {
|
||||
logsDiv.removeChild(logsDiv.lastChild);
|
||||
}
|
||||
}
|
||||
|
||||
async function checkStatus() {
|
||||
const serverUrl = document.getElementById('serverUrl').value;
|
||||
const sessionId = document.getElementById('sessionId').value;
|
||||
|
||||
if (!serverUrl || !sessionId) {
|
||||
alert('서버 URL과 세션 ID를 입력해주세요');
|
||||
return;
|
||||
}
|
||||
|
||||
addLog('연결 상태 확인 중...', 'connected');
|
||||
|
||||
try {
|
||||
const response = await fetch(`${serverUrl}/api/rag/terms/stream/${sessionId}/status`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.connected) {
|
||||
addLog(`✅ 연결 상태: 연결됨 (세션 ID: ${data.session_id})`, 'connected');
|
||||
updateStatus(true);
|
||||
} else {
|
||||
addLog(`❌ 연결 상태: 연결 안됨 (세션 ID: ${data.session_id})`, 'error');
|
||||
updateStatus(false);
|
||||
}
|
||||
} catch (error) {
|
||||
addLog(`❌ 상태 확인 실패: ${error.message}`, 'error');
|
||||
console.error('상태 확인 에러:', error);
|
||||
}
|
||||
}
|
||||
|
||||
function clearResults() {
|
||||
const resultsDiv = document.getElementById('results');
|
||||
resultsDiv.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<svg viewBox="0 0 24 24" fill="currentColor">
|
||||
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/>
|
||||
</svg>
|
||||
<p>연결 후 용어 검색 결과가 여기에 표시됩니다</p>
|
||||
</div>
|
||||
`;
|
||||
messageCount = 0;
|
||||
document.getElementById('messageCount').textContent = '0';
|
||||
}
|
||||
|
||||
// 페이지 이탈 시 연결 해제
|
||||
window.addEventListener('beforeunload', () => {
|
||||
if (eventSource) {
|
||||
eventSource.close();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user