Spaces:
Running
Running
Fix: strip non-ASCII chars before sending to llama-server
Browse files
app.py
CHANGED
|
@@ -78,6 +78,12 @@ def _read_file(path: str) -> str:
|
|
| 78 |
return p.read_text(encoding="utf-8", errors="ignore")
|
| 79 |
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
def _build_full_context() -> str:
|
| 82 |
"""
|
| 83 |
Build safety-check context via targeted retrieval for medications and allergies.
|
|
@@ -105,7 +111,7 @@ def _build_full_context() -> str:
|
|
| 105 |
seen.add(uid)
|
| 106 |
ordered.append(c)
|
| 107 |
|
| 108 |
-
parts = [f"[{c.source}]\n{c.text}" for c in ordered]
|
| 109 |
return "\n\n---\n\n".join(parts)
|
| 110 |
|
| 111 |
|
|
|
|
| 78 |
return p.read_text(encoding="utf-8", errors="ignore")
|
| 79 |
|
| 80 |
|
| 81 |
+
def _sanitize(text: str) -> str:
|
| 82 |
+
"""Replace non-ASCII chars that break JSON serialization in llama-server."""
|
| 83 |
+
import re
|
| 84 |
+
return re.sub(r'[^\x00-\x7F]', '-', text)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
def _build_full_context() -> str:
|
| 88 |
"""
|
| 89 |
Build safety-check context via targeted retrieval for medications and allergies.
|
|
|
|
| 111 |
seen.add(uid)
|
| 112 |
ordered.append(c)
|
| 113 |
|
| 114 |
+
parts = [f"[{c.source}]\n{_sanitize(c.text)}" for c in ordered]
|
| 115 |
return "\n\n---\n\n".join(parts)
|
| 116 |
|
| 117 |
|