Clean an input string by removing HTML escapes, control characters, and other unwanted characters.
(input: Any)
| 3 | from typing import Any, Union |
| 4 | import html |
| 5 | def clean_str(input: Any) -> str: |
| 6 | """Clean an input string by removing HTML escapes, control characters, and other unwanted characters.""" |
| 7 | # If we get non-string input, just give it back |
| 8 | if not isinstance(input, str): |
| 9 | return input |
| 10 | |
| 11 | result = html.unescape(input.strip()) |
| 12 | # https://stackoverflow.com/questions/4324790/removing-control-characters-from-a-string-in-python |
| 13 | return re.sub(r"[\x00-\x1f\x7f-\x9f]", "", result) |
| 14 | def pack_user_ass_to_openai_messages(*args: str): |
| 15 | roles = ["user", "assistant"] |
| 16 | return [ |
no outgoing calls
no test coverage detected