Repository navigation
feat(stt): support Fun-ASR-Flash in Tongyi-Qianwen provider - #16844
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughFun-ASR-Flash is registered for the Tongyi-Qianwen provider and routed through a native DashScope HTTP transcription path. The adapter supports local, URL, and data-URI audio, synchronous responses, SSE streaming, validation, and legacy Qwen compatibility. ChangesFun-ASR-Flash provider support
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant QWenSeq2txt
participant requests.post
participant DashScopeGenerationEndpoint
QWenSeq2txt->>QWenSeq2txt: Encode local audio and infer format
QWenSeq2txt->>requests.post: Send native transcription request
requests.post->>DashScopeGenerationEndpoint: POST multimodal generation payload
DashScopeGenerationEndpoint-->>requests.post: Return output.text or SSE data
requests.post-->>QWenSeq2txt: Return transcription result or events
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/unit_test/rag/llm/test_sequence2txt_model.py (1)
66-76: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLGTM on the happy-path streaming test.
Consider adding a companion test for the error path (
_transcribe_fun_asr_flashreturning an**ERROR**string) to lock in the expected event sequence, especially given thefinal-event inconsistency flagged inrag/llm/sequence2txt_model.py(lines 169-178).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/unit_test/rag/llm/test_sequence2txt_model.py` around lines 66 - 76, Add a companion test alongside test_fun_asr_flash_stream_uses_native_transcription that patches _transcribe_fun_asr_flash to return an **ERROR** string and verifies stream_transcription emits the expected error-path event sequence, including whether a final event is present according to the intended behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rag/llm/sequence2txt_model.py`:
- Around line 157-167: Update _transcribe_fun_asr_flash to emit a log entry in
its exception handler before returning the existing "**ERROR**" string. Include
the caught exception and enough context to identify the Fun-ASR-Flash
transcription failure, while preserving the current return value and token
count.
- Around line 123-150: Update _transcribe_fun_asr_flash to derive audio_format
from the data URI MIME type or URL/path metadata instead of defaulting all
extensionless inputs to WAV, while preserving the wave-to-wav normalization.
Replace the hardcoded parameters sample_rate with the actual input audio sample
rate, obtaining it for local files and requiring or extracting equivalent
metadata for remote/data inputs so format and rate remain aligned.
---
Nitpick comments:
In `@test/unit_test/rag/llm/test_sequence2txt_model.py`:
- Around line 66-76: Add a companion test alongside
test_fun_asr_flash_stream_uses_native_transcription that patches
_transcribe_fun_asr_flash to return an **ERROR** string and verifies
stream_transcription emits the expected error-path event sequence, including
whether a final event is present according to the intended behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 15caf4cf-4f51-409f-8d59-599a17b5b187
📒 Files selected for processing (3)
conf/llm_factories.jsonrag/llm/sequence2txt_model.pytest/unit_test/rag/llm/test_sequence2txt_model.py
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
rag/llm/sequence2txt_model.py (1)
197-205: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftPreserve streaming for Fun-ASR-Flash. This path still makes a blocking HTTP request with
X-DashScope-SSE: disable, sostream_transcription()only yields one completed transcript and drops incremental ASR events. Switch it to SSE (X-DashScope-SSE: enable,stream=True) and parse the event stream so it behaves like the non-Flash branch.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rag/llm/sequence2txt_model.py` around lines 197 - 205, Update the Fun-ASR-Flash branch of stream_transcription to use an SSE-enabled, streaming request instead of _transcribe_fun_asr_flash’s blocking call. Parse and yield incremental ASR events as delta results, then emit the final event when complete, while preserving the existing error-event behavior.
🧹 Nitpick comments (1)
test/unit_test/rag/llm/test_sequence2txt_model.py (1)
23-124: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding a test for the top-level
textresponse path.The upstream
_transcribe_fun_asr_flashhandles bothresult.get("text")andresult.get("output", {}).get("text"), but all tests mock responses with{"output": {"text": ...}}. A test using{"text": "transcribed text"}would verify the fallback path.🧪 Suggested additional test
+def test_fun_asr_flash_handles_top_level_text_response(): + response = MagicMock() + response.json.return_value = {"text": "transcribed text"} + + with patch("rag.llm.sequence2txt_model.requests.post", return_value=response): + model = QWenSeq2txt("test-key", "fun-asr-flash-2026-06-15") + text, _ = model.transcription("data:audio/wav;base64,dGVzdA==") + + assert text == "transcribed text"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/unit_test/rag/llm/test_sequence2txt_model.py` around lines 23 - 124, Add a test alongside test_fun_asr_flash_uses_native_request_format that mocks the Fun-ASR-Flash response as {"text": "transcribed text"} and verifies QWenSeq2txt.transcription returns that text successfully. Reuse the existing request patching and audio setup, and retain assertions for the native request behavior needed to exercise the top-level response path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rag/llm/sequence2txt_model.py`:
- Around line 157-159: Update the local audio handling around the audio_file
Data URI construction to check the file size before reading and base64-encoding
it. For files exceeding Aliyun’s 10 MB Base64 limit, route them through the
existing URL-backed path if available; otherwise reject them with a clear
size-limit error instead of building an oversized Data URI.
---
Outside diff comments:
In `@rag/llm/sequence2txt_model.py`:
- Around line 197-205: Update the Fun-ASR-Flash branch of stream_transcription
to use an SSE-enabled, streaming request instead of _transcribe_fun_asr_flash’s
blocking call. Parse and yield incremental ASR events as delta results, then
emit the final event when complete, while preserving the existing error-event
behavior.
---
Nitpick comments:
In `@test/unit_test/rag/llm/test_sequence2txt_model.py`:
- Around line 23-124: Add a test alongside
test_fun_asr_flash_uses_native_request_format that mocks the Fun-ASR-Flash
response as {"text": "transcribed text"} and verifies QWenSeq2txt.transcription
returns that text successfully. Reuse the existing request patching and audio
setup, and retain assertions for the native request behavior needed to exercise
the top-level response path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 692ac81b-d391-4a80-9571-610740df2bdc
📒 Files selected for processing (2)
rag/llm/sequence2txt_model.pytest/unit_test/rag/llm/test_sequence2txt_model.py
|
@77zane, thanks for adding Fun-ASR-Flash support. I checked the current head The remaining local-file size thread is valid for the synchronous Base64 path. The official Fun-ASR REST documentation says the source must remain small enough that the Base64-encoded input stays within 10 MB:
I recommend the minimal behavior here: preflight the encoded size before reading the file, and reject oversized local inputs with a message that tells the user to pass a publicly accessible URL. This class has no upload/storage facility, so adding OSS upload would expand the PR into credential and lifecycle management. A precise check can avoid allocating the encoded payload: encoded_size = 4 * ((os.path.getsize(audio_path) + 2) // 3)
if encoded_size + len(data_uri_prefix) > 10 * 1024 * 1024:
raise ValueError(
"Local audio exceeds the 10 MB Base64 input limit; pass a publicly accessible URL instead"
)A focused test can mock |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/unit_test/rag/llm/test_sequence2txt_model.py (1)
67-91: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winCover response cleanup when streaming stops early.
After making the response context-managed, configure the mock’s
__enter__result and add a case that consumes one event, closes the generator, and assertsresponse.close()was called.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/unit_test/rag/llm/test_sequence2txt_model.py` around lines 67 - 91, Update test_fun_asr_flash_stream_uses_sse to configure the mocked response’s __enter__ result for the context-managed streaming response. Add a test case that consumes one event from stream_transcription, closes the generator early, and asserts response.close() was called.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rag/llm/sequence2txt_model.py`:
- Around line 219-241: The streamed response created in the transcription
generator must be released when consumption stops early. In
rag/llm/sequence2txt_model.py lines 219-241, update the request handling around
response and the generator’s exception path to close the response on generator
exit, preferably via a context manager or finally block, while preserving
current event behavior. In test/unit_test/rag/llm/test_sequence2txt_model.py
lines 67-91, add coverage that closes the generator after its first yielded
event and asserts the mocked response was released.
---
Nitpick comments:
In `@test/unit_test/rag/llm/test_sequence2txt_model.py`:
- Around line 67-91: Update test_fun_asr_flash_stream_uses_sse to configure the
mocked response’s __enter__ result for the context-managed streaming response.
Add a test case that consumes one event from stream_transcription, closes the
generator early, and asserts response.close() was called.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 59f807bf-f2ee-49a8-a6b5-1ec5e06d8b05
📒 Files selected for processing (2)
rag/llm/sequence2txt_model.pytest/unit_test/rag/llm/test_sequence2txt_model.py
Signed-off-by: LauraGPT <[email protected]>
|
The companion cleanup has now been merged into the contributor branch; current head is 438c5f5. All 4 review threads are resolved, including SSE incremental streaming, format/size validation, exception logging, and response cleanup when a consumer stops early. The focused Fun-ASR-Flash suite is 10/10 green, with Ruff/format/compile checks passing; the author also reports real hosted-API and RAGFlow upload/indexing validation. @Lynn-Inf, could you review the backend adapter when convenient? |
|
@yuzhichang 这个 PR 已经拿到 Lynn-Inf 的 LGTM 了,但一直没有加 ci 标签,测试没跑起来。方便的话麻烦加个 ci 标签让 CI 跑一下,谢谢! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16844 +/- ##
==========================================
- Coverage 94.56% 93.16% -1.40%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 668 -10
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
CI audit for head
The failing test and Go proxy are outside this PR's three changed Fun-ASR-Flash files, and the identical timeout across both document engines points to a shared integration flake. I cannot rerun upstream Actions without admin rights. @yuzhichang, could you rerun the failed jobs when convenient? |
QWenSeq2txt._transcribe_fun_asr_flash accepts either {"output": {"text": ...}}
or a top-level {"text": ...} response shape, but every existing test only
exercised the former. Add coverage for the fallback path, closing the gap
CodeRabbit flagged earlier in review.
|
Update on the two failing Go jobs: I reproduced the I opened #16928 to remove the duplicate definition and restore |
|
Update: #16927 has now merged into |
|
Current-head CI audit for
A rerun of the failed preflight should be sufficient; the current failure does not indicate a Fun-ASR-Flash code change. |
|
@yuzhichang 最新 CI 在 pytest 收集阶段失败: |
|
@yuzhichang CI 重跑现已全部通过:preflight、Infinity/Elasticsearch 的 Python 与 Go 任务,以及 CodeRabbit 均为成功;GitHub 当前状态为 CLEAN / MERGEABLE。4 个 review thread 已全部解决,Lynn-Inf 也已批准后端实现。 需要麻烦您:
谢谢! |
What this PR does
Adds support for Alibaba Cloud's hosted Fun-ASR-Flash snapshots to the existing Tongyi-Qianwen speech-to-text provider.
fun-asr-flash-2026-06-15as a speech-to-text model;fun-asr-flash*models to the documented workspace-native multimodal-generation endpoint;dashscope.MultiModalConversationpath for all other Qwen audio models;Why
Fun-ASR-Flash does not use the legacy Qwen audio request shape currently used by
QWenSeq2txt. Its synchronous API expectsinput_audioat:/api/v1/services/aigc/multimodal-generation/generationWithout a narrowly scoped adapter path, the hosted model cannot be selected successfully through RAGFlow's Tongyi-Qianwen speech-to-text provider.
Closes #16843.
Compatibility
The new behavior is gated by the
fun-asr-flashmodel-name prefix. Existing Qwen audio models continue through the original code path unchanged.Validation
pytest test/unit_test/rag/llm/test_sequence2txt_model.py: 10 passedllm_factories.jsonvalidation: passedThe unit tests cover the native Fun-ASR-Flash request, regression behavior for the legacy Qwen path, SSE streaming, and early response cleanup.
Documentation
Why a dedicated adapter path is necessary (official evidence)
Alibaba Cloud's Fun-ASR RESTful API reference makes the incompatibilities with RAGFlow's existing Qwen audio path explicit:
POST /api/v1/services/aigc/multimodal-generation/generation.dashscope.MultiModalConversation, so a direct HTTP path is required.input_audiomessage shapeinput.messages,content,type: input_audio,input_audio, andinput_audio.dataare documented as required for an audio request.audiocontent shape, which does not match this API contract.parameters.formatparametersandformatas Required, and says the value must match the actual audio format.parameters.formatfield, so the adapter must derive and send it.input_audio.dataaccepts either a public URL or a Base64 Data URI; the reference gives the exactdata:{MIME_TYPE};base64,...form.output.textoutput.text.output.choices[].message.content, so a separate response parser is required.X-DashScope-SSE: enableand documents intermediate and final SSE events.finallycleanup releases the HTTP response on completion, errors, and consumer cancellation.sample_rateis documented as Optional. The implementation omits it instead of declaring a fixed value that may not match remote or compressed audio.The official speech-to-text model list separately confirms that
fun-asr-flash-2026-06-15is an offline HTTP model with a five-minute audio limit.