mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 18:00:36 +00:00
fix: fixup config_resolution.py
fix some config resolution logic that still had "Modes" (build or run) and was using run.yaml Signed-off-by: Charlie Doern <cdoern@redhat.com>
This commit is contained in:
parent
0424afb7ed
commit
7a57957f13
5 changed files with 22 additions and 30 deletions
2
.github/workflows/backward-compat.yml
vendored
2
.github/workflows/backward-compat.yml
vendored
|
|
@ -1,6 +1,6 @@
|
||||||
name: Backward Compatibility Check
|
name: Backward Compatibility Check
|
||||||
|
|
||||||
run-name: Check backward compatibility for config.yaml configs
|
run-name: Check backward compatibility for config.yaml files
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
|
||||||
|
|
@ -64,9 +64,9 @@ def format_output_deps_only(
|
||||||
def run_stack_list_deps_command(args: argparse.Namespace) -> None:
|
def run_stack_list_deps_command(args: argparse.Namespace) -> None:
|
||||||
if args.config:
|
if args.config:
|
||||||
try:
|
try:
|
||||||
from llama_stack.core.utils.config_resolution import Mode, resolve_config_or_distro
|
from llama_stack.core.utils.config_resolution import resolve_config_or_distro
|
||||||
|
|
||||||
config_file = resolve_config_or_distro(args.config, Mode.RUN)
|
config_file = resolve_config_or_distro(args.config)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
cprint(
|
cprint(
|
||||||
f"Could not parse config file {args.config}: {e}",
|
f"Could not parse config file {args.config}: {e}",
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ from llama_stack.core.storage.datatypes import (
|
||||||
StorageConfig,
|
StorageConfig,
|
||||||
)
|
)
|
||||||
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
|
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
|
||||||
from llama_stack.core.utils.config_resolution import Mode, resolve_config_or_distro
|
from llama_stack.core.utils.config_resolution import resolve_config_or_distro
|
||||||
from llama_stack.core.utils.dynamic import instantiate_class_type
|
from llama_stack.core.utils.dynamic import instantiate_class_type
|
||||||
from llama_stack.log import LoggingConfig, get_logger
|
from llama_stack.log import LoggingConfig, get_logger
|
||||||
|
|
||||||
|
|
@ -108,9 +108,9 @@ class StackRun(Subcommand):
|
||||||
|
|
||||||
if args.config:
|
if args.config:
|
||||||
try:
|
try:
|
||||||
from llama_stack.core.utils.config_resolution import Mode, resolve_config_or_distro
|
from llama_stack.core.utils.config_resolution import resolve_config_or_distro
|
||||||
|
|
||||||
config_file = resolve_config_or_distro(args.config, Mode.RUN)
|
config_file = resolve_config_or_distro(args.config)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
self.parser.error(str(e))
|
self.parser.error(str(e))
|
||||||
elif args.providers:
|
elif args.providers:
|
||||||
|
|
@ -187,7 +187,7 @@ class StackRun(Subcommand):
|
||||||
if not config_file:
|
if not config_file:
|
||||||
self.parser.error("Config file is required")
|
self.parser.error("Config file is required")
|
||||||
|
|
||||||
config_file = resolve_config_or_distro(str(config_file), Mode.RUN)
|
config_file = resolve_config_or_distro(str(config_file))
|
||||||
with open(config_file) as fp:
|
with open(config_file) as fp:
|
||||||
config_contents = yaml.safe_load(fp)
|
config_contents = yaml.safe_load(fp)
|
||||||
if isinstance(config_contents, dict) and (cfg := config_contents.get("logging_config")):
|
if isinstance(config_contents, dict) and (cfg := config_contents.get("logging_config")):
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ from llama_stack.core.stack import (
|
||||||
from llama_stack.core.telemetry import Telemetry
|
from llama_stack.core.telemetry import Telemetry
|
||||||
from llama_stack.core.telemetry.tracing import CURRENT_TRACE_CONTEXT, setup_logger
|
from llama_stack.core.telemetry.tracing import CURRENT_TRACE_CONTEXT, setup_logger
|
||||||
from llama_stack.core.utils.config import redact_sensitive_fields
|
from llama_stack.core.utils.config import redact_sensitive_fields
|
||||||
from llama_stack.core.utils.config_resolution import Mode, resolve_config_or_distro
|
from llama_stack.core.utils.config_resolution import resolve_config_or_distro
|
||||||
from llama_stack.core.utils.context import preserve_contexts_async_generator
|
from llama_stack.core.utils.context import preserve_contexts_async_generator
|
||||||
from llama_stack.log import LoggingConfig, get_logger, setup_logging
|
from llama_stack.log import LoggingConfig, get_logger, setup_logging
|
||||||
from llama_stack_api import Api, ConflictError, PaginatedResponse, ResourceNotFoundError
|
from llama_stack_api import Api, ConflictError, PaginatedResponse, ResourceNotFoundError
|
||||||
|
|
@ -374,7 +374,7 @@ def create_app() -> StackApp:
|
||||||
if config_file is None:
|
if config_file is None:
|
||||||
raise ValueError("LLAMA_STACK_CONFIG environment variable is required")
|
raise ValueError("LLAMA_STACK_CONFIG environment variable is required")
|
||||||
|
|
||||||
config_file = resolve_config_or_distro(config_file, Mode.RUN)
|
config_file = resolve_config_or_distro(config_file)
|
||||||
|
|
||||||
# Load and process configuration
|
# Load and process configuration
|
||||||
logger_config = None
|
logger_config = None
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
# This source code is licensed under the terms described in the LICENSE file in
|
# This source code is licensed under the terms described in the LICENSE file in
|
||||||
# the root directory of this source tree.
|
# the root directory of this source tree.
|
||||||
|
|
||||||
from enum import StrEnum
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
|
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
|
||||||
|
|
@ -16,21 +15,14 @@ logger = get_logger(name=__name__, category="core")
|
||||||
DISTRO_DIR = Path(__file__).parent.parent.parent.parent / "llama_stack" / "distributions"
|
DISTRO_DIR = Path(__file__).parent.parent.parent.parent / "llama_stack" / "distributions"
|
||||||
|
|
||||||
|
|
||||||
class Mode(StrEnum):
|
|
||||||
RUN = "run"
|
|
||||||
BUILD = "build"
|
|
||||||
|
|
||||||
|
|
||||||
def resolve_config_or_distro(
|
def resolve_config_or_distro(
|
||||||
config_or_distro: str,
|
config_or_distro: str,
|
||||||
mode: Mode = Mode.RUN,
|
|
||||||
) -> Path:
|
) -> Path:
|
||||||
"""
|
"""
|
||||||
Resolve a config/distro argument to a concrete config file path.
|
Resolve a config/distro argument to a concrete config file path.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
config_or_distro: User input (file path, distribution name, or built distribution)
|
config_or_distro: User input (file path, distribution name, or built distribution)
|
||||||
mode: Mode resolving for ("run", "build", "server")
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Path to the resolved config file
|
Path to the resolved config file
|
||||||
|
|
@ -47,7 +39,7 @@ def resolve_config_or_distro(
|
||||||
|
|
||||||
# Strategy 2: Try as distribution name (if no .yaml extension)
|
# Strategy 2: Try as distribution name (if no .yaml extension)
|
||||||
if not config_or_distro.endswith(".yaml"):
|
if not config_or_distro.endswith(".yaml"):
|
||||||
distro_config = _get_distro_config_path(config_or_distro, mode)
|
distro_config = _get_distro_config_path(config_or_distro)
|
||||||
if distro_config.exists():
|
if distro_config.exists():
|
||||||
logger.debug(f"Using distribution: {distro_config}")
|
logger.debug(f"Using distribution: {distro_config}")
|
||||||
return distro_config
|
return distro_config
|
||||||
|
|
@ -63,34 +55,34 @@ def resolve_config_or_distro(
|
||||||
return distro_config
|
return distro_config
|
||||||
|
|
||||||
# Strategy 4: Try as built distribution name
|
# Strategy 4: Try as built distribution name
|
||||||
distrib_config = DISTRIBS_BASE_DIR / f"llamastack-{config_or_distro}" / f"{config_or_distro}-{mode}.yaml"
|
distrib_config = DISTRIBS_BASE_DIR / f"llamastack-{config_or_distro}" / f"{config_or_distro}-config.yaml"
|
||||||
if distrib_config.exists():
|
if distrib_config.exists():
|
||||||
logger.debug(f"Using built distribution: {distrib_config}")
|
logger.debug(f"Using built distribution: {distrib_config}")
|
||||||
return distrib_config
|
return distrib_config
|
||||||
|
|
||||||
distrib_config = DISTRIBS_BASE_DIR / f"{config_or_distro}" / f"{config_or_distro}-{mode}.yaml"
|
distrib_config = DISTRIBS_BASE_DIR / f"{config_or_distro}" / "config.yaml"
|
||||||
if distrib_config.exists():
|
if distrib_config.exists():
|
||||||
logger.debug(f"Using built distribution: {distrib_config}")
|
logger.debug(f"Using built distribution: {distrib_config}")
|
||||||
return distrib_config
|
return distrib_config
|
||||||
|
|
||||||
# Strategy 5: Failed - provide helpful error
|
# Strategy 5: Failed - provide helpful error
|
||||||
raise ValueError(_format_resolution_error(config_or_distro, mode))
|
raise ValueError(_format_resolution_error(config_or_distro))
|
||||||
|
|
||||||
|
|
||||||
def _get_distro_config_path(distro_name: str, mode: str) -> Path:
|
def _get_distro_config_path(distro_name: str, path: str | None = None) -> Path:
|
||||||
"""Get the config file path for a distro."""
|
"""Get the config file path for a distro."""
|
||||||
if not mode.endswith(".yaml"):
|
if not path or not path.endswith(".yaml"):
|
||||||
mode = f"{mode}.yaml"
|
path = "config.yaml"
|
||||||
return DISTRO_DIR / distro_name / mode
|
return DISTRO_DIR / distro_name / path
|
||||||
|
|
||||||
|
|
||||||
def _format_resolution_error(config_or_distro: str, mode: Mode) -> str:
|
def _format_resolution_error(config_or_distro: str) -> str:
|
||||||
"""Format a helpful error message for resolution failures."""
|
"""Format a helpful error message for resolution failures."""
|
||||||
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
|
from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR
|
||||||
|
|
||||||
distro_path = _get_distro_config_path(config_or_distro, mode)
|
distro_path = _get_distro_config_path(config_or_distro)
|
||||||
distrib_path = DISTRIBS_BASE_DIR / f"llamastack-{config_or_distro}" / f"{config_or_distro}-{mode}.yaml"
|
distrib_path = DISTRIBS_BASE_DIR / f"llamastack-{config_or_distro}" / f"{config_or_distro}-config.yaml"
|
||||||
distrib_path2 = DISTRIBS_BASE_DIR / f"{config_or_distro}" / f"{config_or_distro}-{mode}.yaml"
|
distrib_path2 = DISTRIBS_BASE_DIR / f"{config_or_distro}" / f"{config_or_distro}-config.yaml"
|
||||||
|
|
||||||
available_distros = _get_available_distros()
|
available_distros = _get_available_distros()
|
||||||
distros_str = ", ".join(available_distros) if available_distros else "none found"
|
distros_str = ", ".join(available_distros) if available_distros else "none found"
|
||||||
|
|
@ -111,7 +103,7 @@ Did you mean one of these distributions?
|
||||||
|
|
||||||
def _get_available_distros() -> list[str]:
|
def _get_available_distros() -> list[str]:
|
||||||
"""Get list of available distro names."""
|
"""Get list of available distro names."""
|
||||||
if not DISTRO_DIR.exists() and not DISTRIBS_BASE_DIR.exists():
|
if not DISTRO_DIR.exists() or not DISTRIBS_BASE_DIR.exists():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return list(
|
return list(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue