fix: stream audio transcription responses - #5394
Conversation
WalkthroughThis PR adds streaming support to audio transcription and translation endpoints. ChangesAudio Streaming Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Important
📝 变更描述 / Description
修复
/v1/audio/transcriptions接口在stream=true时无法通过网关流式返回的问题。OPENAI相关接口文档:https://developers.openai.com/api/docs/guides/speech-to-text#streaming-the-transcription-of-a-completed-audio-recording
修复前:客户端通过 multipart 表单传入
stream=true时,网关没有把该请求识别为流式请求;同时 OpenAI 兼容的 STT 响应处理会固定读取完整上游响应体后再返回。因此即使上游 vLLM服务/v1/audio/transcriptions接口 已经按 SSE 流式输出,经过网关后客户端仍只能在请求结束后一次性收到结果。修复后:音频转写/翻译请求会正确识别
stream=true,并在上游响应确认为text/event-stream时边读边转发给客户端。普通 JSON 响应仍保持原有读取和 usage 解析逻辑。实现上,新增了音频请求对
stream字段的解析,并将流式响应处理限制在 STT/translation 且上游确认为 SSE 的场景;这样既能恢复转写流式透传,也不会改变非流式接口的行为。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
本地验证通过: