trulens.feedback.generated¶
trulens.feedback.generated
¶
Utilities for dealing with LLM-generated text.
Attributes¶
PATTERN_0_10
module-attribute
¶
Regex that matches the last integer.
PATTERN_NUMBER
module-attribute
¶
Regex that matches floating point and integer numbers.
PATTERN_INTEGER
module-attribute
¶
Regex that matches integers.
Classes¶
Functions¶
re_configured_rating
¶
re_configured_rating(
s: str,
min_score_val: int = 0,
max_score_val: int = 3,
allow_decimal: bool = False,
) -> int
Extract a {min_score_val}-{max_score_val} rating from a string. Configurable to the ranges like 4-point Likert scale or binary (0 or 1).
If the string does not match an integer/a float or matches an integer/a float outside the {min_score_val} - {max_score_val} range, raises an error instead. If multiple numbers are found within the expected 0-10 range, the smallest is returned.
PARAMETER | DESCRIPTION |
---|---|
s
|
String to extract rating from.
TYPE:
|
min_score_val
|
Minimum value of the rating scale.
TYPE:
|
max_score_val
|
Maximum value of the rating scale.
TYPE:
|
allow_decimal
|
Whether to allow and capture decimal numbers (floats).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
Extracted rating.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ParseError
|
If no integers/floats between 0 and 10 are found in the string. |
re_0_10_rating
¶
Extract a 0-10 rating from a string.
If the string does not match an integer/a float or matches an integer/a float outside the 0-10 range, raises an error instead. If multiple numbers are found within the expected 0-10 range, the smallest is returned.
PARAMETER | DESCRIPTION |
---|---|
s
|
String to extract rating from.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int
|
Extracted rating.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ParseError
|
If no integers/floats between 0 and 10 are found in the string. |