Skip to content

Commit 49bd221

Browse files
committed
LCORE-642: Llama Stack configuration processing stub
1 parent 778123e commit 49bd221

2 files changed

Lines changed: 80 additions & 1 deletion

File tree

src/lightspeed_stack.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010

1111
from rich.logging import RichHandler
1212

13+
from log import get_logger
1314
from configuration import configuration
15+
from llama_stack_configuration import generate_configuration
1416
from runners.uvicorn import start_uvicorn
1517

1618
FORMAT = "%(message)s"
1719
logging.basicConfig(
1820
level="INFO", format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
1921
)
2022

21-
logger = logging.getLogger(__name__)
23+
logger = get_logger(__name__)
2224

2325

2426
def create_argument_parser() -> ArgumentParser:
@@ -47,6 +49,28 @@ def create_argument_parser() -> ArgumentParser:
4749
help="path to configuration file (default: lightspeed-stack.yaml)",
4850
default="lightspeed-stack.yaml",
4951
)
52+
parser.add_argument(
53+
"-g",
54+
"--generate-llama-stack-configuration",
55+
dest="generate_llama_stack_configuration",
56+
help="generate Llama Stack configuration based on LCORE configuration",
57+
action="store_true",
58+
default=False,
59+
)
60+
parser.add_argument(
61+
"-i",
62+
"--input-config-file",
63+
dest="input_config_file",
64+
help="Llama Stack input configuration file",
65+
default="run.yaml",
66+
)
67+
parser.add_argument(
68+
"-o",
69+
"--output-config-file",
70+
dest="output_config_file",
71+
help="Llama Stack output configuration file",
72+
default="run_.yaml",
73+
)
5074

5175
return parser
5276

@@ -74,6 +98,24 @@ def main() -> None:
7498
raise SystemExit(1) from e
7599
return
76100

101+
# -g or --generate-llama-stack-configuration CLI flags are used to (re)generate
102+
# configuration for Llama Stack
103+
if args.generate_llama_stack_configuration:
104+
try:
105+
generate_configuration(
106+
args.input_config_file,
107+
args.output_config_file,
108+
configuration.configuration,
109+
)
110+
logger.info(
111+
"Llama Stack configuration generated and stored into %s",
112+
args.output_config_file,
113+
)
114+
except Exception as e:
115+
logger.error("Failed to generate Llama Stack configuration: %s", e)
116+
raise SystemExit(1) from e
117+
return
118+
77119
# Store config path in env so each uvicorn worker can load it
78120
# (step is needed because process context isn’t shared).
79121
os.environ["LIGHTSPEED_STACK_CONFIG_PATH"] = args.config_file

src/llama_stack_configuration.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Llama Stack configuration handling."""
2+
3+
import yaml
4+
5+
from log import get_logger
6+
7+
from models.config import Configuration
8+
9+
logger = get_logger(__name__)
10+
11+
12+
# pylint: disable=too-many-ancestors
13+
class YamlDumper(yaml.Dumper):
14+
"""Custom YAML dumper with proper indentation levels."""
15+
16+
def increase_indent(self, flow: bool = False, indentless: bool = False) -> None:
17+
"""Control the indentation level of formatted YAML output."""
18+
_ = indentless
19+
return super().increase_indent(flow, False)
20+
21+
22+
def generate_configuration(
23+
input_file: str, output_file: str, config: Configuration
24+
) -> None:
25+
"""Generate new Llama Stack configuration."""
26+
logger.info("Reading Llama Stack configuration from file %s", input_file)
27+
28+
with open(input_file, "r", encoding="utf-8") as file:
29+
ls_config = yaml.safe_load(file)
30+
31+
logger.info("Processing Llama Stack configuration")
32+
_ = config
33+
34+
logger.info("Writing Llama Stack configuration into file %s", output_file)
35+
36+
with open(output_file, "w", encoding="utf-8") as file:
37+
yaml.dump(ls_config, file, Dumper=YamlDumper, default_flow_style=False)

0 commit comments

Comments
 (0)