Skip to content

Commit cbe19d4

Browse files
committed
refactor: Improve GMS server configuration and fetcher management
- Replace global fetcher with environment-based configuration - Add get_fetcher() method to dynamically retrieve DatahubMetadataFetcher - Update CLI option name from gms_server to datahub_server - Modify tools module to use environment variable for server configuration
1 parent e3d4248 commit cbe19d4

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

cli/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
@click.version_option(version="0.1.4")
88
@click.pass_context
99
@click.option(
10-
"--gms-server", default="http://localhost:8080", help="Datahub GMS 서버 URL"
10+
"--datahub_server", default="http://localhost:8080", help="Datahub GMS 서버 URL"
1111
)
1212
@click.option("--run-streamlit", is_flag=True, help="Run the Streamlit app.")
1313
@click.option("-p", "--port", type=int, default=8501, help="Streamlit port")
14-
def cli(ctx, gms_server, run_streamlit, port):
14+
def cli(ctx, datahub_server, run_streamlit, port):
1515
try:
16-
set_gms_server(gms_server)
16+
set_gms_server(datahub_server)
1717
except ValueError as e:
1818
click.echo(str(e))
1919
ctx.exit(1)

llm_utils/tools.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,31 @@
1+
import os
12
from typing import List, Dict
23

34
from langchain.tools import tool
45

56
from data_utils.datahub_source import DatahubMetadataFetcher
67

7-
fetcher = None
8-
98

109
def set_gms_server(gms_server: str):
11-
global fetcher
12-
1310
try:
11+
os.environ["DATAHUB_SERVER"] = gms_server
1412
fetcher = DatahubMetadataFetcher(gms_server=gms_server)
1513
except ValueError as e:
1614
# 유효하지 않은 GMS 서버 주소일 경우 예외를 발생시킴
1715
raise ValueError(f"GMS 서버 설정 실패: {str(e)}")
1816

1917

18+
def get_fetcher():
19+
gms_server = os.getenv("DATAHUB_SERVER")
20+
if not gms_server:
21+
raise ValueError("GMS 서버가 설정되지 않았습니다.")
22+
return DatahubMetadataFetcher(gms_server=gms_server)
23+
24+
2025
@tool
2126
def get_table_info() -> Dict[str, str]:
2227
"""전체 테이블 이름과 설명을 가져오는 함수"""
28+
fetcher = get_fetcher()
2329
urns = fetcher.get_urns()
2430
table_info = {}
2531
for urn in urns:
@@ -33,6 +39,7 @@ def get_table_info() -> Dict[str, str]:
3339
@tool
3440
def get_column_info(table_name: str) -> List[Dict[str, str]]:
3541
"""table_name에 해당하는 컬럼 이름과 설명을 가져오는 함수"""
42+
fetcher = get_fetcher()
3643
urns = fetcher.get_urns()
3744
for urn in urns:
3845
if fetcher.get_table_name(urn) == table_name:

0 commit comments

Comments
 (0)