Spaces:
Sleeping
Sleeping
# algoforge_prime/core/utils.py | |
import re | |
def basic_text_cleanup(text: str) -> str: | |
"""A basic cleanup for LLM outputs that might be wrapped in markdown code blocks.""" | |
if not text or not isinstance(text, str): | |
return "" | |
text = text.strip() | |
# Common markdown code block patterns | |
patterns = [ | |
r"^```python\s*(.*?)\s*```$", # ```python ... ``` | |
r"^```\s*(.*?)\s*```$", # ``` ... ``` | |
] | |
for pattern in patterns: | |
match = re.match(pattern, text, re.DOTALL | re.IGNORECASE) | |
if match: | |
return match.group(1).strip() # Return content within the markers | |
return text # Return original if no common markers found | |
# Add more utilities as needed. | |
print("DEBUG: core.utils - Module defined.") |