haive.core.common.models.dynamic_choice_model¶
Dynamic Choice Model Builder with Protocol-based Generic Options Support.
Uses Protocol to ensure options have extractable names, making it flexible for strings, dicts, BaseModels, or any custom class with a name attribute.
Classes¶
Dynamic choice model builder that is itself a BaseModel. |
Module Contents¶
- class haive.core.common.models.dynamic_choice_model.DynamicChoiceModel(**data)[source]¶
Bases:
pydantic.BaseModel,Generic[OptionItem]Dynamic choice model builder that is itself a BaseModel. Can be called to generate new choice models with current options. Supports strings, dicts with name keys, or any object with name attribute.
Init .
- Returns:
Add return description]
- Return type:
[TODO
- add_option(option)[source]¶
Add a new option and regenerate model.
- Parameters:
option (OptionItem)
- Return type:
None
- remove_option(option)[source]¶
Remove an option and regenerate model.
- Parameters:
option (OptionItem)
- Return type:
- test_model(test_choice)[source]¶
Test the model with a choice and return instance if valid.
- Parameters:
test_choice (str)
- Return type:
pydantic.BaseModel | None
- property current_model: type[pydantic.BaseModel]¶
Get current choice model.
- Return type:
type[pydantic.BaseModel]
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].