msg
Browse files- controller.py +18 -1
controller.py
CHANGED
|
@@ -34,6 +34,23 @@ def cut_text_after_keyword(text, keyword):
|
|
| 34 |
return text[:index].strip()
|
| 35 |
return text
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
class Controller:
|
| 38 |
"""
|
| 39 |
Controller class for handling user submissions and managing conversations.
|
|
@@ -102,6 +119,6 @@ class Controller:
|
|
| 102 |
print("------------ text -----------------------")
|
| 103 |
print(text)
|
| 104 |
print("------------ /result -----------------------")
|
| 105 |
-
result =
|
| 106 |
print(result)
|
| 107 |
return result
|
|
|
|
| 34 |
return text[:index].strip()
|
| 35 |
return text
|
| 36 |
|
| 37 |
+
def get_text_after_last_occurrence(text, delimiter):
|
| 38 |
+
"""
|
| 39 |
+
Retrieves the text after the last occurrence of the specified delimiter.
|
| 40 |
+
|
| 41 |
+
Args:
|
| 42 |
+
- text (str): The input text.
|
| 43 |
+
- delimiter (str): The delimiter to search for.
|
| 44 |
+
|
| 45 |
+
Returns:
|
| 46 |
+
- str: The text after the last occurrence of the delimiter, or an empty string if the delimiter is not found.
|
| 47 |
+
"""
|
| 48 |
+
last_index = text.rfind(delimiter)
|
| 49 |
+
if last_index != -1:
|
| 50 |
+
return text[last_index + len(delimiter):].strip()
|
| 51 |
+
return ""
|
| 52 |
+
|
| 53 |
+
|
| 54 |
class Controller:
|
| 55 |
"""
|
| 56 |
Controller class for handling user submissions and managing conversations.
|
|
|
|
| 119 |
print("------------ text -----------------------")
|
| 120 |
print(text)
|
| 121 |
print("------------ /result -----------------------")
|
| 122 |
+
result = get_text_after_last_occurrence(text, "AI: ")
|
| 123 |
print(result)
|
| 124 |
return result
|