Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 28 additions & 35 deletions cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Lang2SQL CLI 프로그램입니다.
이 프로그램은 Datahub GMS 서버 URL을 설정하고, 필요 시 Streamlit 인터페이스를 실행합니다.
이 프로그램은 환경 초기화와 Streamlit 실행을 제공합니다.

명령어 예시: lang2sql --datahub_server http://localhost:8080 --run-streamlit
주의: --datahub_server 옵션은 더 이상 사용되지 않습니다(deprecated).
DataHub 설정은 UI의 설정 > 데이터 소스 탭에서 관리하세요.
"""

import click
Expand All @@ -11,8 +12,7 @@
from cli.core.environment import initialize_environment
from cli.core.streamlit_runner import run_streamlit_command
from cli.utils.logger import configure_logging
from infra.monitoring.check_server import CheckServer
from llm_utils.tools import set_gms_server

from version import __version__

logger = configure_logging()
Expand All @@ -24,12 +24,8 @@
@click.pass_context
@click.option(
"--datahub_server",
default="http://localhost:8080",
help=(
"Datahub GMS 서버의 URL을 설정합니다. "
"기본값은 'http://localhost:8080'이며, "
"운영 환경 또는 테스트 환경에 맞게 변경할 수 있습니다."
),
default=None,
help=("[Deprecated] DataHub GMS URL. 이제는 UI 설정 > 데이터 소스에서 관리하세요."),
)
@click.option(
"--run-streamlit",
Expand Down Expand Up @@ -61,60 +57,57 @@
)
@click.option(
"--vectordb-type",
type=click.Choice(["faiss", "pgvector"]),
default="faiss",
help="사용할 벡터 데이터베이스 타입 (기본값: faiss)",
default=None,
help="[Deprecated] VectorDB 타입. 이제는 UI 설정 > 데이터 소스에서 관리하세요.",
)
@click.option(
"--vectordb-location",
help=(
"VectorDB 위치 설정\n"
"- FAISS: 디렉토리 경로 (예: ./my_vectordb)\n"
"- pgvector: 연결 문자열 (예: postgresql://user:pass@host:port/db)\n"
"기본값: FAISS는 './dev/table_info_db', pgvector는 환경변수 사용"
),
default=None,
help="[Deprecated] VectorDB 위치. 이제는 UI 설정 > 데이터 소스에서 관리하세요.",
)
def cli(
ctx: click.Context,
datahub_server: str,
datahub_server: str | None,
run_streamlit: bool,
port: int,
env_file_path: str | None = None,
prompt_dir_path: str | None = None,
vectordb_type: str = "faiss",
vectordb_location: str = None,
vectordb_type: str | None = None,
vectordb_location: str | None = None,
) -> None:
"""Lang2SQL CLI 엔트리포인트.

