|
16 | 16 | from termcolor import cprint |
17 | 17 |
|
18 | 18 | from llama_stack.cli.subcommand import Subcommand |
19 | | -from llama_stack.core.datatypes import Api, Provider, StackConfig |
20 | | -from llama_stack.core.distribution import get_provider_registry |
21 | | -from llama_stack.core.stack import cast_distro_name_to_string, replace_env_vars |
22 | | -from llama_stack.core.storage.datatypes import ( |
23 | | - InferenceStoreReference, |
24 | | - KVStoreReference, |
25 | | - ServerStoresConfig, |
26 | | - SqliteKVStoreConfig, |
27 | | - SqliteSqlStoreConfig, |
28 | | - SqlStoreReference, |
29 | | - StorageConfig, |
30 | | -) |
| 19 | +from llama_stack.core.datatypes import StackConfig |
| 20 | +from llama_stack.core.stack import cast_distro_name_to_string, replace_env_vars, run_config_from_dynamic_config_spec |
31 | 21 | from llama_stack.core.utils.config_dirs import DISTRIBS_BASE_DIR |
32 | 22 | from llama_stack.core.utils.config_resolution import resolve_config_or_distro |
33 | | -from llama_stack.core.utils.dynamic import instantiate_class_type |
34 | 23 | from llama_stack.log import LoggingConfig, get_logger |
35 | 24 |
|
36 | 25 | REPO_ROOT = Path(__file__).parent.parent.parent.parent |
@@ -92,50 +81,20 @@ def _run_stack_run_cmd(self, args: argparse.Namespace) -> None: |
92 | 81 | except ValueError as e: |
93 | 82 | self.parser.error(str(e)) |
94 | 83 | elif args.providers: |
95 | | - provider_list: dict[str, list[Provider]] = dict() |
96 | | - for api_provider in args.providers.split(","): |
97 | | - if "=" not in api_provider: |
98 | | - cprint( |
99 | | - "Could not parse `--providers`. Please ensure the list is in the format api1=provider1,api2=provider2", |
100 | | - color="red", |
101 | | - file=sys.stderr, |
102 | | - ) |
103 | | - sys.exit(1) |
104 | | - api, provider_type = api_provider.split("=") |
105 | | - providers_for_api = get_provider_registry().get(Api(api), None) |
106 | | - if providers_for_api is None: |
107 | | - cprint( |
108 | | - f"{api} is not a valid API.", |
109 | | - color="red", |
110 | | - file=sys.stderr, |
111 | | - ) |
112 | | - sys.exit(1) |
113 | | - if provider_type in providers_for_api: |
114 | | - config_type = instantiate_class_type(providers_for_api[provider_type].config_class) |
115 | | - if config_type is not None and hasattr(config_type, "sample_run_config"): |
116 | | - config = config_type.sample_run_config(__distro_dir__="~/.llama/distributions/providers-run") |
117 | | - else: |
118 | | - config = {} |
119 | | - provider = Provider( |
120 | | - provider_type=provider_type, |
121 | | - config=config, |
122 | | - provider_id=provider_type.split("::")[1], |
123 | | - ) |
124 | | - provider_list.setdefault(api, []).append(provider) |
125 | | - else: |
126 | | - cprint( |
127 | | - f"{provider} is not a valid provider for the {api} API.", |
128 | | - color="red", |
129 | | - file=sys.stderr, |
130 | | - ) |
131 | | - sys.exit(1) |
132 | | - run_config = self._generate_run_config_from_providers(providers=provider_list) |
| 84 | + distro_dir = DISTRIBS_BASE_DIR / "providers-run" |
| 85 | + os.makedirs(distro_dir, exist_ok=True) |
| 86 | + try: |
| 87 | + run_config = run_config_from_dynamic_config_spec( |
| 88 | + dynamic_config_spec=args.providers, |
| 89 | + distro_dir=distro_dir, |
| 90 | + distro_name="providers-run", |
| 91 | + ) |
| 92 | + except ValueError as e: |
| 93 | + cprint(str(e), color="red", file=sys.stderr) |
| 94 | + sys.exit(1) |
133 | 95 | config_dict = run_config.model_dump(mode="json") |
134 | 96 |
|
135 | | - # Write config to disk in providers-run directory |
136 | | - distro_dir = DISTRIBS_BASE_DIR / "providers-run" |
137 | 97 | config_file = distro_dir / "config.yaml" |
138 | | - |
139 | 98 | logger.info(f"Writing generated config to: {config_file}") |
140 | 99 | with open(config_file, "w") as f: |
141 | 100 | yaml.dump(config_dict, f, default_flow_style=False, sort_keys=False) |
@@ -261,44 +220,3 @@ def _start_ui_development_server(self, stack_server_port: int): |
261 | 220 | ) |
262 | 221 | except Exception as e: |
263 | 222 | logger.error(f"Failed to start UI development server in {ui_dir}: {e}") |
264 | | - |
265 | | - def _generate_run_config_from_providers(self, providers: dict[str, list[Provider]]): |
266 | | - apis = list(providers.keys()) |
267 | | - distro_dir = DISTRIBS_BASE_DIR / "providers-run" |
268 | | - # need somewhere to put the storage. |
269 | | - os.makedirs(distro_dir, exist_ok=True) |
270 | | - storage = StorageConfig( |
271 | | - backends={ |
272 | | - "kv_default": SqliteKVStoreConfig( |
273 | | - db_path=f"${{env.SQLITE_STORE_DIR:={distro_dir}}}/kvstore.db", |
274 | | - ), |
275 | | - "sql_default": SqliteSqlStoreConfig( |
276 | | - db_path=f"${{env.SQLITE_STORE_DIR:={distro_dir}}}/sql_store.db", |
277 | | - ), |
278 | | - }, |
279 | | - stores=ServerStoresConfig( |
280 | | - metadata=KVStoreReference( |
281 | | - backend="kv_default", |
282 | | - namespace="registry", |
283 | | - ), |
284 | | - inference=InferenceStoreReference( |
285 | | - backend="sql_default", |
286 | | - table_name="inference_store", |
287 | | - ), |
288 | | - conversations=SqlStoreReference( |
289 | | - backend="sql_default", |
290 | | - table_name="openai_conversations", |
291 | | - ), |
292 | | - prompts=KVStoreReference( |
293 | | - backend="kv_default", |
294 | | - namespace="prompts", |
295 | | - ), |
296 | | - ), |
297 | | - ) |
298 | | - |
299 | | - return StackConfig( |
300 | | - distro_name="providers-run", |
301 | | - apis=apis, |
302 | | - providers=providers, |
303 | | - storage=storage, |
304 | | - ) |
0 commit comments