feat: Add support for yaml based configs · commit4ever/llama-cpp-python@060bfa6 · GitHub
Skip to content

Commit 060bfa6

Browse files
committed
feat: Add support for yaml based configs
1 parent 1347e1d commit 060bfa6

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

Lines changed: 30 additions & 0 deletions

llama_cpp/server/__main__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ def main():
5959
if not os.path.exists(config_file):
6060
raise ValueError(f"Config file {config_file} not found!")
6161
with open(config_file, "rb") as f:
62-
config_file_settings = ConfigFileSettings.model_validate_json(f.read())
62+
# Check if yaml file
63+
if config_file.endswith(".yaml") or config_file.endswith(".yml"):
64+
import yaml
65+
import json
66+
67+
config_file_settings = ConfigFileSettings.model_validate_json(
68+
json.dumps(yaml.safe_load(f))
69+
)
70+
else:
71+
config_file_settings = ConfigFileSettings.model_validate_json(f.read())
6372
server_settings = ServerSettings.model_validate(config_file_settings)
6473
model_settings = config_file_settings.models
6574
else:

llama_cpp/server/app.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,15 @@ def create_app(
9797
if not os.path.exists(config_file):
9898
raise ValueError(f"Config file {config_file} not found!")
9999
with open(config_file, "rb") as f:
100-
config_file_settings = ConfigFileSettings.model_validate_json(f.read())
100+
# Check if yaml file
101+
if config_file.endswith(".yaml") or config_file.endswith(".yml"):
102+
import yaml
103+
104+
config_file_settings = ConfigFileSettings.model_validate_json(
105+
json.dumps(yaml.safe_load(f))
106+
)
107+
else:
108+
config_file_settings = ConfigFileSettings.model_validate_json(f.read())
101109
server_settings = ServerSettings.model_validate(config_file_settings)
102110
model_settings = config_file_settings.models
103111

pyproject.toml

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)