Skip to content

Go: add funASR provider - #17171

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
Haruko386:master
Jul 21, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
Haruko386:master

Conversation

@Haruko386

@Haruko386 Haruko386 commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

Summary

As title, related to #14736

verif ied from CLI

RAGFlow(api/default)>  asr with 'paraformer@test@funasr' audio './internal/test.wav' param '{"language": "en"}'
+----------------------------------------------------------------------------------------------------------------------+
| text                                                                                                                 |
+----------------------------------------------------------------------------------------------------------------------+
| The examination and testimony of the experts enabled the commission to conclude that five shots may have been fired. |
+----------------------------------------------------------------------------------------------------------------------+

image
INFO:     127.0.0.1:51910 - "POST /v1/audio/transcriptions HTTP/1.1" 200 OK██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.19it/s]
INFO:     127.0.0.1:60934 - "GET /v1/models HTTP/1.1" 200 OK%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.10it/s]

@Haruko386 Haruko386 added the go Pull requests that update go code label Jul 21, 2026
@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 Jul 21, 2026
@Haruko386
Haruko386 marked this pull request as draft July 21, 2026 08:55
@Haruko386
Haruko386 marked this pull request as ready for review July 21, 2026 08:55
@Haruko386 Haruko386 added the ci Continue Integration label Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds FunASR as a model provider with local endpoint configuration, multipart audio transcription, authenticated model listing, connection checks, and explicit unsupported-operation responses.

Changes

FunASR provider

Layer / File(s) Summary
Configuration and provider registration
conf/models/funasr.json, internal/entity/models/factory.go, internal/entity/models/funasr.go
Defines FunASR endpoints and supported ASR models, registers the provider, and adds driver construction and identification methods.
Audio transcription request flow
internal/entity/models/funasr.go
Sends multipart audio requests with model and optional parameters, parses returned transcription text, and returns explicit errors for unsupported operations.
Model discovery and connection checks
internal/entity/models/funasr.go
Lists available models through an authenticated endpoint and uses that operation for connection validation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant FunASR
  participant FunASRAPI
  Client->>FunASR: TranscribeAudio(model, file, apiConfig)
  FunASR->>FunASRAPI: Multipart POST with audio and parameters
  FunASRAPI-->>FunASR: JSON response containing text
  FunASR-->>Client: ASRResponse with transcribed text
Loading

Poem

A rabbit hears the models hop,
While FunASR makes speech not stop.
Audio flows through forms so neat,
JSON returns the words complete.
“Hop, hop!” says Bunny, “what a feat!”

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes the required Summary section, but it is too terse and lacks the PR purpose and background context. Expand Summary with the problem being solved, why FunASR is needed, and a brief overview of the provider/config changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the PR adds a FunASR provider, which matches the main change.
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.

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.

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

Actionable comments posted: 1

🤖 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 `@internal/entity/models/funasr.go`:
- Around line 192-195: Update FunASR.TranscribeAudioWithSender to remove the
TODO and panic, returning a descriptive unsupported-operation error consistent
with the other unimplemented methods in FunASR.
🪄 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: 8b027493-b2fa-4b9e-aa2a-e967fc159994

📥 Commits

Reviewing files that changed from the base of the PR and between 20b760f and 78f8dac.

📒 Files selected for processing (3)
  • conf/models/funasr.json
  • internal/entity/models/factory.go
  • internal/entity/models/funasr.go

Comment thread internal/entity/models/funasr.go Resolved
Haruko386 and others added 2 commits July 21, 2026 17:02
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Removed commented-out code regarding audio file handling and updated comments for clarity.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/entity/models/funasr.go (2)

158-158: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Prevent nil pointer dereference when ApiKey is empty.

If FunASR is deployed locally and configured without an API key, apiConfig.ApiKey may be nil. Dereferencing it here will cause a runtime panic. Ensure the API key is non-nil and not empty before setting the Authorization header.

🐛 Proposed fix
-	req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *apiConfig.ApiKey))
+	if apiConfig.ApiKey != nil && *apiConfig.ApiKey != "" {
+		req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", *apiConfig.ApiKey))
+	}
🤖 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 `@internal/entity/models/funasr.go` at line 158, Update the request header
setup around apiConfig.ApiKey to check that the pointer is non-nil and its value
is non-empty before setting the Authorization header; omit the header for local
configurations without an API key, while preserving the existing Bearer
formatting for valid keys.

77-79: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Prevent nil pointer dereference for modelName.

modelName is passed as a pointer and dereferenced later (at line 112) without a nil check. If it is nil, this will cause a runtime panic. Please validate it here alongside the file check.

🐛 Proposed fix
 	if file == nil || *file == "" {
 		return nil, fmt.Errorf("file is missing")
 	}
+
+	if modelName == nil || *modelName == "" {
+		return nil, fmt.Errorf("model name is missing")
+	}
🤖 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 `@internal/entity/models/funasr.go` around lines 77 - 79, Update the input
validation around the existing file check to also reject a nil modelName before
it is dereferenced later in the method. Return the same missing-input error path
for nil modelName, while preserving validation of empty file values.
🤖 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.

Outside diff comments:
In `@internal/entity/models/funasr.go`:
- Line 158: Update the request header setup around apiConfig.ApiKey to check
that the pointer is non-nil and its value is non-empty before setting the
Authorization header; omit the header for local configurations without an API
key, while preserving the existing Bearer formatting for valid keys.
- Around line 77-79: Update the input validation around the existing file check
to also reject a nil modelName before it is dereferenced later in the method.
Return the same missing-input error path for nil modelName, while preserving
validation of empty file values.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c40b5546-e27b-4e73-8909-ffd565d2a25f

📥 Commits

Reviewing files that changed from the base of the PR and between 282a057 and 377a5aa.

📒 Files selected for processing (1)
  • internal/entity/models/funasr.go

@JinHai-CN
JinHai-CN merged commit d57edee into infiniflow:main Jul 21, 2026
3 checks passed
@Haruko386
Haruko386 deleted the master branch July 22, 2026 01:48
JinHai-CN pushed a commit that referenced this pull request Jul 27, 2026
### Summary

The FunASR provider added in #17171 defaults to a local
`http://localhost:8000/v1` server, but it still inherited the global
API-key requirement and unconditionally built an Authorization header.
This prevented the default unauthenticated self-hosted deployment from
working. The transcription path also dereferenced a missing model name
while building its multipart request.

This change:

- allows an empty API key for FunASR, matching other local providers
- omits the Authorization header when no key is configured while
preserving trimmed Bearer authentication when one is provided
- validates and trims the ASR model name before building the multipart
request, returning an error instead of panicking
- adds HTTP-level regression coverage for unauthenticated
transcription/model listing and optional authentication
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. go Pull requests that update go code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants