mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-30 07:39:38 +00:00
models config refactor
This commit is contained in:
parent
552b747136
commit
54cd9ded80
3 changed files with 18 additions and 5 deletions
|
@ -18,6 +18,8 @@ async def get_provider_impl(config: BuiltinImplConfig, deps: Dict[Api, ProviderS
|
||||||
config, BuiltinImplConfig
|
config, BuiltinImplConfig
|
||||||
), f"Unexpected config type: {type(config)}"
|
), f"Unexpected config type: {type(config)}"
|
||||||
|
|
||||||
|
print(config)
|
||||||
|
|
||||||
impl = BuiltinModelsImpl(config)
|
impl = BuiltinModelsImpl(config)
|
||||||
await impl.initialize()
|
await impl.initialize()
|
||||||
return impl
|
return impl
|
||||||
|
|
|
@ -4,15 +4,21 @@
|
||||||
# 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 typing import Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from llama_models.datatypes import ModelFamily
|
|
||||||
|
|
||||||
from llama_models.schema_utils import json_schema_type
|
from llama_models.schema_utils import json_schema_type
|
||||||
from llama_models.sku_list import all_registered_models, resolve_model
|
from llama_models.sku_list import all_registered_models, resolve_model
|
||||||
|
from llama_stack.distribution.datatypes import GenericProviderConfig
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, field_validator
|
from pydantic import BaseModel, Field, field_validator
|
||||||
|
|
||||||
|
|
||||||
@json_schema_type
|
@json_schema_type
|
||||||
class BuiltinImplConfig(BaseModel): ...
|
class ModelConfigProviderEntry(GenericProviderConfig):
|
||||||
|
api: str
|
||||||
|
core_model_id: str
|
||||||
|
|
||||||
|
|
||||||
|
@json_schema_type
|
||||||
|
class BuiltinImplConfig(BaseModel):
|
||||||
|
models_config: List[ModelConfigProviderEntry]
|
||||||
|
|
|
@ -14,6 +14,7 @@ from llama_stack.apis.models import * # noqa: F403
|
||||||
from llama_models.llama3.api.datatypes import * # noqa: F403
|
from llama_models.llama3.api.datatypes import * # noqa: F403
|
||||||
from llama_models.datatypes import CoreModelId, Model
|
from llama_models.datatypes import CoreModelId, Model
|
||||||
from llama_models.sku_list import resolve_model
|
from llama_models.sku_list import resolve_model
|
||||||
|
from termcolor import cprint
|
||||||
|
|
||||||
from .config import BuiltinImplConfig
|
from .config import BuiltinImplConfig
|
||||||
|
|
||||||
|
@ -34,21 +35,25 @@ class BuiltinModelsImpl(Models):
|
||||||
config: BuiltinImplConfig,
|
config: BuiltinImplConfig,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
self.models = {
|
self.models = {
|
||||||
x.llama_model_metadata.core_model_id.value: x
|
x.llama_model_metadata.core_model_id.value: x
|
||||||
for x in [DUMMY_MODELS_SPEC_1, DUMMY_MODELS_SPEC_2]
|
for x in [DUMMY_MODELS_SPEC_1, DUMMY_MODELS_SPEC_2]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cprint(self.config, "red")
|
||||||
|
|
||||||
async def initialize(self) -> None:
|
async def initialize(self) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def list_models(self) -> ModelsListResponse:
|
async def list_models(self) -> ModelsListResponse:
|
||||||
|
print(self.config, "hihihi")
|
||||||
return ModelsListResponse(models_list=list(self.models.values()))
|
return ModelsListResponse(models_list=list(self.models.values()))
|
||||||
|
|
||||||
async def get_model(self, core_model_id: str) -> ModelsGetResponse:
|
async def get_model(self, core_model_id: str) -> ModelsGetResponse:
|
||||||
if core_model_id in self.models:
|
if core_model_id in self.models:
|
||||||
return ModelsGetResponse(core_model_spec=self.models[core_model_id])
|
return ModelsGetResponse(core_model_spec=self.models[core_model_id])
|
||||||
raise ValueError(f"Cannot find {core_model_id} in model registry")
|
raise RuntimeError(f"Cannot find {core_model_id} in model registry")
|
||||||
|
|
||||||
async def register_model(
|
async def register_model(
|
||||||
self, model_id: str, api: str, provider_spec: Dict[str, str]
|
self, model_id: str, api: str, provider_spec: Dict[str, str]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue