Repository navigation
Go: add funASR provider - #17171
Go: add funASR provider#17171
Conversation
📝 WalkthroughWalkthroughAdds FunASR as a model provider with local endpoint configuration, multipart audio transcription, authenticated model listing, connection checks, and explicit unsupported-operation responses. ChangesFunASR provider
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
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 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: 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
📒 Files selected for processing (3)
conf/models/funasr.jsoninternal/entity/models/factory.gointernal/entity/models/funasr.go
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.
There was a problem hiding this comment.
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 winPrevent nil pointer dereference when
ApiKeyis empty.If FunASR is deployed locally and configured without an API key,
apiConfig.ApiKeymay benil. Dereferencing it here will cause a runtime panic. Ensure the API key is non-nil and not empty before setting theAuthorizationheader.🐛 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 winPrevent nil pointer dereference for
modelName.
modelNameis passed as a pointer and dereferenced later (at line 112) without anilcheck. If it isnil, this will cause a runtime panic. Please validate it here alongside thefilecheck.🐛 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
📒 Files selected for processing (1)
internal/entity/models/funasr.go
### 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
Summary
As title, related to #14736
verif ied from CLI