ahvn.ukf.registry module¶
UKF Type Registry for polymorphic deserialization.
This module provides a central registry for all UKF Template (UKFT) classes, enabling polymorphic deserialization based on the type field. The registry follows the naming convention of HEAVEN_CM and HEAVEN_KB.
- class ahvn.ukf.registry.UKFTypeRegistry[源代码]¶
基类:
objectCentral registry for UKF Template types.
This registry maps UKF type strings (from the type field) to their corresponding UKFT class implementations. It enables polymorphic deserialization where from_dict and from_ukf can return the appropriate subclass based on the type field.
示例
>>> @register_ukft ... class MyUKFT(BaseUKF): ... type: str = Field(default="my_type", frozen=True) >>> >>> data = {"type": "my_type", "name": "test", ...} >>> ukf = BaseUKF.from_dict(data) # Returns MyUKFT instance >>> isinstance(ukf, MyUKFT) True
- register(ukft_class)[源代码]¶
Register a UKFT class in the registry.
- 参数:
ukft_class (
Type[BaseUKF]) -- A BaseUKF subclass to register.- 返回类型:
- 返回:
The same class (for use as a decorator).
- 抛出:
ValueError -- If the class doesn't have a type field or if the type is already registered.
- ahvn.ukf.registry.register_ukft(ukft_class)[源代码]¶
Decorator to register a UKFT class in the global registry.
This decorator should be applied to all BaseUKF subclasses that represent concrete UKF types. It automatically registers the class in HEAVEN_UR for polymorphic deserialization.
- 参数:
ukft_class (
Type[BaseUKF]) -- A BaseUKF subclass to register.- 返回类型:
- 返回:
The same class (for use as a decorator).
示例
>>> @register_ukft ... class KnowledgeUKFT(BaseUKF): ... type: str = Field(default="knowledge", frozen=True)