-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdata_source_section.py
More file actions
401 lines (383 loc) · 17.4 KB
/
data_source_section.py
File metadata and controls
401 lines (383 loc) · 17.4 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
import streamlit as st
from interface.core.config import (
Config,
load_config,
update_vectordb_settings,
update_data_source_mode,
get_data_sources_registry,
add_datahub_source,
update_datahub_source,
delete_datahub_source,
add_vectordb_source,
update_vectordb_source,
delete_vectordb_source,
)
from infra.monitoring.check_server import CheckServer
def _render_status_banner(config: Config) -> None:
mode = config.data_source_mode
ready_msgs = []
if mode == "datahub":
last_health = st.session_state.get("datahub_last_health")
if last_health is True:
st.success(f"데이터 소스 준비됨: DataHub ({config.datahub_server})")
elif last_health is False:
st.warning(
"DataHub 헬스 체크 실패. URL을 확인하거나 VectorDB로 전환하세요."
)
else:
st.info("DataHub 상태 미검증 – 헬스 체크 버튼으로 확인하세요.")
elif mode == "vectordb":
if config.vectordb_type and (
(config.vectordb_type == "faiss" and config.vectordb_location)
or (config.vectordb_type == "pgvector" and config.vectordb_location)
):
st.success(
f"데이터 소스 준비됨: VectorDB ({config.vectordb_type}, {config.vectordb_location or '기본값'})"
)
else:
st.warning("VectorDB 설정이 불완전합니다. 타입/위치를 확인하세요.")
else:
st.info(
"데이터 소스를 선택해주세요: DataHub 또는 VectorDB 중 하나는 필수입니다."
)
def render_data_source_section(config: Config | None = None) -> None:
st.subheader("데이터 소스 (필수)")
if config is None:
config = load_config()
_render_status_banner(config)
# 선택 스위치
col = st.columns([1, 3])[0]
with col:
mode = st.radio(
"데이터 소스 선택",
options=["DataHub", "VectorDB"],
horizontal=True,
index=(
0 if (config.data_source_mode or "datahub").lower() == "datahub" else 1
),
)
selected = mode.lower()
update_data_source_mode(config, selected)
st.divider()
registry = get_data_sources_registry()
if selected == "datahub":
with st.container(border=True):
st.write("등록된 DataHub")
for source in list(registry.datahub):
cols = st.columns([2, 4, 2, 1, 1])
with cols[0]:
st.text(source.name)
with cols[1]:
st.text(source.url)
with cols[2]:
note_val = source.note or ""
st.caption(note_val)
with cols[3]:
if st.button("편집", key=f"edit_dh_{source.name}"):
st.session_state["edit_dh_name"] = source.name
with cols[4]:
if st.button("삭제", type="secondary", key=f"del_dh_{source.name}"):
delete_datahub_source(name=source.name)
st.rerun()
# 편집 폼
edit_dh = st.session_state.get("edit_dh_name")
if edit_dh:
st.divider()
st.write(f"DataHub 편집: {edit_dh}")
existing = next(
(s for s in registry.datahub if s.name == edit_dh), None
)
if existing:
new_url = st.text_input(
"URL", value=existing.url, key="dh_edit_url"
)
new_vdb_type = st.selectbox(
"VectorDB 타입",
options=["faiss", "pgvector", "qdrant"],
index=(
0
if existing.vectordb_type == "faiss"
else (1 if existing.vectordb_type == "pgvector" else 2)
),
key="dh_edit_vdb_type",
)
new_vdb_loc_placeholder = (
"FAISS 디렉토리 경로 (예: ./dev/table_info_db)"
if new_vdb_type == "faiss"
else (
"pgvector 연결 문자열 (postgresql://...)"
if new_vdb_type == "pgvector"
else "Qdrant URL (예: http://localhost:6333)"
)
)
new_vdb_location = st.text_input(
"VectorDB 위치",
value=existing.vectordb_location or existing.faiss_path or "",
key="dh_edit_vdb_loc",
placeholder=new_vdb_loc_placeholder,
)
new_vdb_api_key = st.text_input(
"VectorDB API Key (선택)",
value=existing.vectordb_api_key or "",
type="password",
key="dh_edit_vdb_key",
)
new_note = st.text_input(
"메모", value=existing.note or "", key="dh_edit_note"
)
cols = st.columns([1, 1, 2])
with cols[0]:
if st.button("헬스 체크", key="dh_edit_health"):
ok = CheckServer.is_gms_server_healthy(url=new_url)
st.session_state["datahub_last_health"] = bool(ok)
if ok:
st.success("GMS 서버가 정상입니다.")
else:
st.error(
"GMS 서버 헬스 체크 실패. URL과 네트워크를 확인하세요."
)
with cols[1]:
if st.button("저장", key="dh_edit_save"):
try:
update_datahub_source(
name=edit_dh,
url=new_url,
faiss_path=(
new_vdb_location
if new_vdb_type == "faiss"
else None
),
vectordb_type=new_vdb_type,
vectordb_location=(new_vdb_location or None),
vectordb_api_key=(new_vdb_api_key or None),
note=(new_note or None),
)
st.success("저장되었습니다.")
st.session_state.pop("edit_dh_name", None)
st.rerun()
except Exception as e:
st.error(f"저장 실패: {e}")
with cols[2]:
if st.button("취소", key="dh_edit_cancel"):
st.session_state.pop("edit_dh_name", None)
st.rerun()
st.divider()
st.write("DataHub 추가")
dh_name = st.text_input("이름", key="dh_name")
dh_url = st.text_input(
"URL", key="dh_url", placeholder="http://localhost:8080"
)
dh_vdb_type = st.selectbox(
"VectorDB 타입",
options=["faiss", "pgvector", "qdrant"],
key="dh_new_vdb_type",
)
dh_vdb_loc_placeholder = (
"FAISS 디렉토리 경로 (예: ./dev/table_info_db)"
if dh_vdb_type == "faiss"
else (
"pgvector 연결 문자열 (postgresql://...)"
if dh_vdb_type == "pgvector"
else "Qdrant URL (예: http://localhost:6333)"
)
)
dh_vdb_location = st.text_input(
"VectorDB 위치",
key="dh_new_vdb_loc",
placeholder=dh_vdb_loc_placeholder,
)
dh_vdb_api_key = st.text_input(
"VectorDB API Key (선택)",
type="password",
key="dh_new_vdb_key",
)
dh_note = st.text_input("메모", key="dh_note", placeholder="선택")
cols = st.columns([1, 1, 2])
with cols[0]:
if st.button("헬스 체크", key="dh_health_new"):
ok = CheckServer.is_gms_server_healthy(url=dh_url)
st.session_state["datahub_last_health"] = bool(ok)
if ok:
st.success("GMS 서버가 정상입니다.")
else:
st.error(
"GMS 서버 헬스 체크 실패. URL과 네트워크를 확인하세요."
)
with cols[1]:
if st.button("추가", key="dh_add"):
try:
if not dh_name or not dh_url:
st.warning("이름과 URL을 입력하세요.")
else:
add_datahub_source(
name=dh_name,
url=dh_url,
faiss_path=(
dh_vdb_location if dh_vdb_type == "faiss" else None
),
vectordb_type=dh_vdb_type,
vectordb_location=(dh_vdb_location or None),
vectordb_api_key=(dh_vdb_api_key or None),
note=dh_note or None,
)
st.success("추가되었습니다.")
st.rerun()
except Exception as e:
st.error(f"추가 실패: {e}")
else: # VectorDB
with st.container(border=True):
st.write("등록된 VectorDB")
for source in list(registry.vectordb):
cols = st.columns([2, 2, 4, 2, 1, 1])
with cols[0]:
st.text(source.name)
with cols[1]:
st.text(source.type)
with cols[2]:
st.text(source.location)
with cols[3]:
st.caption(source.collection_prefix or "-")
with cols[4]:
if st.button("편집", key=f"edit_vdb_{source.name}"):
st.session_state["edit_vdb_name"] = source.name
with cols[5]:
if st.button(
"삭제", type="secondary", key=f"del_vdb_{source.name}"
):
delete_vectordb_source(name=source.name)
st.rerun()
# 편집 폼
edit_vdb = st.session_state.get("edit_vdb_name")
if edit_vdb:
st.divider()
st.write(f"VectorDB 편집: {edit_vdb}")
existing = next(
(s for s in registry.vectordb if s.name == edit_vdb), None
)
if existing:
new_type = st.selectbox(
"타입",
options=["faiss", "pgvector", "qdrant"],
index=(
0
if existing.type == "faiss"
else (1 if existing.type == "pgvector" else 2)
),
key="vdb_edit_type",
)
new_loc_placeholder = (
"FAISS 디렉토리 경로 (예: ./dev/table_info_db)"
if new_type == "faiss"
else (
"pgvector 연결 문자열 (postgresql://user:pass@host:port/db)"
if new_type == "pgvector"
else "Qdrant URL (예: http://localhost:6333)"
)
)
new_location = st.text_input(
"위치",
value=existing.location,
key="vdb_edit_location",
placeholder=new_loc_placeholder,
)
new_api_key = st.text_input(
"API Key (선택)",
value=existing.api_key or "",
type="password",
key="vdb_edit_key",
)
new_prefix = st.text_input(
"컬렉션 접두사(선택)",
value=existing.collection_prefix or "",
key="vdb_edit_prefix",
)
new_note = st.text_input(
"메모(선택)", value=existing.note or "", key="vdb_edit_note"
)
cols = st.columns([1, 1, 2])
with cols[0]:
if st.button("검증", key="vdb_edit_validate"):
try:
update_vectordb_settings(
config,
vectordb_type=new_type,
vectordb_location=new_location,
)
st.success("설정이 유효합니다.")
except Exception as e:
st.error(f"검증 실패: {e}")
with cols[1]:
if st.button("저장", key="vdb_edit_save"):
try:
update_vectordb_source(
name=edit_vdb,
vtype=new_type,
location=new_location,
api_key=(new_api_key or None),
collection_prefix=(new_prefix or None),
note=(new_note or None),
)
st.success("저장되었습니다.")
st.session_state.pop("edit_vdb_name", None)
st.rerun()
except Exception as e:
st.error(f"저장 실패: {e}")
with cols[2]:
if st.button("취소", key="vdb_edit_cancel"):
st.session_state.pop("edit_vdb_name", None)
st.rerun()
st.divider()
st.write("VectorDB 추가")
vdb_name = st.text_input("이름", key="vdb_name")
vdb_type = st.selectbox(
"타입", options=["faiss", "pgvector", "qdrant"], key="vdb_type"
)
vdb_loc_placeholder = (
"FAISS 디렉토리 경로 (예: ./dev/table_info_db)"
if vdb_type == "faiss"
else (
"pgvector 연결 문자열 (postgresql://user:pass@host:port/db)"
if vdb_type == "pgvector"
else "Qdrant URL (예: http://localhost:6333)"
)
)
vdb_location = st.text_input(
"위치", key="vdb_location", placeholder=vdb_loc_placeholder
)
vdb_api_key = st.text_input(
"API Key (선택)", type="password", key="vdb_new_key"
)
vdb_prefix = st.text_input(
"컬렉션 접두사(선택)", key="vdb_prefix", placeholder="예: app1_"
)
vdb_note = st.text_input("메모(선택)", key="vdb_note")
cols = st.columns([1, 1, 2])
with cols[0]:
if st.button("검증", key="vdb_validate_new"):
try:
update_vectordb_settings(
config,
vectordb_type=vdb_type,
vectordb_location=vdb_location,
)
st.success("설정이 유효합니다.")
except Exception as e:
st.error(f"검증 실패: {e}")
with cols[1]:
if st.button("추가", key="vdb_add"):
try:
if not vdb_name or not vdb_type or not vdb_location:
st.warning("이름/타입/위치를 입력하세요.")
else:
add_vectordb_source(
name=vdb_name,
vtype=vdb_type,
location=vdb_location,
api_key=(vdb_api_key or None),
collection_prefix=(vdb_prefix or None),
note=(vdb_note or None),
)
st.success("추가되었습니다.")
st.rerun()
except Exception as e:
st.error(f"추가 실패: {e}")