Repository navigation
fix(go): support OpenAI audio endpoints - #15104
Conversation
📝 WalkthroughWalkthroughAdds real OpenAI ASR (multipart /audio/transcriptions) and TTS (JSON /audio/speech) implementations including streaming support, updates config URL suffixes, adds multipart helper and imports, and provides tests for non-streaming and streaming audio flows. ChangesOpenAI Audio Capabilities
Sequence Diagram(s)sequenceDiagram
participant APIClient
participant OpenAIModel
participant OpenAIEndpoint
APIClient->>OpenAIModel: TranscribeAudio(model, file, params)
OpenAIModel->>OpenAIModel: build multipart (file + fields), set stream flag if requested
OpenAIModel->>OpenAIEndpoint: POST /audio/transcriptions (multipart, Bearer)
OpenAIEndpoint->>OpenAIModel: text/plain or JSON or SSE events
OpenAIModel->>APIClient: transcript chunks and final [DONE]
sequenceDiagram
participant APIClient
participant OpenAIModel
participant OpenAIEndpoint
APIClient->>OpenAIModel: AudioSpeech(model, input, ttsConfig)
OpenAIModel->>OpenAIModel: validate voice, build JSON (model,input,voice,stream_format)
OpenAIModel->>OpenAIEndpoint: POST /audio/speech (application/json, Bearer)
OpenAIEndpoint->>OpenAIModel: audio bytes or SSE audio.delta events
OpenAIModel->>APIClient: streamed audio chunks or final audio bytes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
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. 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: 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/openai_test.go`:
- Around line 85-86: Replace any t.Fatalf calls inside the httptest.NewServer
handler closures (e.g., the handlers that call ParseMultipartForm and other
request-parsing checks in internal/entity/models/openai_test.go) with
t.Errorf(...) followed by an immediate return so the handler stops processing
but the test goroutine continues and the failure is properly reported; update
each handler closure that currently uses t.Fatalf("ParseMultipartForm: %v", err)
(and the other occurrences) to call t.Errorf with the same message and then
return from the handler.
In `@internal/entity/models/openai.go`:
- Around line 764-768: The current validation checks only presence/null for
reqBody["voice"] and emptiness for string values, allowing non-string types
through; update the validation (around the reqBody handling for "voice") to
assert the value is a string type and that strings.TrimSpace(voiceString) != ""
— i.e., first type-assert reqBody["voice"] to string (reject if not string),
then check non-empty after trimming and return a clear error (e.g., "voice must
be a non-empty string") to replace the existing fmt.Errorf("voice is required")
path.
🪄 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: fb944726-05ef-42f1-9f3f-13b7464ad922
📒 Files selected for processing (3)
conf/models/openai.jsoninternal/entity/models/openai.gointernal/entity/models/openai_test.go
|
Ready for review! |
@Haruko386 I addressed all of them, would you please check the changes? |
|
@JinHai-CN Ready for review! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15104 +/- ##
==========================================
- Coverage 94.53% 93.12% -1.41%
==========================================
Files 10 10
Lines 713 713
Branches 116 116
==========================================
- Hits 674 664 -10
- Misses 25 29 +4
- Partials 14 20 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Closes #15102.
OpenAI's Go provider config advertises
whisper-1as ASR andtts-1as TTS, but the Go driver returnedopenai, no such methodfor both audio paths and did not defineurl_suffix.asr/url_suffix.tts.This PR:
audio/transcriptionsandaudio/speechTranscribeAudiousing multipart form uploadsAudioSpeechusing the OpenAI speech JSON request shapeType of change