BuddyMath / refiner.py
dotandru's picture
Fix: Clean production deployment with sse-starlette
9d29c62
raw
history blame
1.26 kB
import re
import logging
logger = logging.getLogger("Refiner")
class Refiner:
@staticmethod
def refine(data: dict) -> dict:
try:
if 'sections' in data and isinstance(data['sections'], list):
for section in data['sections']:
if 'steps' in section and isinstance(section['steps'], list):
for step in section['steps']:
# חשוב: אנחנו מנקים רק את block_math מדולרים
# את content_mixed אנחנו משאירים עם דולרים כדי שהאפליקציה תרנדר!
if 'block_math' in step:
step['block_math'] = Refiner._clean_latex_block(step['block_math'])
return data
except Exception as e:
logger.error(f"Refinement error: {e}")
return data
@staticmethod
def _clean_latex_block(tex: str) -> str:
if not tex or tex == 'null': return ""
s = str(tex)
# בבלוק מתמטי נקי לא צריך דולרים
s = s.replace('$$', '').replace('$', '')
s = s.replace('-', '−') # מינוס יפה
return s.strip()