Skip to content

Commit 8c3874e

Browse files
Expose unified synthesis mode via the CLI
The CLI (python llama_stack_configuration.py -c config.yaml) only called generate_configuration(), the legacy enrichment mode that requires an already-built run.yaml as input. There was no CLI path to synthesize_configuration()/synthesize_to_file(), the unified mode that builds run.yaml from lightspeed-stack.yaml alone, so consumers of unified mode had to import the module instead of using the documented script interface. Add a --synthesize flag: when set, the CLI builds the config via synthesize_to_file() from -c alone (ignoring -i), instead of enriching an existing run.yaml.
1 parent 9f674ef commit 8c3874e

2 files changed

Lines changed: 90 additions & 4 deletions

File tree

src/llama_stack_configuration.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ def generate_configuration(
14571457
def main() -> None:
14581458
"""CLI entry point."""
14591459
parser = ArgumentParser(
1460-
description="Enrich Llama Stack config with Lightspeed values",
1460+
description="Enrich or synthesize Llama Stack config from Lightspeed values",
14611461
)
14621462
parser.add_argument(
14631463
"-c",
@@ -1469,20 +1469,32 @@ def main() -> None:
14691469
"-i",
14701470
"--input",
14711471
default="run.yaml",
1472-
help="Input Llama Stack config (default: run.yaml)",
1472+
help="Input Llama Stack config for legacy enrichment mode; ignored "
1473+
"with --synthesize (default: run.yaml)",
14731474
)
14741475
parser.add_argument(
14751476
"-o",
14761477
"--output",
14771478
default="run_.yaml",
1478-
help="Output enriched config (default: run_.yaml)",
1479+
help="Output config file (default: run_.yaml)",
1480+
)
1481+
parser.add_argument(
1482+
"--synthesize",
1483+
action="store_true",
1484+
help="Use unified synthesis mode (LCORE-2336): build a complete "
1485+
"run.yaml from -c alone instead of legacy enrichment of -i",
14791486
)
14801487
args = parser.parse_args()
14811488

14821489
with open(args.config, "r", encoding="utf-8") as f:
14831490
config = yaml.safe_load(f)
14841491

1485-
generate_configuration(args.input, args.output, config)
1492+
if args.synthesize:
1493+
synthesize_to_file(
1494+
config, args.output, config_file_dir=str(Path(args.config).parent)
1495+
)
1496+
else:
1497+
generate_configuration(args.input, args.output, config)
14861498

14871499

14881500
if __name__ == "__main__":

tests/unit/test_llama_stack_synthesize.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import stat
11+
import sys
1112
from pathlib import Path
1213
from typing import Any, Optional, get_args
1314

@@ -20,6 +21,7 @@
2021
deep_merge_list_replace,
2122
ensure_mcp_tool_runtime,
2223
load_default_baseline,
24+
main,
2325
migrate_config_dumb,
2426
synthesize_configuration,
2527
synthesize_to_file,
@@ -915,6 +917,78 @@ def test_migrate_config_dumb_rejects_non_mapping_inputs(tmp_path: Path) -> None:
915917
migrate_config_dumb(str(empty_run), lcs_path, out_path)
916918

917919

920+
# ---------------------------------------------------------------------------
921+
# CLI entry point
922+
# ---------------------------------------------------------------------------
923+
924+
925+
def test_main_synthesize_flag_builds_run_yaml(
926+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
927+
) -> None:
928+
"""--synthesize builds a complete run.yaml from -c alone."""
929+
config_path = tmp_path / "lightspeed-stack.yaml"
930+
config_path.write_text(
931+
yaml.dump(
932+
{
933+
"llama_stack": {
934+
"config": {
935+
"baseline": "empty",
936+
"native_override": {"version": 2, "apis": ["inference"]},
937+
}
938+
}
939+
}
940+
),
941+
encoding="utf-8",
942+
)
943+
output_path = tmp_path / "run.yaml"
944+
945+
monkeypatch.setattr(
946+
sys,
947+
"argv",
948+
[
949+
"llama_stack_configuration.py",
950+
"-c",
951+
str(config_path),
952+
"-o",
953+
str(output_path),
954+
"--synthesize",
955+
],
956+
)
957+
main()
958+
959+
result = yaml.safe_load(output_path.read_text(encoding="utf-8"))
960+
assert result == {"version": 2, "apis": ["inference"]}
961+
962+
963+
def test_main_default_uses_legacy_enrichment(
964+
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
965+
) -> None:
966+
"""Without --synthesize, the CLI keeps calling legacy generate_configuration."""
967+
config_path = tmp_path / "lightspeed-stack.yaml"
968+
config_path.write_text(yaml.dump({}), encoding="utf-8")
969+
input_path = tmp_path / "run.yaml"
970+
input_path.write_text(yaml.dump({"version": 2}), encoding="utf-8")
971+
output_path = tmp_path / "run_.yaml"
972+
973+
monkeypatch.setattr(
974+
sys,
975+
"argv",
976+
[
977+
"llama_stack_configuration.py",
978+
"-c",
979+
str(config_path),
980+
"-i",
981+
str(input_path),
982+
"-o",
983+
str(output_path),
984+
],
985+
)
986+
main()
987+
988+
result = yaml.safe_load(output_path.read_text(encoding="utf-8"))
989+
assert result["version"] == 2
990+
991+
918992
# ---------------------------------------------------------------------------
919993
# reference profiles (LCORE-2346)
920994
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)