Skip to main content

Module text

Module text 

Source
Expand description

Text helpers: code-fence stripping, truncation, {key} templating, edit distance. Small text helpers shared across the workspace: code-fence stripping, character-safe truncation, {key} templating and edit distance.

Functionsยง

interpolate_with
Replace each {expr} in template with the value lookup gives for expr (trimmed): a string verbatim, any other JSON value as its JSON text. An unknown expr becomes the empty string; an unclosed { is kept as written.
levenshtein
Edit distance between a and b, counted in characters (insert, delete and substitute each cost 1).
strip_code_fence
text without a surrounding Markdown code fence, for parsing the JSON a model wrapped in one.
truncate_chars
The first max_chars characters of s, cut on a character boundary.
truncate_with_marker
s, or its first max_chars characters followed by marker when it is longer. The result is max_chars plus the marker at most.