Skip to content

The agent that grows with you

fix(stt): strip Qwen3-ASR response prefix

LauraGPT517b8debbdbf
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
+ ("transcription", "expected"),
+ [
+ ("language English<asr_text>Hello from Qwen.", "Hello from Qwen."),
+ (
+ types.SimpleNamespace(text="language Chinese<asr_text>Object response."),
+ "Object response.",
+ ),
+ (
+ {"text": "language English<asr_text>Dictionary 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."""
+ text: Optional[str] = None
+
if isinstance(transcription, str):
- return transcription.strip()
+ text = transcription.strip()
- if hasattr(transcription, "text"):
+ 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()
+
+ if text is None:
+ text = str(transcription).strip()
+
+ marker = "<asr_text>"
+ if marker in text:
+ text = text.split(marker, 1)[1].strip()
- return str(transcription).strip()
+ return text