Skip to content

fix: allow local FunASR without API key - #17388

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
LauraGPT:codex/ragflow-funasr-hardening-20260725
Jul 27, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
LauraGPT:codex/ragflow-funasr-hardening-20260725

Conversation

@LauraGPT

Copy link
Copy Markdown
Contributor

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

User impact

Users can connect RAGFlow to the default local FunASR server without inventing a placeholder API key. Authenticated compatible endpoints continue to receive a standard Bearer header.

Tests

  • go test ./internal/entity/models -run '^TestFunASR' -count=1 -v
  • go test ./internal/entity/models -count=1
  • git diff --check

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 26, 2026
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

FunASR now permits API-key-free requests, validates and trims transcription model names, and conditionally sets authorization headers. New tests cover transcription, model listing, missing credentials, authentication, multipart fields, and response handling.

Changes

FunASR request handling

Layer / File(s) Summary
Request validation and authentication
internal/entity/models/funasr.go
Allows empty API keys, rejects missing or blank model names, trims model values, and applies BearerAuth only when it returns a value.
HTTP behavior coverage
internal/entity/models/funasr_test.go
Adds HTTP server tests for transcription requests, model validation, optional authentication, authenticated model listing, multipart fields, and normalized responses.

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

Possibly related PRs

Suggested labels: go

Poem

I’m a rabbit with a model to trim,
No key? The request still swims.
Bearer headers hop when secrets appear,
Multipart fields arrive neat and clear.
FunASR tests cheer: “The path is bright!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 summarizes the main change: allowing local FunASR to work without an API key.
Description check ✅ Passed The description includes the required Summary and adds useful user impact and test details.

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: 2

🤖 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_test.go`:
- Around line 55-58: Add test cases around TranscribeAudio in newFunASRForTest
covering a whitespace-only model name that returns “model name is missing” and a
model name with surrounding spaces that serializes as “fun-asr-nano”, alongside
the existing nil and trimmed-name cases.
- Line 46: Update the multipart form parsing error path in the server handler to
call t.Errorf instead of t.Fatalf, then return immediately so the handler
goroutine stops safely while the test records the failure.
🪄 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 Plus

Run ID: a7d6237c-f689-46dc-ab76-1e477b92976b

📥 Commits

Reviewing files that changed from the base of the PR and between d2a769c and 6baccf2.

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

Comment thread internal/entity/models/funasr_test.go Resolved
Comment thread internal/entity/models/funasr_test.go Resolved
@LauraGPT

Copy link
Copy Markdown
Contributor Author

@JinHai-CN, could you review this small follow-up to the FunASR provider from #17171 when convenient?

It fixes the default local deployment path: an empty API key is now accepted, the Authorization header is omitted unless configured, and a missing model name returns an error instead of being dereferenced. The current head is mergeable/CLEAN with no unresolved review threads or failed/pending checks. Focused and package-level Go tests pass, and CodeRabbit's two test findings were addressed with regression coverage.

@JinHai-CN
JinHai-CN requested a review from Haruko386 July 26, 2026 13:58
@Haruko386
Haruko386 marked this pull request as draft July 27, 2026 01:32
@Haruko386
Haruko386 marked this pull request as ready for review July 27, 2026 01:32
@Haruko386 Haruko386 added the ci Continue Integration label Jul 27, 2026

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 27, 2026
@Haruko386
Haruko386 marked this pull request as draft July 27, 2026 01:38
@Haruko386
Haruko386 marked this pull request as ready for review July 27, 2026 01:38
@Haruko386 Haruko386 added ci Continue Integration and removed ci Continue Integration labels Jul 27, 2026
@JinHai-CN
JinHai-CN merged commit 4b39106 into infiniflow:main Jul 27, 2026
12 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants