Skip to content

feat(stt): add FunASR / SenseVoice provider - #16473

Merged
yuzhichang merged 2 commits into
infiniflow:mainfrom
LauraGPT:funasr/ragflow-15526-conflict-fix
Jul 15, 2026
Merged

yuzhichang merged 2 commits into
infiniflow:mainfrom
LauraGPT:funasr/ragflow-15526-conflict-fix

Conversation

@LauraGPT

@LauraGPT LauraGPT commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds FunASR as a self-hosted speech-to-text provider through its OpenAI-compatible /v1/audio/transcriptions endpoint.

This is a focused replacement for #15526 by @Rene0422 and relates to #15448. The unrelated Markdown parser changes from the previous branch are intentionally removed so this PR contains only the FunASR provider integration.

  • register FunASR as a SPEECH2TEXT factory;
  • add FunASRSeq2txt with sensevoice and http://localhost:8000/v1 defaults, an optional API key, URL normalization, and inherited transcription handling;
  • wire FunASR into the current local-provider schema with a prefilled local URL and official documentation link;
  • discover the server's /v1/models dynamically and expose every returned model as speech-to-text in the model picker;
  • use RAGFlow's existing default provider icon fallback instead of referencing a missing funasr asset;
  • list FunASR in the supported-provider documentation;
  • add focused backend and frontend regression tests.

Validation

  • focused backend pytest suite -> 7 passed
  • real CPU funasr-server + RAGFlow provider smoke test -> discovered fun-asr-nano, sensevoice, and paraformer; transcribed a real WAV as 我现在在录一段测试音频 (10 tokens, 0.504s)
  • ruff check and ruff format --check on the changed Python files
  • python3 -m py_compile on the provider and its test
  • JSON parse and a semantic assertion for exactly one enabled FunASR SPEECH2TEXT factory
  • focused frontend Jest test -> 2 passed
  • ESLint and Prettier on all changed TypeScript files
  • npm run build -> production build succeeded (14,181 modules transformed)
  • git diff --check

Deployment

Run FunASR separately and point the RAGFlow provider at it:

pip install funasr
funasr-server --device cuda --model sensevoice

The API key remains optional because the stock local server does not require authentication. A key can still be supplied when the endpoint is protected by a gateway.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds FunASR as a local speech-to-text provider in backend and frontend configuration. Separately updates Markdown fenced-code parsing to accept tilde fences, enforce opening/closing fence matching, and refine block boundary detection.

Changes

FunASR Provider Integration

Layer / File(s) Summary
FunASR model class and factory config
rag/llm/sequence2txt_model.py, conf/llm_factories.json
Adds FunASRSeq2txt with a local /v1 transcription endpoint and placeholder key handling, and registers FunASR in factory_llm_infos with SPEECH2TEXT tags.
Frontend enum, icon, and local provider list
web/src/constants/llm.ts, web/src/pages/user-setting/constants.tsx
Adds LLMFactory.FunASR, maps it to the funasr icon key, and includes it in LocalLlmFactories.

Markdown Parser CommonMark Fence Fixes

Layer / File(s) Summary
Fence detection and block termination
deepdoc/parser/markdown_parser.py, test/unit_test/deepdoc/parser/test_markdown_parser.py
Updates fenced-code recognition to accept backtick and tilde openings, rewrites closing-fence checks to use the opening fence character and length, and refactors text-block boundary detection; the test module gains a regression docstring.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop hop, the rabbit sings with glee,
FunASR hums in the code tree.
Markdown fences stand straight and true,
Tildes and backticks now pass through.
A tidy diff, a happy burrow,
Soft ears twitch — "well done" tomorrow.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly states the main change: adding the FunASR/SenseVoice speech-to-text provider.
Description check ✅ Passed The description matches the required Summary template and adds useful context, validation, and deployment notes.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LauraGPT
LauraGPT marked this pull request as ready for review June 30, 2026 00:55
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
deepdoc/parser/markdown_parser.py (2)

467-496: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant _get_fence_marker() call; recomputes fence_char/length below.

Line 470 unpacks fence_char, fence_len via _get_fence_marker(), but both are immediately recomputed at Lines 481-492 and fence_len is never used. You can drop the Line 470 call (or reuse its result) to avoid the duplicate parse.

♻️ Proposed cleanup
 def _extract_code_block(self, start_pos):
     end_pos = start_pos
     content_lines = [self.lines[start_pos]]
-    fence_char, fence_len = self._get_fence_marker(self.lines[start_pos])
🤖 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 `@deepdoc/parser/markdown_parser.py` around lines 467 - 496, The
_extract_code_block method in markdown_parser has a redundant
_get_fence_marker() call whose results are immediately recomputed and the
fence_len value is never used. Remove the unused unpacking at the start of
_extract_code_block, or reuse the returned fence_char/fence_len consistently
when building the closing-fence regex, so the fence parsing logic is defined in
one place only.

