Share fallback field-label cleanup
This commit is contained in:
@@ -101,6 +101,18 @@ def split_avoid(text: Any) -> tuple[str, str]:
|
||||
return text[: match.start()].strip(" ."), match.group(1).strip(" .")
|
||||
|
||||
|
||||
def strip_prompt_field_labels(
|
||||
text: Any,
|
||||
*,
|
||||
field_labels: tuple[str, ...] | list[str] = DEFAULT_PROMPT_FIELD_LABELS,
|
||||
) -> str:
|
||||
text = clean_text(text)
|
||||
if not text:
|
||||
return ""
|
||||
labels = "|".join(re.escape(name) for name in sorted(field_labels, key=len, reverse=True))
|
||||
return clean_text(re.sub(rf"\b(?:{labels}):\s*", "", text))
|
||||
|
||||
|
||||
def prompt_field(
|
||||
text: Any,
|
||||
label: str,
|
||||
|
||||
Reference in New Issue
Block a user