fix(stt): strip Qwen3-ASR response prefix

Normalize the structured <asr_text> 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 <angelos@oikos.lan.home.malaiwah.com>

Assisted-by: Codex:gpt-5.6
This commit is contained in:
LauraGPT 2026-07-16 09:13:01 +00:00 committed by Teknium
parent a5074c0ca8
commit 517b8debbd
2 changed files with 43 additions and 7 deletions

View file

@ -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 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"

View file

@ -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 = "<asr_text>"
if marker in text:
text = text.split(marker, 1)[1].strip()
return text