Skip to content

Doubao-powered voice input for Linux, Wayland and Omarchy

fix(polish): tune Zhipu reasoning and guide low-latency model selection (#37)

Leyang41dc00345dbf
diff --git a/README.md b/README.md
index b127d15..f103a03 100644
--- a/README.md
+++ b/README.md
@@ -75,10 +75,41 @@ Doubao Say selects a prompt from each transcript's dominant language. The bundle
filler words and false starts, improves punctuation and organization, preserves
meaning, and can be edited or restored to its default.
-Disable deep thinking/reasoning for this latency-sensitive task. **DeepSeek Flash
-(`deepseek-v4-flash`) is recommended.** Doubao Say requests non-thinking mode when
-using the official DeepSeek endpoint; with a gateway or another provider, confirm
-that thinking is disabled or select a non-reasoning model.
+### Choose a fast polishing model
+
+**Prefer a small, low-latency model with thinking disabled.** Polishing only needs
+light text correction, not deep reasoning. Large reasoning models are a poor
+default for this task: polishing has a five-second total budget, after which
+Doubao Say uses your original text. Small models can still think, and a
+Flash/Lite name does not guarantee that thinking is off or can be disabled.
+
+Start with one of these options on its official endpoint:
+
+| Model | Base URL | Automatic thinking control |
+| --- | --- | --- |
+| DeepSeek Flash (`deepseek-flash`) | `https://api.deepseek.com` | Requests `thinking: {"type": "disabled"}` |
+| Gemini 2.5 Flash-Lite (`gemini-2.5-flash-lite`) | `https://generativelanguage.googleapis.com/v1beta/openai` | Requests `reasoning_effort: "none"` |
+
+Gemini 2.5 Flash also has automatic thinking-off support. See the official
+[DeepSeek thinking guide](https://api-docs.deepseek.com/guides/thinking_mode/) and
+[Gemini OpenAI compatibility guide](https://ai.google.dev/gemini-api/docs/openai)
+for the provider parameters. These are configuration suggestions, not measured
+latency guarantees; network, service load, and text length also affect speed.
+Use **Test endpoint** to check connectivity, then try a short recording to assess
+actual polishing latency and quality.
+
+The settings page shows the thinking policy for your endpoint and model.
+Automatic control depends on the official hostname, not just the model name.
+For gateways or providers without a verified policy (including OpenAI, Claude,
+and Grok), confirm thinking is disabled in the provider configuration or choose
+a non-reasoning model; Doubao Say otherwise leaves provider defaults in place.
+Claude's native API is not supported by this OpenAI-compatible client.
+
+Zhipu (`open.bigmodel.cn`) standard and Coding Plan APIs request thinking-off,
+except for GLM-5.3 and GLM-5.3-Flash: these cannot disable thinking and request
+`reasoning_effort: "low"` instead. Low effort is still thinking, so these are not
+the preferred choices for this five-second workflow. See the
+[Zhipu thinking guide](https://docs.bigmodel.cn/cn/guide/capabilities/thinking).
When enabled, 1.2 seconds of silence with stable recognized text starts provisional
polishing. A separate status line stays visible while the overlay streams the result.
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 427fc66..6203b9f 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -56,9 +56,34 @@ API Key 保存在 `~/.config/doubao-say/volcengine_api_key`(或对应的
中文与英文 Prompt;应用会根据每次转写的主要语言自动选择。内置 Prompt 会去除口水词、重复和口误,改善标点与结构,同时保留原意;用户可
自行修改,也可一键恢复默认内容。
-这类低延迟任务应关闭深度思考/推理模式,**推荐使用 DeepSeek Flash
-(`deepseek-v4-flash`)**。使用 DeepSeek 官方接口时,豆包说会请求非思考模式;使用中转接口
-或其他服务商时,请确认已经关闭思考,或选择非推理模型。
+### 选择低延迟润色模型
+
+**优先选择小型、低延迟模型,并关闭思考。** 润色只需要轻量文字修正,不需要深度推理。
+不建议默认使用大型推理模型:润色总共只有五秒,超过上限就会使用原文。
+小模型也可能开启思考,名称带 Flash/Lite 不代表思考已经关闭,也不代表支持关闭。
+
+建议从以下官方接口配置开始:
+
+| 模型 | Base URL | 自动思考控制 |
+| --- | --- | --- |
+| DeepSeek Flash(`deepseek-flash`) | `https://api.deepseek.com` | 请求 `thinking: {"type": "disabled"}` |
+| Gemini 2.5 Flash-Lite(`gemini-2.5-flash-lite`) | `https://generativelanguage.googleapis.com/v1beta/openai` | 请求 `reasoning_effort: "none"` |
+
+Gemini 2.5 Flash 也已适配自动关闭思考。参数说明见
+[DeepSeek 思考模式文档](https://api-docs.deepseek.com/guides/thinking_mode/)和
+[Gemini OpenAI 兼容文档](https://ai.google.dev/gemini-api/docs/openai)。
+以上是配置建议,不是实测延迟保证;网络、服务负载和文本长度都会影响速度。
+先用“测试接口”检查连通性,再通过一段简短录音判断实际润色速度和质量。
+
+设置页会显示当前接口和模型的思考策略。自动适配依赖官方域名,而不只是模型名称。
+使用中转接口或尚未适配思考控制的服务商(包括 OpenAI、Claude、Grok)时,
+请在服务商配置中确认关闭思考,或选择非推理模型;否则应用会沿用服务商默认值。
+当前 OpenAI 兼容客户端不支持 Claude 原生 API。
+
+智谱(`open.bigmodel.cn`)标准 API 和 Coding Plan 接口会请求关闭思考,
+但 GLM-5.3 和 GLM-5.3-Flash 不允许关闭,因此改为请求 `reasoning_effort: "low"`。
+低推理强度仍然是思考模式,不作为五秒润色场景的首选。详情见
+[智谱深度思考文档](https://docs.bigmodel.cn/cn/guide/capabilities/thinking)。
开启后,识别文本稳定且静音 1.2 秒会启动预润色;再次说话会立即让旧请求失效并回到聆听状态。
悬浮窗独立显示润色状态和流式文字。润色结合本次整段上下文,只修明显口误与识别错误,
diff --git a/src/doubao_input/reasoning.py b/src/doubao_input/reasoning.py
index 9908d60..c55fc9f 100644
--- a/src/doubao_input/reasoning.py
+++ b/src/doubao_input/reasoning.py
@@ -10,6 +10,14 @@ def reasoning_policy(base_url, model):
if host == "api.deepseek.com":
return {"thinking": {"type": "disabled"}}, tr(
"Thinking-off requested via DeepSeek.", "通过 DeepSeek 接口请求关闭思考。")
+ if host == "open.bigmodel.cn":
+ # GLM-5.3 models reject thinking.type=disabled, including on Coding Plan.
+ if name in {"glm-5.3", "glm-5.3-flash"}:
+ return {"reasoning_effort": "low"}, tr(
+ "This Zhipu model cannot disable thinking; low reasoning effort requested.",
+ "此智谱模型无法关闭思考;已请求最低推理强度。")
+ return {"thinking": {"type": "disabled"}}, tr(
+ "Thinking-off requested via Zhipu.", "通过智谱接口请求关闭思考。")
if host in {"dashscope.aliyuncs.com", "dashscope-intl.aliyuncs.com",
"dashscope-us.aliyuncs.com"}:
if "thinking" not in name and name.startswith((
diff --git a/src/doubao_input/ui/polish_settings.py b/src/doubao_input/ui/polish_settings.py
index a5a7410..20290d1 100644
--- a/src/doubao_input/ui/polish_settings.py
+++ b/src/doubao_input/ui/polish_settings.py
@@ -45,8 +45,8 @@ class PolishSettings(Gtk.Box):
self.details.append(self._row("Base URL", self.base_url))
self.details.append(self._row("Model", self.model))
self.latency_guidance = Gtk.Label(xalign=0, wrap=True, label=tr(
- "For faster results, use a non-reasoning model. Recommended: DeepSeek Flash (deepseek-flash).",
- "为了更快返回,请选择非推理模型。推荐:DeepSeek Flash(deepseek-flash)。"))
+ "Choose a small, fast model and turn thinking off, even for Flash/Lite models. Try DeepSeek Flash (deepseek-flash) or Gemini 2.5 Flash-Lite (gemini-2.5-flash-lite) on their official endpoints; thinking-off is requested automatically. Large reasoning models may exceed the 5-second limit and fall back to your original text.",
+ "优先选择小型、低延迟模型,并关闭思考,Flash/Lite 模型也不例外。建议使用 DeepSeek Flash(deepseek-flash)或 Gemini 2.5 Flash-Lite(gemini-2.5-flash-lite)的官方接口,应用会自动请求关闭思考。大型推理模型可能超过五秒上限,导致回退原文。"))
self.latency_guidance.add_css_class("dim-label")
self.details.append(self.latency_guidance)
self.reasoning_notice = Gtk.Label(xalign=0, wrap=True)
diff --git a/tests/e2e/cases/onboarding.yaml b/tests/e2e/cases/onboarding.yaml
index 9b7aaa3..8cc91a7 100644
--- a/tests/e2e/cases/onboarding.yaml
+++ b/tests/e2e/cases/onboarding.yaml
@@ -16,6 +16,7 @@ cases:
- aiAct: Stay on Trigger key. Scroll downward exactly once inside the light-gray central content panel, then stop.
- aiAct: Scroll downward exactly once more inside the same central content panel, then stop.
- aiAct: Scroll downward one final time inside the same central content panel, then stop.
+ - aiAssert: The model guidance is readable and recommends a small, fast model with thinking off, names DeepSeek Flash and Gemini 2.5 Flash-Lite, and warns that large reasoning models may exceed five seconds and fall back to the original text.
- aiAssert: The Test endpoint button in the Voice polishing section is fully visible.
- aiTap: Test endpoint button in the visible Voice polishing section
- wait: { duration: 750 }
diff --git a/tests/unit/test_polish.py b/tests/unit/test_polish.py
index c2499bb..84db755 100644
--- a/tests/unit/test_polish.py
+++ b/tests/unit/test_polish.py
@@ -29,11 +29,35 @@ class StreamResponse(Response):
class PolishTest(TestCase):
+ def test_zhipu_low_latency_parameters_in_streaming_and_non_streaming_requests(self):
+ for path in ("/api/paas/v4", "/api/coding/paas/v4"):
+ for model, expected in (
+ ("glm-4.7", {"thinking": {"type": "disabled"}}),
+ ("glm-5.3-flash", {"reasoning_effort": "low"})):
+ for streaming in (False, True):
+ with self.subTest(path=path, model=model, streaming=streaming):
+ response = (StreamResponse(
+ b'data: {"choices":[{"delta":{"content":"polished"}}]}\n\n'
+ b'data: [DONE]\n\n') if streaming else Response(
+ b'{"choices":[{"message":{"content":"polished"}}]}'))
+ seen = []
+ with patch("doubao_input.polish.request.urlopen", return_value=response) as call:
+ result = PolishClient().polish(
+ "synthetic text", base_url="https://open.bigmodel.cn" + path,
+ api_key="fake-key", model=model, prompt="Polish text",
+ on_progress=seen.append if streaming else None)
+ payload = json.loads(call.call_args.args[0].data)
+ self.assertEqual({key: payload[key] for key in
+ ("thinking", "reasoning_effort") if key in payload}, expected)
+ self.assertEqual(payload["stream"], streaming)
+ self.assertEqual(result, "polished")
+ self.assertEqual(seen, ["polished"] if streaming else [])
+
def test_endpoint_join(self):
self.assertEqual(chat_completions_url("https://example.test/v1/"),
"https://example.test/v1/chat/completions")
- def test_fast_mode_extension_is_only_sent_to_official_deepseek(self):
+ def test_deepseek_fast_mode_extension_is_not_sent_to_unknown_providers(self):
for base, expected in (("https://api.deepseek.com/v1", True),
("https://example.test/v1", False)):
response = Response(b'{"choices":[{"message":{"content":"ok"}}]}')
diff --git a/tests/unit/test_reasoning.py b/tests/unit/test_reasoning.py
index 173fd1e..8e2288f 100644
--- a/tests/unit/test_reasoning.py
+++ b/tests/unit/test_reasoning.py
@@ -1,9 +1,37 @@
from unittest import TestCase
+from unittest.mock import patch
from doubao_input.reasoning import reasoning_policy
class ReasoningTest(TestCase):
+ def test_zhipu_requests_thinking_off_for_standard_and_coding_endpoints(self):
+ for path in ("/api/paas/v4", "/api/coding/paas/v4"):
+ for model in ("glm-5-turbo", "glm-4.7", "glm-4.5-air"):
+ with self.subTest(path=path, model=model):
+ parameters, _ = reasoning_policy("https://open.bigmodel.cn" + path, model)
+ self.assertEqual(parameters, {"thinking": {"type": "disabled"}})
+
+ def test_zhipu_forced_thinking_models_request_low_effort(self):
+ for path in ("/api/paas/v4", "/api/coding/paas/v4"):
+ for model in ("glm-5.3", "glm-5.3-flash", "GLM-5.3-FLASH"):
+ with self.subTest(path=path, model=model):
+ parameters, _ = reasoning_policy("https://open.bigmodel.cn" + path, model)
+ self.assertEqual(parameters, {"reasoning_effort": "low"})
+
+ def test_zhipu_notice_is_localized(self):
+ for language, expected in (
+ ("en", "Thinking-off requested via Zhipu."),
+ ("zh_CN", "通过智谱接口请求关闭思考。")):
+ with self.subTest(language=language), patch("doubao_input.i18n._language", language):
+ _, notice = reasoning_policy("https://open.bigmodel.cn/api/paas/v4", "glm-4.7")
+ self.assertEqual(notice, expected)
+ _, notice = reasoning_policy("https://open.bigmodel.cn/api/paas/v4", "glm-5.3-flash")
+ self.assertEqual(notice, (
+ "此智谱模型无法关闭思考;已请求最低推理强度。"
+ if language == "zh_CN" else
+ "This Zhipu model cannot disable thinking; low reasoning effort requested."))
+
def test_provider_specific_parameters(self):
pairs = [
("https://api.deepseek.com/v1", "deepseek-v4-flash", {"thinking": {"type": "disabled"}}),
@@ -13,6 +41,8 @@ class ReasoningTest(TestCase):
("https://dashscope.aliyuncs.com/compatible-mode/v1", "qwen3-235b-a22b-thinking-2507", {}),
("https://proxy.example/v1", "deepseek-v4-flash", {}),
("https://api.deepseek.com.example/v1", "deepseek-v4-flash", {}),
+ ("https://proxy.example/v1", "glm-5.3-flash", {}),
+ ("https://open.bigmodel.cn.example/api/paas/v4", "glm-5.3-flash", {}),
]
for base, model, expected in pairs:
with self.subTest(base=base, model=model):