-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrag_admin.html
More file actions
604 lines (513 loc) · 22.3 KB
/
rag_admin.html
File metadata and controls
604 lines (513 loc) · 22.3 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>던전톡 RAG 데이터 관리</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1000px;
margin: 0 auto;
background: white;
border-radius: 15px;
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: 2.5rem;
margin-bottom: 10px;
}
.header p {
font-size: 1.1rem;
opacity: 0.9;
}
.content {
padding: 40px;
}
.status-section {
background: #f8f9fa;
border-radius: 10px;
padding: 25px;
margin-bottom: 30px;
border-left: 5px solid #28a745;
}
.status-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin-top: 20px;
}
.status-card {
background: white;
padding: 20px;
border-radius: 8px;
text-align: center;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.status-card h3 {
color: #495057;
margin-bottom: 10px;
}
.status-value {
font-size: 2rem;
font-weight: bold;
color: #28a745;
}
.action-section {
background: #fff;
border-radius: 10px;
padding: 25px;
margin-bottom: 30px;
border: 1px solid #e9ecef;
}
.action-section h2 {
color: #495057;
margin-bottom: 20px;
font-size: 1.5rem;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #495057;
}
input, select, textarea {
width: 100%;
padding: 12px;
border: 2px solid #e9ecef;
border-radius: 8px;
font-size: 1rem;
transition: border-color 0.3s;
}
input:focus, select:focus, textarea:focus {
outline: none;
border-color: #667eea;
}
textarea {
min-height: 120px;
resize: vertical;
}
.btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 12px 30px;
border-radius: 8px;
font-size: 1rem;
cursor: pointer;
transition: transform 0.2s;
margin-right: 10px;
margin-bottom: 10px;
}
.btn:hover {
transform: translateY(-2px);
}
.btn-danger {
background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%);
}
.btn-success {
background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%);
}
.btn-info {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.result {
margin-top: 20px;
padding: 15px;
border-radius: 8px;
display: none;
}
.result.success {
background: #d4edda;
border: 1px solid #c3e6cb;
color: #155724;
}
.result.error {
background: #f8d7da;
border: 1px solid #f5c6cb;
color: #721c24;
}
.loading {
display: none;
text-align: center;
padding: 20px;
}
.spinner {
width: 40px;
height: 40px;
border: 4px solid #f3f3f3;
border-top: 4px solid #667eea;
border-radius: 50%;
animation: spin 1s linear infinite;
margin: 0 auto 15px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.file-upload-area {
border: 2px dashed #667eea;
border-radius: 8px;
padding: 40px;
text-align: center;
cursor: pointer;
transition: all 0.3s;
margin-bottom: 20px;
}
.file-upload-area:hover {
background: #f8f9fa;
border-color: #495057;
}
.file-upload-area.dragover {
background: #e3f2fd;
border-color: #2196f3;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🏰 던전톡 RAG 관리</h1>
<p>벡터 데이터베이스 관리 및 문서 업로드</p>
</div>
<div class="content">
<!-- 상태 확인 섹션 -->
<div class="status-section">
<h2>📊 벡터 DB 상태</h2>
<div class="status-grid" id="statusGrid">
<div class="status-card">
<h3>문서 수</h3>
<div class="status-value" id="docCount">-</div>
</div>
<div class="status-card">
<h3>벡터스토어 상태</h3>
<div class="status-value" id="vectorStatus">-</div>
</div>
<div class="status-card">
<h3>로컬 문서 수</h3>
<div class="status-value" id="localDocCount">-</div>
</div>
</div>
<button class="btn btn-info" onclick="checkStatus()">🔄 상태 새로고침</button>
</div>
<!-- 빠른 작업 섹션 -->
<div class="action-section">
<h2>⚡ 빠른 작업</h2>
<button class="btn btn-success" onclick="initVectorDB()">🚀 벡터 DB 초기화</button>
<button class="btn btn-info" onclick="rescanDocuments()">📂 문서 재스캔</button>
<div id="quickActionResult" class="result"></div>
<div id="quickActionLoading" class="loading">
<div class="spinner"></div>
<p>처리 중...</p>
</div>
</div>
<!-- 문서 업로드 섹션 -->
<div class="action-section">
<h2>📄 문서 업로드</h2>
<div class="file-upload-area" id="fileUploadArea" onclick="document.getElementById('fileInput').click()">
<p>📁 클릭하거나 파일을 드래그해서 업로드하세요</p>
<p style="color: #6c757d; font-size: 0.9rem;">지원 형식: .txt, .md, .pdf</p>
</div>
<input type="file" id="fileInput" style="display: none;" accept=".txt,.md,.pdf" onchange="handleFileSelect(event)">
<div class="form-group">
<label for="worldType">🌍 세계관</label>
<select id="worldType">
<option value="">자동 감지</option>
<option value="FANTASY">판타지</option>
<option value="SF">SF</option>
<option value="MODERN">현대</option>
<option value="ZOMBIE">좀비</option>
<option value="HISTORICAL">역사</option>
</select>
</div>
<div class="form-group">
<label for="docType">📋 문서 유형</label>
<select id="docType">
<option value="">자동 감지</option>
<option value="NPC">NPC</option>
<option value="LOCATION">장소</option>
<option value="ITEM">아이템</option>
<option value="SCENARIO">시나리오</option>
<option value="RULES">규칙</option>
<option value="LORE">세계관</option>
</select>
</div>
<div class="form-group">
<label for="userTags">🏷️ 사용자 태그 (쉼표로 구분)</label>
<input type="text" id="userTags" placeholder="예: 강력한, 마법사, 보스">
</div>
<button class="btn" onclick="uploadDocument()">📤 문서 업로드</button>
<div id="uploadResult" class="result"></div>
<div id="uploadLoading" class="loading">
<div class="spinner"></div>
<p>업로드 중...</p>
</div>
</div>
<!-- 직접 텍스트 추가 섹션 -->
<div class="action-section">
<h2>✏️ 직접 텍스트 추가</h2>
<div class="form-group">
<label for="textTitle">📝 문서 제목</label>
<input type="text" id="textTitle" placeholder="예: 새로운 NPC - 마법사 엘라라">
</div>
<div class="form-group">
<label for="textContent">📄 문서 내용</label>
<textarea id="textContent" placeholder="여기에 추가할 RAG 데이터를 입력하세요..."></textarea>
</div>
<div class="form-group">
<label for="textWorldType">🌍 세계관</label>
<select id="textWorldType">
<option value="FANTASY">판타지</option>
<option value="SF">SF</option>
<option value="MODERN">현대</option>
<option value="ZOMBIE">좀비</option>
<option value="HISTORICAL">역사</option>
</select>
</div>
<div class="form-group">
<label for="textDocType">📋 문서 유형</label>
<select id="textDocType">
<option value="NPC">NPC</option>
<option value="LOCATION">장소</option>
<option value="ITEM">아이템</option>
<option value="SCENARIO">시나리오</option>
<option value="RULES">규칙</option>
<option value="LORE">세계관</option>
</select>
</div>
<div class="form-group">
<label for="textUserTags">🏷️ 사용자 태그 (쉼표로 구분)</label>
<input type="text" id="textUserTags" placeholder="예: 강력한, 마법사, 보스">
</div>
<button class="btn" onclick="addTextDocument()">➕ 텍스트 추가</button>
<div id="textResult" class="result"></div>
<div id="textLoading" class="loading">
<div class="spinner"></div>
<p>추가 중...</p>
</div>
</div>
</div>
</div>
<script>
// 페이지 로드 시 상태 확인
window.onload = function() {
checkStatus();
};
// 상태 확인 함수
async function checkStatus() {
try {
const response = await fetch('/vector-db-status');
const data = await response.json();
document.getElementById('docCount').textContent = data.document_count || '0';
document.getElementById('vectorStatus').textContent = data.vectorstore_available ? '✅' : '❌';
document.getElementById('localDocCount').textContent = data.documents_in_dir || '0';
// 상태에 따라 색상 변경
const statusElement = document.getElementById('vectorStatus');
statusElement.style.color = data.vectorstore_available ? '#28a745' : '#dc3545';
} catch (error) {
console.error('상태 확인 실패:', error);
showResult('statusResult', '상태 확인 실패: ' + error.message, 'error');
}
}
// 벡터 DB 초기화
async function initVectorDB() {
showLoading('quickActionLoading', true);
hideResult('quickActionResult');
try {
const response = await fetch('/init-vectordb', { method: 'POST' });
const data = await response.json();
if (response.ok) {
showResult('quickActionResult',
`✅ ${data.message}\n처리된 파일: ${data.files_processed}개\n초기화 성공: ${data.initialization_success ? '예' : '아니오'}`,
'success'
);
checkStatus(); // 상태 새로고침
} else {
showResult('quickActionResult', '❌ ' + (data.detail || '초기화 실패'), 'error');
}
} catch (error) {
showResult('quickActionResult', '❌ 초기화 실패: ' + error.message, 'error');
} finally {
showLoading('quickActionLoading', false);
}
}
// 문서 재스캔
async function rescanDocuments() {
showLoading('quickActionLoading', true);
hideResult('quickActionResult');
try {
const response = await fetch('/rescan-documents', { method: 'POST' });
const data = await response.json();
if (response.ok) {
showResult('quickActionResult',
`✅ ${data.message}\n처리됨: ${data.processed}개\n실패: ${data.failed}개`,
'success'
);
checkStatus(); // 상태 새로고침
} else {
showResult('quickActionResult', '❌ ' + (data.detail || '재스캔 실패'), 'error');
}
} catch (error) {
showResult('quickActionResult', '❌ 재스캔 실패: ' + error.message, 'error');
} finally {
showLoading('quickActionLoading', false);
}
}
// 파일 업로드 처리
let selectedFile = null;
function handleFileSelect(event) {
selectedFile = event.target.files[0];
if (selectedFile) {
document.getElementById('fileUploadArea').innerHTML =
`<p>📁 선택된 파일: ${selectedFile.name}</p>
<p style="color: #28a745;">업로드 준비 완료</p>`;
}
}
// 드래그 앤 드롭 처리
const fileUploadArea = document.getElementById('fileUploadArea');
fileUploadArea.addEventListener('dragover', function(e) {
e.preventDefault();
this.classList.add('dragover');
});
fileUploadArea.addEventListener('dragleave', function(e) {
e.preventDefault();
this.classList.remove('dragover');
});
fileUploadArea.addEventListener('drop', function(e) {
e.preventDefault();
this.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
selectedFile = files[0];
this.innerHTML =
`<p>📁 선택된 파일: ${selectedFile.name}</p>
<p style="color: #28a745;">업로드 준비 완료</p>`;
}
});
// 문서 업로드
async function uploadDocument() {
if (!selectedFile) {
showResult('uploadResult', '❌ 파일을 선택해주세요', 'error');
return;
}
showLoading('uploadLoading', true);
hideResult('uploadResult');
const formData = new FormData();
formData.append('file', selectedFile);
const worldType = document.getElementById('worldType').value;
const docType = document.getElementById('docType').value;
const userTags = document.getElementById('userTags').value;
if (worldType) formData.append('world_type', worldType);
if (docType) formData.append('doc_type', docType);
if (userTags) formData.append('user_tags', userTags);
try {
const response = await fetch('/upload-document', {
method: 'POST',
body: formData
});
const data = await response.json();
if (response.ok) {
showResult('uploadResult',
`✅ ${data.message}\n파일명: ${data.filename}\n청크 수: ${data.chunks_added}개\n감지된 메타데이터: ${JSON.stringify(data.detected_metadata, null, 2)}`,
'success'
);
// 업로드 완료 후 초기화
selectedFile = null;
document.getElementById('fileInput').value = '';
document.getElementById('fileUploadArea').innerHTML =
`<p>📁 클릭하거나 파일을 드래그해서 업로드하세요</p>
<p style="color: #6c757d; font-size: 0.9rem;">지원 형식: .txt, .md, .pdf</p>`;
checkStatus(); // 상태 새로고침
} else {
showResult('uploadResult', '❌ ' + (data.detail || '업로드 실패'), 'error');
}
} catch (error) {
showResult('uploadResult', '❌ 업로드 실패: ' + error.message, 'error');
} finally {
showLoading('uploadLoading', false);
}
}
// 직접 텍스트 추가
async function addTextDocument() {
const title = document.getElementById('textTitle').value.trim();
const content = document.getElementById('textContent').value.trim();
const worldType = document.getElementById('textWorldType').value;
const docType = document.getElementById('textDocType').value;
const userTags = document.getElementById('textUserTags').value;
if (!title || !content) {
showResult('textResult', '❌ 제목과 내용을 모두 입력해주세요', 'error');
return;
}
showLoading('textLoading', true);
hideResult('textResult');
// 임시 파일 생성을 위해 Blob 사용
const blob = new Blob([content], { type: 'text/plain' });
const file = new File([blob], title + '.txt', { type: 'text/plain' });
const formData = new FormData();
formData.append('file', file);
formData.append('world_type', worldType);
formData.append('doc_type', docType);
if (userTags) formData.append('user_tags', userTags);
try {
const response = await fetch('/upload-document', {
method: 'POST',
body: formData
});
const data = await response.json();
if (response.ok) {
showResult('textResult',
`✅ ${data.message}\n제목: ${title}\n청크 수: ${data.chunks_added}개\n감지된 메타데이터: ${JSON.stringify(data.detected_metadata, null, 2)}`,
'success'
);
// 입력 필드 초기화
document.getElementById('textTitle').value = '';
document.getElementById('textContent').value = '';
document.getElementById('textUserTags').value = '';
checkStatus(); // 상태 새로고침
} else {
showResult('textResult', '❌ ' + (data.detail || '추가 실패'), 'error');
}
} catch (error) {
showResult('textResult', '❌ 추가 실패: ' + error.message, 'error');
} finally {
showLoading('textLoading', false);
}
}
// 유틸리티 함수들
function showResult(elementId, message, type) {
const element = document.getElementById(elementId);
element.textContent = message;
element.className = 'result ' + type;
element.style.display = 'block';
}
function hideResult(elementId) {
const element = document.getElementById(elementId);
element.style.display = 'none';
}
function showLoading(elementId, show) {
const element = document.getElementById(elementId);
element.style.display = show ? 'block' : 'none';
}
</script>
</body>
</html>