301-339: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove _atomic_region_ranges() or wire it into _protected_ranges()
deepdoc/parser/markdown_parser.py:301-339 — this helper isn’t referenced anywhere; _protected_ranges() still uses _fenced_code_ranges(), which already handles the same fenced-code boundaries. If the new helper is meant to harden delimiter extraction, swap it in; otherwise drop it as dead code.

🤖 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 `@deepdoc/parser/markdown_parser.py` around lines 301 - 339, The new
_atomic_region_ranges() helper is currently unused, while _protected_ranges()
still relies on _fenced_code_ranges() for fenced-code exclusion. Either update
_protected_ranges() in markdown_parser.py to call _atomic_region_ranges() if
this is the intended hardened range detector, or remove _atomic_region_ranges()
entirely and keep the existing fenced-code path consistent. Use the
_protected_ranges, _fenced_code_ranges, and _atomic_region_ranges symbols to
locate the change.
🤖 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.

Nitpick comments:
In `@deepdoc/parser/markdown_parser.py`:
- Around line 467-496: The _extract_code_block method in markdown_parser has a
redundant _get_fence_marker() call whose results are immediately recomputed and
the fence_len value is never used. Remove the unused unpacking at the start of
_extract_code_block, or reuse the returned fence_char/fence_len consistently
when building the closing-fence regex, so the fence parsing logic is defined in
one place only.
- Around line 301-339: The new _atomic_region_ranges() helper is currently
unused, while _protected_ranges() still relies on _fenced_code_ranges() for
fenced-code exclusion. Either update _protected_ranges() in markdown_parser.py
to call _atomic_region_ranges() if this is the intended hardened range detector,
or remove _atomic_region_ranges() entirely and keep the existing fenced-code
path consistent. Use the _protected_ranges, _fenced_code_ranges, and
_atomic_region_ranges symbols to locate the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7ac76a78-6c05-43ff-a546-77e48180c0a3

📥 Commits

Reviewing files that changed from the base of the PR and between 5276baf and 289db62.

📒 Files selected for processing (6)
  • conf/llm_factories.json
  • deepdoc/parser/markdown_parser.py
  • rag/llm/sequence2txt_model.py
  • test/unit_test/deepdoc/parser/test_markdown_parser.py
  • web/src/constants/llm.ts
  • web/src/pages/user-setting/constants.tsx

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. size:L This PR changes 100-499 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 30, 2026
@LauraGPT

Copy link
Copy Markdown
Contributor Author

Current head 818a295 is ready for human review from the FunASR/SenseVoice integration side.

I rechecked the CodeRabbit nitpicks against the latest branch: the redundant _get_fence_marker() call is no longer present, and the unused _atomic_region_ranges() helper is no longer in the current deepdoc/parser/markdown_parser.py.

Validation rerun locally:

python -m py_compile deepdoc/parser/markdown_parser.py rag/llm/sequence2txt_model.py
python -m pytest -c /dev/null --confcutdir=test/unit_test/deepdoc/parser test/unit_test/deepdoc/parser/test_markdown_parser.py -q
# 12 passed
git diff --check upstream/main...HEAD

The PR is still mergeable, with CodeRabbit reporting success.

@LauraGPT

LauraGPT commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Fresh FunASR/SenseVoice-side validation recheck (2026-07-07 UTC):

  • PR is open, non-draft, and mergeable with mergeable_state=clean; current head is 818a2957.
  • Review-thread audit shows 0 current unresolved review threads. CodeRabbit is green; repo check runs on this head are skipped rather than failing.
  • Local validation at head 818a2957 after fetching the merge base:
    • git diff --check origin/main...HEAD passed.
    • python3 -m py_compile deepdoc/parser/markdown_parser.py rag/llm/sequence2txt_model.py passed.
    • conf/llm_factories.json parses as JSON and contains the FunASR / SenseVoice provider entries.
    • Focused parser regression command passed: python3 -m pytest -c /dev/null --confcutdir=test/unit_test/deepdoc/parser test/unit_test/deepdoc/parser/test_markdown_parser.py -q -> 12 passed.

Caveat: the plain repo-level pytest command is not a useful signal in my bare validation environment because it imports the global unit-test conftest.py and expects the repo's NLTK setup; the focused command above isolates the touched parser tests.

@LauraGPT
LauraGPT force-pushed the funasr/ragflow-15526-conflict-fix branch from 818a295 to 173f886 Compare July 13, 2026 09:25
@LauraGPT

LauraGPT commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Refreshed this FunASR/SenseVoice integration onto current infiniflow/main@466f33e6 (the previous branch point was 289 upstream commits behind). The updated head is 173f8865; GitHub reports it mergeable with a clean merge state.

Verification after the rebase:

  • git range-diff confirms the five PR commits are semantically unchanged; only current-main context shifted.
  • python3 -m py_compile deepdoc/parser/markdown_parser.py rag/llm/sequence2txt_model.py
  • FunASR provider contract check with a mocked OpenAI client: default sensevoice, unauthenticated placeholder key, custom model/base URL, and inherited transcription path all passed.
  • conf/llm_factories.json parses and contains exactly one FunASR SPEECH2TEXT provider.
  • focused Markdown parser suite: 12 passed.
  • git diff --check origin/main...HEAD passed.

The repository workflow jobs are skipped for this fork head rather than failing. @coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

@LauraGPT Thanks for the update on the rebase and validation. I'll kick off a fresh review of the current head now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

@LauraGPT Thanks for the detailed rebase and validation summary. I'll kick off a fresh review of the current head (173f8865) now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Add the OpenAI-compatible transcription adapter, dynamic model discovery, current provider-schema wiring, documentation, and focused tests. Based on the provider proposal in infiniflow#15526 by @Rene0422.

Signed-off-by: LauraGPT <[email protected]>
@LauraGPT
LauraGPT force-pushed the funasr/ragflow-15526-conflict-fix branch from 173f886 to 7aa7512 Compare July 13, 2026 13:00
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 13, 2026
@LauraGPT

Copy link
Copy Markdown
Contributor Author

Replaced the branch with one focused FunASR provider commit (7aa7512e). The unrelated Markdown parser changes and old merge-conflict history are no longer part of this PR; it is now 11 files / 233 additions and GitHub reports a clean merge state.

Fresh validation on current main@45862bf9:

  • focused backend suite: 7 passed;
  • focused frontend suite: 2 passed;
  • Ruff, Python compilation, ESLint, Prettier, JSON semantics, and git diff --check: passed;
  • production frontend build: passed;
  • real CPU funasr-server E2E: RAGFlow discovered fun-asr-nano, sensevoice, and paraformer, then transcribed the test WAV as 我现在在录一段测试音频 (10 tokens, 0.504s).

The implementation and PR description retain attribution to the original #15526 contribution by @Rene0422.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

@LauraGPT Thanks for the update — focusing this PR down to the single FunASR provider commit (7aa7512e) and dropping the unrelated Markdown parser changes makes it much easier to review. I'll kick off a fresh review of the current head now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@LauraGPT

Copy link
Copy Markdown
Contributor Author

@Lynn-Inf, when you have a chance, could you please review this focused FunASR/SenseVoice provider addition?

The PR is now a single commit covering 11 provider/model-registration files, with the unrelated parser changes removed; GitHub reports it clean and mergeable. Focused backend tests (7 passed), frontend tests (2 passed), Ruff, ESLint, Prettier, JSON validation, and git diff --check all passed on the current head. Guidance on the model metadata and sequence2txt registration would be especially helpful.

@Lynn-Inf
Lynn-Inf requested a review from dcc123456 July 14, 2026 01:59
@Lynn-Inf

Copy link
Copy Markdown
Contributor

Backend LGTM. @dcc123456 will review the frontend part.

@LauraGPT

Copy link
Copy Markdown
Contributor Author

@yuzhichang, this PR now has backend LGTM from @Lynn-Inf and frontend approval from @dcc123456. The current head 7aa7512e is mergeable with no unresolved review threads, but all RAGFlow test workflows remain skipped because the PR does not yet have the ci label.

Could you add the ci label when convenient so the matrix can run? This local FunASR/SenseVoice provider is complementary to #16844, which adds Fun-ASR-Flash through the Tongyi-Qianwen provider.

@yuzhichang yuzhichang added the ci Continue Integration label Jul 14, 2026
@LauraGPT

Copy link
Copy Markdown
Contributor Author

The CI matrix has completed on head 7aa7512e: preflight plus the other three engine/proxy jobs passed. The sole failure, ragflow_tests_infinity (python), happened before any test ran while Docker was starting:

failed to bind host port 0.0.0.0:42402/tcp: address already in use

The subsequent test steps were skipped, so this is a shared-runner port collision rather than a FunASR provider failure. I attempted to rerun only the failed job, but GitHub requires repository admin rights for that action. @yuzhichang, could you rerun the failed job when convenient?

@LauraGPT

Copy link
Copy Markdown
Contributor Author

The clean CI rerun has completed successfully on head df3bf303:

  • preflight passed;
  • Elasticsearch and Infinity passed in both Python and Go;
  • CodeRabbit passed;
  • 0 failed or pending checks.

The rerun commit is tree-identical to the reviewed 7aa7512e head, so the approved diff did not change. With backend LGTM and frontend approval already recorded, this is ready to merge. @yuzhichang, could you merge it when convenient?

@yuzhichang
yuzhichang merged commit 06e36d2 into infiniflow:main Jul 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants