StateMachineInstruction
StateMachineInstruction defines the single instruction used in a state machine protocol. It maps one or more input TokenSets to a state string selected from your samples.
Key characteristics:
- Output is created automatically with a single
statetoken - Final token is always
<NON> - Samples provide a
statestring instead of a response snippet
StateMachineInstruction Parameters
class StateMachineInstruction:
def __init__(self, input: StateMachineInput):
- input: A
StateMachineInputinstance defining the input TokenSets
Creating a StateMachineInstruction
# Create TokenSets for input patterns
question_tokenset = mtp.TokenSet(tokens=(question, context))
# Create StateMachineInput
state_machine_input = mtp.StateMachineInput(
tokensets=[question_tokenset]
)
# Create the StateMachineInstruction
state_machine_instruction = mtp.StateMachineInstruction(
input=state_machine_input
)
# Add samples that map inputs to states
state_machine_instruction.add_sample(
input_snippets=["Where are you from?"],
state="WHERE"
)
The list of possible states is derived from these samples and stored in the template states field when state_machine=True. For details, see the State Machines Overview.
Databiomes