diff --git a/router/router.py b/router/router.py index 34a2dd7..f47e0de 100644 --- a/router/router.py +++ b/router/router.py @@ -81,8 +81,19 @@ def route(rd, tier): return {"model":avail[0],"reason":"fallback"} def clean_unicode(text): - if not isinstance(text, str): return text - return text.replace("\u2014","-").replace("\u2013","-").replace("\u2018",").replace(u2019,").replace("\u201c",').replace(u201d,').replace("\u2026","...").replace("\u00a0"," ") + if not isinstance(text, str): + return text + # Replace common Unicode punctuation with ASCII equivalents + text = text.replace(chr(0x2014), "-") + text = text.replace(chr(0x2013), "-") + text = text.replace(chr(0x2018), "'") + text = text.replace(chr(0x2019), "'") + text = text.replace(chr(0x201C), '"') + text = text.replace(chr(0x201D), '"') + text = text.replace(chr(0x2026), "...") + text = text.replace(chr(0x00A0), " ") + # Strip ALL remaining non-ASCII (emoji, symbols) + return text.encode("ascii", "ignore").decode("ascii") def clean_response(d): if isinstance(d, dict): return {k: clean_response(v) for k,v in d.items()}