Skip to content

Commit 656cbdd

Browse files
committed
설정 관련 모듈을 분리하여 재구성
1 parent 1295296 commit 656cbdd

File tree

9 files changed

+1071
-873
lines changed

9 files changed

+1071
-873
lines changed

interface/core/config.py

Lines changed: 0 additions & 873 deletions
This file was deleted.

interface/core/config/__init__.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
"""config 패키지의 공개 API를 재노출하여 기존 import 호환성을 유지합니다.
2+
모델, 경로/지속성, 레지스트리, 설정 업데이트 유틸을 한 곳에서 제공합니다.
3+
"""
4+
5+
from .models import (
6+
Config,
7+
DataHubSource,
8+
VectorDBSource,
9+
DataSourcesRegistry,
10+
DBConnectionProfile,
11+
DBConnectionsRegistry,
12+
LLMProfile,
13+
LLMRegistry,
14+
EmbeddingProfile,
15+
EmbeddingRegistry,
16+
)
17+
18+
from .settings import (
19+
DEFAULT_DATAHUB_SERVER,
20+
DEFAULT_VECTORDB_TYPE,
21+
DEFAULT_VECTORDB_LOCATION,
22+
load_config,
23+
_get_session_value,
24+
update_datahub_server,
25+
update_data_source_mode,
26+
update_vectordb_settings,
27+
update_llm_settings,
28+
update_embedding_settings,
29+
update_db_settings,
30+
_put_env,
31+
_put_session,
32+
)
33+
34+
from .registry_data_sources import (
35+
get_data_sources_registry,
36+
_save_registry,
37+
add_datahub_source,
38+
update_datahub_source,
39+
delete_datahub_source,
40+
add_vectordb_source,
41+
update_vectordb_source,
42+
delete_vectordb_source,
43+
)
44+
45+
from .registry_db import (
46+
get_db_connections_registry,
47+
_save_db_registry,
48+
add_db_connection,
49+
update_db_connection,
50+
delete_db_connection,
51+
)
52+
53+
from .registry_llm import (
54+
get_llm_registry,
55+
save_llm_profile,
56+
_save_llm_registry,
57+
get_embedding_registry,
58+
save_embedding_profile,
59+
_save_embedding_registry,
60+
)
61+
62+
from .paths import (
63+
_get_registry_file_path,
64+
_get_db_registry_file_path,
65+
_get_llm_registry_file_path,
66+
_get_embedding_registry_file_path,
67+
_ensure_parent_dir,
68+
)
69+
70+
from .persist import (
71+
save_registry_to_disk,
72+
save_db_registry_to_disk,
73+
save_llm_registry_to_disk,
74+
save_embedding_registry_to_disk,
75+
load_registry_from_disk,
76+
load_db_registry_from_disk,
77+
load_llm_registry_from_disk,
78+
load_embedding_registry_from_disk,
79+
)
80+
81+
__all__ = [
82+
# Models
83+
"Config",
84+
"DataHubSource",
85+
"VectorDBSource",
86+
"DataSourcesRegistry",
87+
"DBConnectionProfile",
88+
"DBConnectionsRegistry",
89+
"LLMProfile",
90+
"LLMRegistry",
91+
"EmbeddingProfile",
92+
"EmbeddingRegistry",
93+
# Defaults
94+
"DEFAULT_DATAHUB_SERVER",
95+
"DEFAULT_VECTORDB_TYPE",
96+
"DEFAULT_VECTORDB_LOCATION",
97+
# Settings APIs
98+
"load_config",
99+
"_get_session_value",
100+
"update_datahub_server",
101+
"update_data_source_mode",
102+
"update_vectordb_settings",
103+
"update_llm_settings",
104+
"update_embedding_settings",
105+
"update_db_settings",
106+
"_put_env",
107+
"_put_session",
108+
# Registries - data sources
109+
"get_data_sources_registry",
110+
"_save_registry",
111+
"add_datahub_source",
112+
"update_datahub_source",
113+
"delete_datahub_source",
114+
"add_vectordb_source",
115+
"update_vectordb_source",
116+
"delete_vectordb_source",
117+
# Registries - db connections
118+
"get_db_connections_registry",
119+
"_save_db_registry",
120+
"add_db_connection",
121+
"update_db_connection",
122+
"delete_db_connection",
123+
# Registries - llm/embedding
124+
"get_llm_registry",
125+
"save_llm_profile",
126+
"_save_llm_registry",
127+
"get_embedding_registry",
128+
"save_embedding_profile",
129+
"_save_embedding_registry",
130+
# Persistence helpers and paths (for backward compatibility)
131+
"_get_registry_file_path",
132+
"_get_db_registry_file_path",
133+
"_get_llm_registry_file_path",
134+
"_get_embedding_registry_file_path",
135+
"_ensure_parent_dir",
136+
"save_registry_to_disk",
137+
"save_db_registry_to_disk",
138+
"save_llm_registry_to_disk",
139+
"save_embedding_registry_to_disk",
140+
"load_registry_from_disk",
141+
"load_db_registry_from_disk",
142+
"load_llm_registry_from_disk",
143+
"load_embedding_registry_from_disk",
144+
]

