mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-04 04:04:14 +00:00
26 lines
882 B
Python
26 lines
882 B
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the terms described in the LICENSE file in
|
|
# the root directory of this source tree.
|
|
|
|
import asyncio
|
|
import importlib
|
|
from typing import Any, Dict
|
|
|
|
from .datatypes import SourceAdapter
|
|
|
|
|
|
def instantiate_class_type(fully_qualified_name):
|
|
module_name, class_name = fully_qualified_name.rsplit(".", 1)
|
|
module = importlib.import_module(module_name)
|
|
return getattr(module, class_name)
|
|
|
|
|
|
# returns a class implementing the protocol corresponding to the ApiSurface
|
|
def instantiate_adapter(adapter: SourceAdapter, adapter_config: Dict[str, Any]):
|
|
module = importlib.import_module(adapter.module)
|
|
|
|
config_type = instantiate_class_type(adapter.config_class)
|
|
config = config_type(**adapter_config)
|
|
return asyncio.run(module.get_adapter_impl(config))
|