Skip to content

Commit dd24db6

Browse files
committed
데이터 소스 설정을 Lang2SQL 페이지에서 선택해 사용가능하도록 수정
1 parent 1ca5d5d commit dd24db6

File tree

5 files changed

+548
-59
lines changed

5 files changed

+548
-59
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import streamlit as st
2+
3+
from interface.core.config import (
4+
load_config,
5+
get_data_sources_registry,
6+
update_datahub_server,
7+
update_vectordb_settings,
8+
update_data_source_mode,
9+
)
10+
11+
12+
def render_sidebar_data_source_selector(config=None) -> None:
13+
if config is None:
14+
config = load_config()
15+
16+
registry = get_data_sources_registry()
17+
18+
st.sidebar.markdown("### 데이터 소스")
19+
enable_data_source = st.sidebar.checkbox(
20+
"데이터 소스 적용", value=True, key="enable_data_source"
21+
)
22+
if not enable_data_source:
23+
return
24+
25+
mode_index = 0 if (config.data_source_mode or "datahub").lower() == "datahub" else 1
26+
selected_mode = st.sidebar.radio(
27+
"소스 종류", options=["DataHub", "VectorDB"], index=mode_index, horizontal=True
28+
)
29+
30+
if selected_mode == "DataHub":
31+
datahub_names = [s.name for s in registry.datahub]
32+
if not datahub_names:
33+
st.sidebar.warning(
34+
"등록된 DataHub가 없습니다. 설정 > 데이터 소스에서 추가하세요."
35+
)
36+
return
37+
dh_name = st.sidebar.selectbox(
38+
"DataHub 인스턴스", options=datahub_names, key="sidebar_dh_select"
39+
)
40+
if st.sidebar.button("소스 적용", key="sidebar_apply_dh"):
41+
selected = next((s for s in registry.datahub if s.name == dh_name), None)
42+
if selected is None:
43+
st.sidebar.error("선택한 DataHub를 찾을 수 없습니다.")
44+
return
45+
try:
46+
update_datahub_server(config, selected.url)
47+
# DataHub 선택 시, FAISS 경로가 정의되어 있으면 기본 VectorDB 로케이션으로도 반영
48+
if selected.faiss_path:
49+
try:
50+
update_vectordb_settings(
51+
config,
52+
vectordb_type="faiss",
53+
vectordb_location=selected.faiss_path,
54+
)
55+
except Exception as e:
56+
st.sidebar.warning(f"FAISS 경로 적용 경고: {e}")
57+
update_data_source_mode(config, "datahub")
58+
st.sidebar.success(f"DataHub 적용됨: {selected.name}")
59+
except Exception as e:
60+
st.sidebar.error(f"적용 실패: {e}")
61+
else:
62+
vdb_names = [s.name for s in registry.vectordb]
63+
if not vdb_names:
64+
st.sidebar.warning(
65+
"등록된 VectorDB가 없습니다. 설정 > 데이터 소스에서 추가하세요."
66+
)
67+
return
68+
vdb_name = st.sidebar.selectbox(
69+
"VectorDB 인스턴스", options=vdb_names, key="sidebar_vdb_select"
70+
)
71+
if st.sidebar.button("소스 적용", key="sidebar_apply_vdb"):
72+
selected = next((s for s in registry.vectordb if s.name == vdb_name), None)
73+
if selected is None:
74+
st.sidebar.error("선택한 VectorDB를 찾을 수 없습니다.")
75+
return
76+
try:
77+
update_vectordb_settings(
78+
config,
79+
vectordb_type=selected.type,
80+
vectordb_location=selected.location,
81+
)
82+
update_data_source_mode(config, "vectordb")
83+
st.sidebar.success(f"VectorDB 적용됨: {selected.name}")
84+
except Exception as e:
85+
st.sidebar.error(f"적용 실패: {e}")

interface/app_pages/lang2sql.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
from interface.core.lang2sql_runner import run_lang2sql
2121
from interface.core.result_renderer import display_result
2222
from interface.core.session_utils import init_graph
23+
from interface.core.config import load_config
24+
from interface.app_pages.components.data_source_selector import (
25+
render_sidebar_data_source_selector,
26+
)
2327

2428
TITLE = "Lang2SQL"
2529
DEFAULT_QUERY = "고객 데이터를 기반으로 유니크한 유저 수를 카운트하는 쿼리"
@@ -37,6 +41,10 @@
3741

3842
st.title(TITLE)
3943

44+
config = load_config()
45+
46+
render_sidebar_data_source_selector(config)
47+
4048
st.sidebar.markdown("### 워크플로우 선택")
4149
use_enriched = st.sidebar.checkbox(
4250
"프로파일 추출 & 컨텍스트 보강 워크플로우 사용", value=False

interface/app_pages/settings.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
config = load_config()
1616

17-
tabs = st.tabs(["데이터 소스", "LLM", "DB", "VectorDB", "Device"])
17+
tabs = st.tabs(["데이터 소스", "LLM", "DB", "Device"])
1818

1919
with tabs[0]:
2020
render_data_source_section(config)
@@ -26,9 +26,6 @@
2626
st.info("DB 연결 설정은 곧 제공됩니다.")
2727

2828
with tabs[3]:
29-
st.info("VectorDB 설정은 곧 제공됩니다.")
30-
31-
with tabs[4]:
3229
st.info("디바이스 설정은 곧 제공됩니다.")
3330

3431
st.divider()

0 commit comments

Comments
 (0)