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¶

DynamicChoiceModel

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

interactive_demo()[source]¶

Interactive demo mode.

Return type:

None

print_full_state()[source]¶

Print comprehensive state information.

Return type:

None

remove_option(option)[source]¶

Remove an option and regenerate model.

Parameters:

option (OptionItem)

Return type:

bool

remove_option_by_name(name)[source]¶

Remove option by name string.

Parameters:

name (str)

Return type:

bool

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

validate_choice(choice)[source]¶

Test if a choice would be valid.

Parameters:

choice (str)

Return type:

bool

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].

property option_names: list[str]¶

Get current option names.

Return type:

list[str]