"""Shared Xfyun service value normalization.""" from __future__ import annotations def websocket_url(value: str, default: str) -> str: url = (value or default).strip() if url.startswith("https://"): return f"wss://{url.removeprefix('https://')}" if url.startswith("http://"): return f"ws://{url.removeprefix('http://')}" return url def xfyun_language(value: str) -> str: normalized = (value or "zh_cn").lower().replace("-", "_") return {"zh": "zh_cn", "en": "en_us"}.get(normalized, normalized) def xfyun_speed(value: float) -> int: """Reuse the existing OpenAI-style speed field where 1.0 means normal.""" return max(0, min(100, round(value * 50 if value <= 4 else value)))