mellea.stdlib.requirement
Requirements are a special type of Component used as input to the “validate” step in Instruct/Validate/Repair design patterns.
Functions
default_output_to_bool
True
.
Checks if the output is exactly equal to “yes” or “y” (case-insensitive). If not, it will also
check if any of the words in the output are “yes” (case-insensitive).
reqify
req
check
simple_validate
Requirement("Answer 'yes' or 'no'", simple_validate(lambda x: x == 'yes' or x == 'no')
Validation functions operate over Context
. Often you do not care about the entire context, and just want to consider the most recent output from the model.
Args:
fn
: the simple validation function that takes a string and returns either a bool or (bool, str)reason
: only used if the provided function returns a bool; if the validation function fails, a static reason for that failure to give to the llm when repairing
Classes
ValidationResult
ValidationResults store the output of a Requirement’s validation. They can be used to return additional info from validation functions, which is useful for sampling/repairing.
Methods:
reason
score
thunk
as_bool
Requirement
Requirements are a special type of Component used as input to the Validate step in Instruct/Validate/Repair patterns.
Methods:
validate
parts
format_for_llm
LLMaJRequirement
A requirement that always uses LLM-as-a-Judge. Any available constraint ALoRA will be ignored.
ALoraRequirement
A requirement that always uses an (possibly specified) ALora. If an exception is thrown during the ALora execution path, mellea
will fall back to LLMaJ. But that is the only case where LLMaJ will be used.