-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
46 lines (36 loc) · 1.27 KB
/
config.py
File metadata and controls
46 lines (36 loc) · 1.27 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
"""
Configuration management for Txt2SQL.
"""
import os
from pathlib import Path
from typing import Optional
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
class Config:
"""Application configuration."""
def __init__(self, model_path: Optional[str] = None):
"""
Initialize configuration.
Args:
model_path: Path to the T5 model directory (from env or parameter)
"""
# Only model path comes from environment
self.model_path = model_path or os.getenv("WIKISQL_MODEL")
# Model settings - fixed defaults
self.max_length = 128
self.num_beams = 2
self.torch_threads = 2
# Validate model path
self._validate()
def _validate(self) -> None:
"""Validate configuration values."""
if not self.model_path:
raise ValueError(
"Model path not configured. Set WIKISQL_MODEL environment variable "
"or pass model_path parameter."
)
if not Path(self.model_path).exists():
raise FileNotFoundError(f"Model not found at: {self.model_path}")
def __repr__(self) -> str:
return f"Config(model_path='{self.model_path}')"