alter_ego.utils package¶
Module contents¶
- alter_ego.utils.exclusive_response(s: str, tokens: List[str], *, case_insensitive: bool = True) str | None [source]¶
Validates that a string contains only one of a list of tokens.
- Parameters:
s (str) – The string to search in.
tokens (List[str]) – List of allowable tokens.
case_insensitive (bool) – If True, the function will be case insensitive.
- Returns:
The first matching token found, or None.
- Return type:
Optional[str]
- alter_ego.utils.extract_number(s: str) int | float | None [source]¶
Extract a single number, potentially a float, from a string.
This function uses a straightforward definition of “number” that excludes scientific notation like 3e8.
- Parameters:
s (str) – The string to extract the number from.
- Returns:
The extracted number as an integer or a float, if applicable. Returns None otherwise.
- Return type:
Optional[Union[int, float]]