interface/core/config/models.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""설정 및 각 레지스트리에서 사용하는 데이터 모델(dataclass) 정의 모듈입니다."""
2+
3+
from dataclasses import dataclass, field
4+
from typing import List, Optional, Any, Dict
5+
6+
7+
@dataclass
8+
class Config:
9+
datahub_server: str
10+
vectordb_type: str
11+
vectordb_location: str
12+
data_source_mode: str | None = None # "datahub" | "vectordb" | None
13+
14+
15+
@dataclass
16+
class DataHubSource:
17+
name: str
18+
url: str
19+
faiss_path: Optional[str] = None
20+
note: Optional[str] = None
21+
22+
23+
@dataclass
24+
class VectorDBSource:
25+
name: str
26+
type: str # 'faiss' | 'pgvector'
27+
location: str
28+
collection_prefix: Optional[str] = None
29+
note: Optional[str] = None
30+
31+
32+
@dataclass
33+
class DataSourcesRegistry:
34+
datahub: List[DataHubSource] = field(default_factory=list)
35+
vectordb: List[VectorDBSource] = field(default_factory=list)
36+
37+
38+
@dataclass
39+
class DBConnectionProfile:
40+
name: str
41+
type: str # 'postgresql' | 'mysql' | 'mariadb' | 'oracle' | 'clickhouse' | 'duckdb' | 'sqlite' | 'databricks' | 'snowflake' | 'trino'
42+
host: Optional[str] = None
43+
port: Optional[int] = None
44+
user: Optional[str] = None
45+
password: Optional[str] = None
46+
database: Optional[str] = None
47+
extra: Optional[Dict[str, Any]] = None # non-secret
48+
note: Optional[str] = None
49+
50+
51+
@dataclass
52+
class DBConnectionsRegistry:
53+
connections: List[DBConnectionProfile] = field(default_factory=list)
54+
55+
56+
@dataclass
57+
class LLMProfile:
58+
name: str
59+
provider: (
60+
str # 'openai' | 'azure' | 'bedrock' | 'gemini' | 'ollama' | 'huggingface'
61+
)
62+
fields: Dict[str, str] = field(default_factory=dict) # includes secrets
63+
note: Optional[str] = None
64+
65+
66+
@dataclass
67+
class LLMRegistry:
68+
profiles: List[LLMProfile] = field(default_factory=list)
69+
70+
71+
@dataclass
72+
class EmbeddingProfile:
73+
name: str
74+
provider: (
75+
str # 'openai' | 'azure' | 'bedrock' | 'gemini' | 'ollama' | 'huggingface'
76+
)
77+
fields: Dict[str, str] = field(default_factory=dict)
78+
note: Optional[str] = None
79+
80+
81+
@dataclass
82+
class EmbeddingRegistry:
83+
profiles: List[EmbeddingProfile] = field(default_factory=list)

interface/core/config/paths.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""레지스트리 파일 경로 계산 및 상위 디렉토리 생성 유틸리티를 제공합니다."""
2+
3+
import os
4+
from pathlib import Path
5+
6+
7+
def _get_registry_file_path() -> Path:
8+
# Allow override via env var, else default to ./config/data_sources.json
9+
override = os.getenv("LANG2SQL_REGISTRY_PATH")
10+
if override:
11+
return Path(override).expanduser().resolve()
12+
return Path(os.getcwd()) / "config" / "data_sources.json"
13+
14+
15+
def _get_db_registry_file_path() -> Path:
16+
# Allow override via env var, else default to ./config/db_connections.json
17+
override = os.getenv("LANG2SQL_DB_REGISTRY_PATH")
18+
if override:
19+
return Path(override).expanduser().resolve()
20+
return Path(os.getcwd()) / "config" / "db_connections.json"
21+
22+
23+
def _get_llm_registry_file_path() -> Path:
24+
override = os.getenv("LANG2SQL_LLM_REGISTRY_PATH")
25+
if override:
26+
return Path(override).expanduser().resolve()
27+
return Path(os.getcwd()) / "config" / "llm_profiles.json"
28+
29+
30+
def _get_embedding_registry_file_path() -> Path:
31+
override = os.getenv("LANG2SQL_EMBEDDING_REGISTRY_PATH")
32+
if override:
33+
return Path(override).expanduser().resolve()
34+
return Path(os.getcwd()) / "config" / "embedding_profiles.json"
35+
36+
37+
def _ensure_parent_dir(path: Path) -> None:
38+
path.parent.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)