From 517b8debbdbf5e1559f7b07e25718bacb4b3f993 Mon Sep 17 00:00:00 2001 From: LauraGPT <18321252+LauraGPT@users.noreply.github.com> Date: Thu, 16 Jul 2026 09:13:01 +0000 Subject: [PATCH] fix(stt): strip Qwen3-ASR response prefix Normalize the structured marker after extracting text from string, SDK object, and dictionary transcription responses. Preserve the current provider-aware STT configuration architecture. Refreshes #8773 on current main. Co-authored-by: angelos Assisted-by: Codex:gpt-5.6 --- tests/tools/test_managed_media_gateways.py | 27 ++++++++++++++++++++++ tools/transcription_tools.py | 23 ++++++++++++------ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/tests/tools/test_managed_media_gateways.py b/tests/tools/test_managed_media_gateways.py index 1b248ce09bf..d7d35e4b7b6 100644 --- a/tests/tools/test_managed_media_gateways.py +++ b/tests/tools/test_managed_media_gateways.py @@ -347,6 +347,33 @@ def test_transcription_uses_model_specific_response_formats(monkeypatch, tmp_pat assert json_capture["close_calls"] == 1 +@pytest.mark.parametrize( + ("transcription", "expected"), + [ + ("language EnglishHello from Qwen.", "Hello from Qwen."), + ( + types.SimpleNamespace(text="language ChineseObject response."), + "Object response.", + ), + ( + {"text": "language EnglishDictionary response."}, + "Dictionary response.", + ), + ], +) +def test_extract_transcript_text_strips_qwen3_asr_prefix( + transcription, + expected, +): + _install_fake_tools_package() + transcription_tools = _load_tool_module( + "tools.transcription_tools", + "transcription_tools.py", + ) + + assert transcription_tools._extract_transcript_text(transcription) == expected + + PLUGINS_DIR = Path(__file__).resolve().parents[2] / "plugins" diff --git a/tools/transcription_tools.py b/tools/transcription_tools.py index 4ee26abb9c8..0b14e34bbcf 100644 --- a/tools/transcription_tools.py +++ b/tools/transcription_tools.py @@ -2076,17 +2076,26 @@ def _resolve_openai_audio_client_config() -> tuple[str, str]: def _extract_transcript_text(transcription: Any) -> str: """Normalize text and JSON transcription responses to a plain string.""" - if isinstance(transcription, str): - return transcription.strip() + text: Optional[str] = None - if hasattr(transcription, "text"): + if isinstance(transcription, str): + text = transcription.strip() + + if text is None and hasattr(transcription, "text"): value = getattr(transcription, "text") if isinstance(value, str): - return value.strip() + text = value.strip() - if isinstance(transcription, dict): + if text is None and isinstance(transcription, dict): value = transcription.get("text") if isinstance(value, str): - return value.strip() + text = value.strip() - return str(transcription).strip() + if text is None: + text = str(transcription).strip() + + marker = "" + if marker in text: + text = text.split(marker, 1)[1].strip() + + return text