Configuration class for the Ariadne toolkit. Loads settings from a YAML file and provides structured access to
configuration parameters.
Source code in src/ariadne/utils/config.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 | class Config:
"""
Configuration class for the Ariadne toolkit. Loads settings from a YAML file and provides structured access to
configuration parameters.
"""
system: SystemConfig = field(default_factory=SystemConfig)
verbatim_mapping: VerbatimMapping = field(default_factory=VerbatimMapping)
term_cleaning: TermCleaning = field(default_factory=TermCleaning)
vector_search: VectorSearch = field(default_factory=VectorSearch)
llm_mapping: Llm_mapping = field(default_factory=Llm_mapping)
def __init__(self, filename: str = "config.yaml"):
"""
Initializes the Config object by loading settings from the specified YAML file.
Args:
filename: The path to the YAML configuration file. Defaults to 'config.yaml' in the current working
directory or project root.
"""
path = Path.cwd() / filename
if not path.exists():
path = get_project_root() / filename
if not path.exists():
raise FileNotFoundError(f"Could not find {filename} in {Path.cwd()} or project root.")
with path.open("r", encoding="utf-8") as fh:
raw = yaml.safe_load(fh) or {}
self.system = self.from_dict(SystemConfig, raw["system"])
self.verbatim_mapping = self.from_dict(VerbatimMapping, raw["verbatim_mapping"])
self.term_cleaning = self.from_dict(TermCleaning, raw["term_cleaning"])
self.vector_search = self.from_dict(VectorSearch, raw["vector_search"])
self.llm_mapping = self.from_dict(Llm_mapping, raw["llm_mapping"])
def from_dict(self, cls: Type["Config"], data: Dict[str, Any]) -> "Config":
def build(dc_type: Type[Any], subdata: Dict[str, Any]) -> Any:
if not is_dataclass(dc_type):
return subdata
kw = {}
for f in fields(dc_type):
if subdata is None or f.name not in subdata:
continue
value = subdata[f.name]
if is_dataclass(f.type):
kw[f.name] = build(f.type, value or {})
else:
kw[f.name] = value
return dc_type(**kw)
return build(cls, data)
def to_dict(self) -> Dict[str, Any]:
def serialize(obj: Any) -> Any:
if is_dataclass(obj):
result = {}
for f in fields(obj):
value = getattr(obj, f.name)
result[f.name] = serialize(value)
return result
elif isinstance(obj, list):
return [serialize(item) for item in obj]
else:
return obj
return {
"system": serialize(self.system),
"verbatim_mapping": serialize(self.verbatim_mapping),
"term_cleaning": serialize(self.term_cleaning),
"vector_search": serialize(self.vector_search),
"llm_mapping": serialize(self.llm_mapping),
}
|
__init__(filename='config.yaml')
Initializes the Config object by loading settings from the specified YAML file.
Parameters:
| Name |
Type |
Description |
Default |
filename
|
str
|
The path to the YAML configuration file. Defaults to 'config.yaml' in the current working
directory or project root.
|
'config.yaml'
|
Source code in src/ariadne/utils/config.py
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 | def __init__(self, filename: str = "config.yaml"):
"""
Initializes the Config object by loading settings from the specified YAML file.
Args:
filename: The path to the YAML configuration file. Defaults to 'config.yaml' in the current working
directory or project root.
"""
path = Path.cwd() / filename
if not path.exists():
path = get_project_root() / filename
if not path.exists():
raise FileNotFoundError(f"Could not find {filename} in {Path.cwd()} or project root.")
with path.open("r", encoding="utf-8") as fh:
raw = yaml.safe_load(fh) or {}
self.system = self.from_dict(SystemConfig, raw["system"])
self.verbatim_mapping = self.from_dict(VerbatimMapping, raw["verbatim_mapping"])
self.term_cleaning = self.from_dict(TermCleaning, raw["term_cleaning"])
self.vector_search = self.from_dict(VectorSearch, raw["vector_search"])
self.llm_mapping = self.from_dict(Llm_mapping, raw["llm_mapping"])
|