| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #!/usr/bin/env python3
- """Patch the Aiden 1.7.1 image's DSV4.1 chat encoder for the 1017 protocol.
- The image (aidendle94/sparkrun-sglang-dsv41-gb10:production-1.7.1, built
- 2026-09-29) carries the OLD reasoning-effort tier mapping:
- REASONING_EFFORT_MAPPINGS = {
- "low": 25, "high": 50, "xhigh": 75, "max": 100,
- }
- while the DeepSeek-V4.1-Flash-1017 reference encoder (encoding/encoding.py)
- shifted the ladder and dropped the xhigh tier:
- {"low": 50, "high": 75, "max": 100} (default stays "high")
- With the old map, explicit tier requests under-reason by one tier (API
- "high" renders `Reasoning Effort: 50` where 1017 means 75). The server
- default is pinned to max(100) via SGLANG_DSV41_REASONING_EFFORT, so this
- patch only affects requests that name a tier explicitly.
- Idempotent: running twice is a no-op. Refuses to touch a file that matches
- neither anchor (unknown encoder revision).
- """
- import sys
- from pathlib import Path
- FILES = [
- Path("/sgl-workspace/sglang/python/sglang/srt/entrypoints/openai/encoding_dsv41.py"),
- Path("/usr/local/lib/python3.12/dist-packages/sglang/srt/entrypoints/openai/encoding_dsv41.py"),
- ]
- OLD = ''' "low": 25,
- "high": 50,
- "xhigh": 75,
- "max": 100,
- }'''
- NEW = ''' "low": 50,
- "high": 75,
- "max": 100,
- }'''
- def main() -> int:
- target = next((f for f in FILES if f.exists()), None)
- if target is None:
- print("dsv41-effort-patch: encoder file not found — nothing to patch")
- return 1
- text = target.read_text()
- if NEW in text and OLD not in text:
- print("dsv41-effort-patch: already patched (low 50 / high 75 / max 100)")
- return 0
- if OLD not in text:
- print(
- "dsv41-effort-patch: anchor not found — encoder revision differs, "
- "refusing to patch blindly"
- )
- return 1
- target.write_text(text.replace(OLD, NEW, 1))
- check = target.read_text()
- if NEW in check and OLD not in check:
- print("dsv41-effort-patch: applied (low 50 / high 75 / max 100, xhigh dropped)")
- return 0
- print("dsv41-effort-patch: patch verification failed")
- return 1
- if __name__ == "__main__":
- sys.exit(main())
|