Spaces:
Running
Running
regraded01
commited on
Commit
·
d628c92
1
Parent(s):
9f5f200
refactor: extract key-value pairs from a yml using a function
Browse files- src/utils.py +24 -0
src/utils.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import yaml
|
2 |
+
|
3 |
+
# Load in model configuration and check the required keys are present
|
4 |
+
model_config_dir = "config/model_config.yml"
|
5 |
+
config_keys = ["system_message", "model_id", "template"]
|
6 |
+
|
7 |
+
def load_config_values(
|
8 |
+
model_config_dir=model_config_dir,
|
9 |
+
config_keys=config_keys
|
10 |
+
):
|
11 |
+
"""
|
12 |
+
Function to extract user-input keys from config.yml
|
13 |
+
Returns `system_message`, `model_id`, `template`.
|
14 |
+
TO DO: fix how the function returns values so can be flexible (based on the order of the input `config_keys` list)
|
15 |
+
|
16 |
+
"""
|
17 |
+
with open(model_config_dir, "r") as file:
|
18 |
+
model_config = yaml.safe_load(file)
|
19 |
+
|
20 |
+
for var in model_config.keys():
|
21 |
+
if var not in config_keys:
|
22 |
+
raise ValueError(f"`{var}` key missing from `{model_config_dir}`")
|
23 |
+
|
24 |
+
return model_config["system_message"], model_config["model_id"], model_config["template"]
|