syntaxhacker commited on
Commit ·
cdab93b
1
Parent(s): ddc093c
patch preciz SDK in Dockerfile to handle malformed XML tool calls
Browse files- Dockerfile +1 -0
- scripts/patch_preciz.py +54 -0
Dockerfile
CHANGED
|
@@ -8,6 +8,7 @@ WORKDIR /app
|
|
| 8 |
COPY requirements.txt .
|
| 9 |
COPY scripts/ scripts/
|
| 10 |
RUN pip install --no-cache-dir -r requirements.txt && \
|
|
|
|
| 11 |
python -c "import site; import shutil; shutil.copy('scripts/utils_shim.py', f'{site.getsitepackages()[0]}/utils.py')" && \
|
| 12 |
rm -rf scripts
|
| 13 |
|
|
|
|
| 8 |
COPY requirements.txt .
|
| 9 |
COPY scripts/ scripts/
|
| 10 |
RUN pip install --no-cache-dir -r requirements.txt && \
|
| 11 |
+
python scripts/patch_preciz.py && \
|
| 12 |
python -c "import site; import shutil; shutil.copy('scripts/utils_shim.py', f'{site.getsitepackages()[0]}/utils.py')" && \
|
| 13 |
rm -rf scripts
|
| 14 |
|
scripts/patch_preciz.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Patch preciz SDK's _parse_tool_calls to handle malformed XML gracefully."""
|
| 2 |
+
|
| 3 |
+
import site
|
| 4 |
+
import re
|
| 5 |
+
|
| 6 |
+
P = f"{site.getsitepackages()[0]}/summarizer/llm_client.py"
|
| 7 |
+
|
| 8 |
+
with open(P) as f:
|
| 9 |
+
src = f.read()
|
| 10 |
+
|
| 11 |
+
marker_old = (
|
| 12 |
+
' raw_text = re.sub(r"\\s+handle$", "", raw_text).strip()\n'
|
| 13 |
+
' return [(fallback.group(1), raw_text)]\n'
|
| 14 |
+
' return []'
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
marker_new = (
|
| 18 |
+
' raw_text = re.sub(r"\\s+handle$", "", raw_text).strip()\n'
|
| 19 |
+
' return [(fallback.group(1), raw_text)]\n'
|
| 20 |
+
' # Ultra-fallback: strip all tags, extract key-value pairs\n'
|
| 21 |
+
' # from even badly malformed XML\n'
|
| 22 |
+
' stripped = re.sub(r"<[^>]+>", "\\n", content)\n'
|
| 23 |
+
' lines = [l.strip() for l in stripped.split("\\n") if l.strip()]\n'
|
| 24 |
+
' known_keys = {"name", "question", "dataset"}\n'
|
| 25 |
+
' tool = "rag_qa"\n'
|
| 26 |
+
' question = ""\n'
|
| 27 |
+
' dataset = "developer-portfolio"\n'
|
| 28 |
+
' for i, line in enumerate(lines):\n'
|
| 29 |
+
' if line not in known_keys:\n'
|
| 30 |
+
' continue\n'
|
| 31 |
+
' if i + 1 < len(lines) and lines[i + 1] not in known_keys:\n'
|
| 32 |
+
' val = lines[i + 1]\n'
|
| 33 |
+
' if line == "name":\n'
|
| 34 |
+
' tool = LONGCAT_NAME_MAP.get(val, val)\n'
|
| 35 |
+
' elif line == "question":\n'
|
| 36 |
+
' question = val\n'
|
| 37 |
+
' elif line == "dataset":\n'
|
| 38 |
+
' dataset = val\n'
|
| 39 |
+
' if not question:\n'
|
| 40 |
+
' vals = [l for l in lines if l not in known_keys]\n'
|
| 41 |
+
' if vals:\n'
|
| 42 |
+
' question = " ".join(vals)\n'
|
| 43 |
+
' if question:\n'
|
| 44 |
+
' return [_normalize_tool_args(tool, {"question": question, "dataset": dataset})]\n'
|
| 45 |
+
' return []'
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
assert marker_old in src, "Marker not found"
|
| 49 |
+
src = src.replace(marker_old, marker_new, 1)
|
| 50 |
+
|
| 51 |
+
with open(P, "w") as f:
|
| 52 |
+
f.write(src)
|
| 53 |
+
|
| 54 |
+
print("Patched _parse_tool_calls with robust XML fallback")
|