Skip to content

fix(server): return plain text for response_format=text - #3874

Merged
LauraGPT merged 1 commit into
modelscope:mainfrom
David-Wu1119:fix/server-text-response-plain
Nov 11, 2026
Merged

LauraGPT merged 1 commit into
modelscope:mainfrom
David-Wu1119:fix/server-text-response-plain

Conversation

@David-Wu1119

Copy link
Copy Markdown
Contributor

Summary

funasr-server answers response_format=text on /v1/audio/transcriptions with JSONResponse(result["text"]), so the body is a JSON string literal ("say \"hi\"", application/json). OpenAI's transcription API returns the bare transcript for text, and the OpenAI Python SDK returns response.text directly for that format (openai.lib._parsing._audio.get_transcription_response_format_type maps text to str), so SDK and curl users receive the quotes and escape characters as part of the transcript.

client.audio.transcriptions.create(model="sensevoice", file=f, response_format="text")
# main:   '"say \\"hi\\""'
# branch: 'say "hi"'

Fix: return PlainTextResponse for this branch. json and verbose_json are unchanged.

Type of change

  • Bug fix
  • Documentation
  • Example or demo
  • Runtime or deployment
  • Benchmark or evaluation
  • Model/training change

Validation

Environment: macOS arm64, Python 3.11.15, CPU-only torch 2.15.0, fastapi 0.162.4 / starlette 1.10.0, openai 3.49.0, pytest 9.2.0.

  • New test_text_response_format_returns_plain_text in tests/test_server_app_openai_segments.py (the stubbed fastapi.responses module gains a PlainTextResponse stub). It fails on main (the route returns the JSON-wrapped value) and passes with this change: python -m pytest -q tests/test_server_app_openai_segments.py gives 1 failed / 23 passed on main, 24 passed here.
  • Neighbours: tests/test_service_docs_contract.py, tests/test_openai_api_n8n_compat.py, tests/test_fun_asr_nano_openai_response.py, tests/test_openai_api_docker_validation.py, tests/test_docs_funasr_install_commands.py pass. tests/test_gradio_app.py fails the same 19 cases on main and here because gradio is not installed in the test environment.
  • End to end with real FastAPI: create_app(device="cpu", preload_model="sensevoice") with a stub AutoModel, POST /v1/audio/transcriptions (response_format=text) through fastapi.testclient.TestClient and through openai.OpenAI(..., http_client=TestClient). main: application/json, body "say \"hi\""; this branch: text/plain; charset=utf-8, body say "hi".
  • python -m compileall funasr examples tests
  • Docs or links checked
  • Runtime/deployment command tested (in-process TestClient against create_app; no model weights, no GPU, no running funasr-server process)

User impact

OpenAI-compatible clients (OpenAI SDK, LiteLLM-style proxies, scripts migrating from Whisper) that request response_format=text get the transcript itself.

Notes for reviewers

srt and vtt still fall through to the json branch; that is out of scope here.

🤖 Generated with Claude Code

The packaged funasr-server handles response_format=text by wrapping the
transcript in JSONResponse, so the body is a JSON string literal such as
"say \"hi\"" with application/json. OpenAI's transcription API returns the
bare transcript for this format, and the OpenAI Python SDK hands
response.text straight back to the caller, so clients received the
surrounding quotes and escaped characters as part of the transcript.

Return PlainTextResponse for this branch. json and verbose_json are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 05:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@LauraGPT
LauraGPT merged commit be264e9 into modelscope:main Nov 11, 2026
1 check passed
LauraGPT added a commit that referenced this pull request Nov 12, 2026
…esponses

Correct the Product site CI failure exposed by #3874 without changing the handler or weakening security/format contracts. Preserve the 1.4.15 recipe and add visible, source-bound current-main notices.

Signed-off-by: LauraGPT <zhifu.gzf@alibaba-inc.com>
LauraGPT added a commit that referenced this pull request Nov 12, 2026
Deliver plain-text HTTP responses and VAD word boundaries (#3874, #3883).

Signed-off-by: LauraGPT <zhifu.gzf@alibaba-inc.com>
@LauraGPT LauraGPT mentioned this pull request Nov 12, 2026
LauraGPT added a commit that referenced this pull request Nov 12, 2026
Deliver tested plain-text HTTP responses and VAD word boundaries (#3874, #3883).

Signed-off-by: LauraGPT <zhifu.gzf@alibaba-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants