From 975bd960fd07e75799b8e3adc4c0033046b34792 Mon Sep 17 00:00:00 2001 From: historia Date: Wed, 26 Aug 2026 19:58:45 -0400 Subject: feat: language and option fields in tui, context-sensitive voice label --- app/backends/common.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'app/backends') diff --git a/app/backends/common.py b/app/backends/common.py index 25d4f31..b9448e0 100644 --- a/app/backends/common.py +++ b/app/backends/common.py @@ -230,6 +230,28 @@ def normalize_remote_url(value: str) -> str: (parts.scheme or "http", parts.netloc, parts.path, "", "")) +def parse_request_options(text: str) -> Dict[str, str]: + """Parse a user-supplied ``KEY=VALUE`` option string into a dict. + + Items are separated by commas or whitespace; each must contain an + ``=`` with a non-empty key. Values are kept verbatim (only the key is + stripped), so e.g. ``speed=1.1`` yields ``{"speed": "1.1"}`` — the + audio.cpp server coerces per-model option values itself. A blank + string yields {}. Raises ValueError with a user-facing message when + an item lacks ``=`` or has an empty key; later duplicates of a key + override earlier ones. + """ + options: Dict[str, str] = {} + for item in text.replace(",", " ").split(): + key, sep, value = item.partition("=") + if not sep or not key.strip(): + raise ValueError( + f"Request options expect KEY=VALUE items " + f"(e.g. emotion=neutral); got {item!r}") + options[key.strip()] = value + return options + + def server_running(url: str, timeout: float = 0.3) -> bool: """True when something accepts TCP connections at URL's host:port. -- cgit v1.2.3