Spaces:
Running
Running
Update core/utils.py
Browse files- core/utils.py +17 -14
core/utils.py
CHANGED
@@ -1,21 +1,24 @@
|
|
1 |
# algoforge_prime/core/utils.py
|
2 |
-
|
3 |
-
# This file can contain various helper functions used across the core modules.
|
4 |
-
# For example, text parsing, sanitization, logging helpers, etc.
|
5 |
|
6 |
def basic_text_cleanup(text: str) -> str:
|
7 |
-
"""A
|
8 |
-
if not text:
|
9 |
return ""
|
10 |
-
|
11 |
text = text.strip()
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
-
# Add more utilities as needed.
|
|
|
|
1 |
# algoforge_prime/core/utils.py
|
2 |
+
import re
|
|
|
|
|
3 |
|
4 |
def basic_text_cleanup(text: str) -> str:
|
5 |
+
"""A basic cleanup for LLM outputs that might be wrapped in markdown code blocks."""
|
6 |
+
if not text or not isinstance(text, str):
|
7 |
return ""
|
8 |
+
|
9 |
text = text.strip()
|
10 |
+
# Common markdown code block patterns
|
11 |
+
patterns = [
|
12 |
+
r"^```python\s*(.*?)\s*```$", # ```python ... ```
|
13 |
+
r"^```\s*(.*?)\s*```$", # ``` ... ```
|
14 |
+
]
|
15 |
|
16 |
+
for pattern in patterns:
|
17 |
+
match = re.match(pattern, text, re.DOTALL | re.IGNORECASE)
|
18 |
+
if match:
|
19 |
+
return match.group(1).strip() # Return content within the markers
|
20 |
+
|
21 |
+
return text # Return original if no common markers found
|
22 |
|
23 |
+
# Add more utilities as needed.
|
24 |
+
print("DEBUG: core.utils - Module defined.")
|