forked from AIBootcamp13/ai_bootcamp_13-upstageailab-ir-competition-Upstage-AI-Lab-5-Classroom-Repository-AI-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_data_config.py
More file actions
101 lines (84 loc) · 3.76 KB
/
switch_data_config.py
File metadata and controls
101 lines (84 loc) · 3.76 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
#!/usr/bin/env python3
"""
Configuration Switcher for RAG System Data Sources
This script helps switch between different data configurations easily.
"""
import sys
from pathlib import Path
import yaml
# Add src to python path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
def switch_data_config(config_name: str):
"""
Switch the data configuration in settings.yaml
Args:
config_name: Name of the data config file (without .yaml extension)
"""
settings_path = Path(__file__).parent / "conf" / "settings.yaml"
data_config_path = Path(__file__).parent / "conf" / "data" / f"{config_name}.yaml"
if not data_config_path.exists():
print(f"❌ Data configuration '{config_name}.yaml' not found in conf/data/")
list_available_configs()
return
# Read current settings
with open(settings_path, 'r', encoding='utf-8') as f:
settings = yaml.safe_load(f)
# Update the defaults section
if 'defaults' in settings:
for i, default in enumerate(settings['defaults']):
if default.startswith('data:'):
settings['defaults'][i] = f'data: {config_name}'
break
# Write back to settings.yaml
with open(settings_path, 'w', encoding='utf-8') as f:
yaml.dump(settings, f, default_flow_style=False, allow_unicode=True, sort_keys=False)
print(f"✅ Successfully switched to data configuration: {config_name}")
print(f"📁 Documents path: {get_config_value(data_config_path, 'documents_path')}")
print(f"📁 Validation path: {get_config_value(data_config_path, 'validation_path')}")
print(f"📁 Output path: {get_config_value(data_config_path, 'output_path')}")
def get_config_value(config_path: Path, key: str) -> str:
"""Get a value from a YAML config file"""
with open(config_path, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
return config.get(key, 'Not set')
def list_available_configs():
"""List all available data configurations"""
data_dir = Path(__file__).parent / "conf" / "data"
configs = [f.stem for f in data_dir.glob("*.yaml")]
print("\n📋 Available data configurations:")
for config in configs:
config_path = data_dir / f"{config}.yaml"
docs_path = get_config_value(config_path, 'documents_path')
print(f" • {config}: {docs_path}")
def show_current_config():
"""Show the current data configuration"""
settings_path = Path(__file__).parent / "conf" / "settings.yaml"
with open(settings_path, 'r', encoding='utf-8') as f:
settings = yaml.safe_load(f)
current_config = "unknown"
if 'defaults' in settings:
for default in settings['defaults']:
if isinstance(default, str) and default.startswith('data:'):
current_config = default.split(':', 1)[1].strip()
break
elif isinstance(default, dict) and 'data' in default:
current_config = default['data']
break
print(f"🔧 Current data configuration: {current_config}")
# Show the actual paths being used
data_config_path = Path(__file__).parent / "conf" / "data" / f"{current_config}.yaml"
if data_config_path.exists():
print(f"📁 Documents: {get_config_value(data_config_path, 'documents_path')}")
print(f"📁 Validation: {get_config_value(data_config_path, 'validation_path')}")
print(f"📁 Output: {get_config_value(data_config_path, 'output_path')}")
else:
print("⚠️ Configuration file not found")
if __name__ == "__main__":
import fire
print("🔄 RAG Data Configuration Switcher")
print("=" * 40)
fire.Fire({
'switch': switch_data_config,
'list': list_available_configs,
'current': show_current_config,
})