mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-08 03:00:56 +00:00
32 lines
955 B
Python
32 lines
955 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.
|
|
from typing import AbstractSet, Dict, Generic, TypeVar
|
|
|
|
TRegistry = TypeVar("TRegistry")
|
|
|
|
|
|
class Registry(Generic[TRegistry]):
|
|
_REGISTRY: Dict[str, TRegistry] = {}
|
|
|
|
@staticmethod
|
|
def names() -> AbstractSet[str]:
|
|
return Registry._REGISTRY.keys()
|
|
|
|
@staticmethod
|
|
def register(name: str, task: TRegistry) -> None:
|
|
if name in Registry._REGISTRY:
|
|
raise ValueError(f"Dataset {name} already exists.")
|
|
Registry._REGISTRY[name] = task
|
|
|
|
@staticmethod
|
|
def get(name: str) -> TRegistry:
|
|
if name not in Registry._REGISTRY:
|
|
raise ValueError(f"Dataset {name} not found.")
|
|
return Registry._REGISTRY[name]
|
|
|
|
@staticmethod
|
|
def reset() -> None:
|
|
Registry._REGISTRY = {}
|