- 환경 변수 및 VectorDB 설정 초기화
- GMS 서버 연결 및 헬스체크
- 필요 시 Streamlit 애플리케이션 실행
"""

try:
initialize_environment(
env_file_path=env_file_path,
prompt_dir_path=prompt_dir_path,
vectordb_type=vectordb_type,
vectordb_location=vectordb_location,
env_file_path=env_file_path, prompt_dir_path=prompt_dir_path
)
except Exception:
logger.error("Initialization failed.", exc_info=True)
ctx.exit(1)

logger.info(
"Initialization started: GMS server = %s, run_streamlit = %s, port = %d",
datahub_server,
"Initialization started: run_streamlit = %s, port = %d",
run_streamlit,
port,
)

if CheckServer.is_gms_server_healthy(url=datahub_server):
set_gms_server(datahub_server)
logger.info("GMS server URL successfully set: %s", datahub_server)
else:
logger.error("GMS server health check failed. URL: %s", datahub_server)
# ctx.exit(1)
# Deprecated 안내: CLI에서 DataHub 설정은 더 이상 처리하지 않습니다
if datahub_server:
click.secho(
"[Deprecated] --datahub_server 옵션은 더 이상 사용되지 않습니다. 설정 > 데이터 소스 탭에서 설정하세요.",
fg="yellow",
)

# Deprecated 안내: CLI에서 VectorDB 설정은 더 이상 처리하지 않습니다
if vectordb_type or vectordb_location:
click.secho(
"[Deprecated] --vectordb-type/--vectordb-location 옵션은 더 이상 사용되지 않습니다. 설정 > 데이터 소스 탭에서 설정하세요.",
fg="yellow",
)

if run_streamlit:
run_streamlit_command(port)
Expand Down
11 changes: 3 additions & 8 deletions cli/core/environment.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
"""환경 변수 VectorDB 초기화 모듈."""
"""환경 변수 초기화 모듈 (VectorDB 설정은 UI에서 관리)."""

from typing import Optional

from cli.utils.env_loader import load_env, set_prompt_dir, set_vectordb
from cli.utils.env_loader import load_env, set_prompt_dir


def initialize_environment(
*,
env_file_path: Optional[str],
prompt_dir_path: Optional[str],
vectordb_type: str,
vectordb_location: Optional[str],
) -> None:
"""환경 변수와 VectorDB 설정을 초기화합니다.
"""환경 변수를 초기화합니다. VectorDB 설정은 UI에서 관리합니다.

Args:
env_file_path (Optional[str]): 로드할 .env 파일 경로. None이면 기본값 사용.
prompt_dir_path (Optional[str]): 프롬프트 템플릿 디렉토리 경로. None이면 설정하지 않음.
vectordb_type (str): VectorDB 타입 ("faiss" 또는 "pgvector").
vectordb_location (Optional[str]): VectorDB 위치. None이면 기본값 사용.

Raises:
Exception: 초기화 과정에서 오류가 발생한 경우.
"""
load_env(env_file_path=env_file_path)
set_prompt_dir(prompt_dir_path=prompt_dir_path)
set_vectordb(vectordb_type=vectordb_type, vectordb_location=vectordb_location)
3 changes: 2 additions & 1 deletion interface/app_pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#### 사용 방법
1. 왼쪽 메뉴에서 원하는 기능 페이지를 선택하세요.
2. **🔍 Lang2SQL**: 자연어 → SQL 변환 및 결과 분석
3. **📊 그래프 빌더**: 데이터 시각화를 위한 차트 구성
3. **📊 그래프 빌더**: LangGraph 실행 순서를 프리셋/커스텀으로 구성하고 세션에 적용
4. **⚙️ 설정**: 데이터 소스, LLM, DB 연결 등 환경 설정
"""
)

Expand Down
29 changes: 25 additions & 4 deletions interface/app_pages/lang2sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
from interface.core.lang2sql_runner import run_lang2sql
from interface.core.result_renderer import display_result
from interface.core.session_utils import init_graph
from interface.core.config import load_config
from interface.app_pages.sidebar_components import (
render_sidebar_data_source_selector,
render_sidebar_llm_selector,
render_sidebar_embedding_selector,
render_sidebar_db_selector,
)


TITLE = "Lang2SQL"
DEFAULT_QUERY = "고객 데이터를 기반으로 유니크한 유저 수를 카운트하는 쿼리"
Expand All @@ -37,6 +45,21 @@

st.title(TITLE)

config = load_config()

render_sidebar_data_source_selector(config)
st.sidebar.divider()
render_sidebar_llm_selector()
st.sidebar.divider()
render_sidebar_embedding_selector()
st.sidebar.divider()
render_sidebar_db_selector()
st.sidebar.divider()

st.sidebar.title("Output Settings")
for key, label in SIDEBAR_OPTIONS.items():
st.sidebar.checkbox(label, value=True, key=key)

st.sidebar.markdown("### 워크플로우 선택")
use_enriched = st.sidebar.checkbox(
"프로파일 추출 & 컨텍스트 보강 워크플로우 사용", value=False
Expand All @@ -55,6 +78,8 @@
f"Lang2SQL이 성공적으로 새로고침되었습니다. ({GRAPH_TYPE} 워크플로우)"
)

## moved to component: render_sidebar_llm_selector()

user_query = st.text_area("쿼리를 입력하세요:", value=DEFAULT_QUERY)

if "dialects" not in st.session_state:
Expand Down Expand Up @@ -110,10 +135,6 @@
)
user_top_n = st.slider("검색할 테이블 정보 개수:", min_value=1, max_value=20, value=5)

st.sidebar.title("Output Settings")
for key, label in SIDEBAR_OPTIONS.items():
st.sidebar.checkbox(label, value=True, key=key)

if st.button("쿼리 실행"):
res = run_lang2sql(
query=user_query,
Expand Down
31 changes: 31 additions & 0 deletions interface/app_pages/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Settings 페이지 – 섹션 기반 UI
"""

import streamlit as st

from interface.core.config import load_config
from interface.app_pages.settings_sections.data_source_section import (
render_data_source_section,
)
from interface.app_pages.settings_sections.llm_section import render_llm_section
from interface.app_pages.settings_sections.db_section import render_db_section


st.title("⚙️ 설정")

config = load_config()

tabs = st.tabs(["데이터 소스", "LLM", "DB"])

with tabs[0]:
render_data_source_section(config)

with tabs[1]:
render_llm_section(config)

with tabs[2]:
render_db_section()

st.divider()
st.caption("민감 정보는 로그에 기록되지 않으며, 이 설정은 현재 세션에 우선 반영됩니다.")
9 changes: 9 additions & 0 deletions interface/app_pages/settings_sections/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Namespace package for settings page sections

__all__ = [
"data_source_section",
"llm_section",
"db_section",
"vectordb_section",
"device_section",
]
Loading