Examples
Basic Conditional Intervention
Apply pirate-themed features only when whale-related content is detected:Aborting Generation
Stop generation if certain content is detected:Auto-Generated Conditionals
Use natural language to automatically generate conditional statements:Auto-Generated Conditionals example
Creating Conditionals
Comparison Operators
You can create conditionals by comparing features or feature groups with numeric values or other features using standard comparison operators. This creates a Conditional object that can be used in steering behaviors.==(equal)!=(not equal)<(less than)<=(less than or equal)>(greater than)>=(greater than or equal)
Logical Operators
Multiple conditions can be combined using logical operators to create a ConditionalGroup:Using Conditionals
set_when()
Apply feature interventions when a condition is met. Parameters:ConditionalGroup
required
The ConditionalGroup that triggers the
intervention
Union[FeatureEdits, dict[Union[Feature, FeatureGroup], float]]
required
Feature edits to apply when condition is met
abort_when()
Abort inference when a condition is met by raising an InferenceAbortedException. Parameters:ConditionalGroup
required
The ConditionalGroup that triggers the abort
handle_when()
Register a custom handler function to be called when a condition is met. Parameters:ConditionalGroup
required
The ConditionalGroup that triggers the handler
Callable[[InferenceContext], None]
required
Function that takes an InferenceContext and
returns None
AutoConditional
The AutoConditional utility helps automatically generate conditional statements based on natural language descriptions. Parameters:str
required
Natural language description of the desired condition
Union[str, Variant]
required
Model to use for generating conditions
ConditionalGroup
Generated ConditionalGroup
Best Practices
- Use conditional interventions to create context-aware steering behaviors
- Combine multiple conditions with logical operators for more precise control
- Handle aborted inferences gracefully in your application
- Test conditions thoroughly to ensure desired behavior
- Consider using AutoConditional for quick prototyping