2026-06-14 19:36:12 +08:00
|
|
|
"""Shared Xfyun service value normalization."""
|
2026-06-11 10:51:08 +08:00
|
|
|
|
|
|
|
|
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)))
|