Skip to content

fix(go): support OpenAI audio endpoints - #15104

Merged
JinHai-CN merged 8 commits into
infiniflow:mainfrom
bitloi:fix/15102-openai-go-audio-stubs
May 25, 2026
Merged

JinHai-CN merged 8 commits into
infiniflow:mainfrom
bitloi:fix/15102-openai-go-audio-stubs

Conversation

@bitloi

@bitloi bitloi commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Closes #15102.

OpenAI's Go provider config advertises whisper-1 as ASR and tts-1 as TTS, but the Go driver returned openai, no such method for both audio paths and did not define url_suffix.asr / url_suffix.tts.

This PR:

  • adds OpenAI audio URL suffixes for audio/transcriptions and audio/speech
  • implements non-streaming TranscribeAudio using multipart form uploads
  • implements non-streaming AudioSpeech using the OpenAI speech JSON request shape
  • keeps streaming TTS explicitly unsupported instead of sending binary audio through the text SSE sender
  • adds focused tests for config coverage, ASR/TTS request shape, required TTS voice validation, and unsupported streaming TTS

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 21, 2026
@coderabbitai

coderabbitai Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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.

Changes

OpenAI Audio Capabilities

Layer / File(s) Summary
Configuration, imports, multipart helper
conf/models/openai.json, internal/entity/models/openai.go
Add url_suffix entries for ASR and TTS; extend imports for multipart/file handling; add writeOpenAIMultipartField helper.
ASR: TranscribeAudio & streaming
internal/entity/models/openai.go, internal/entity/models/openai_test.go
Implement TranscribeAudio (multipart POST to /audio/transcriptions), TranscribeAudioWithSender (SSE or non-SSE streaming parsing), response decoding helper, and the ASR request builder.
TTS: AudioSpeech & streaming
internal/entity/models/openai.go, internal/entity/models/openai_test.go
Implement non-streaming AudioSpeech (JSON POST to /audio/speech with required voice), streaming AudioSpeechWithSender (SSE or raw stream), TTS request builder, and SSE/raw stream readers.
Tests: config, ASR, TTS, streaming
internal/entity/models/openai_test.go
Add newOpenAIForTest helper and tests validating conf/models/openai.json url_suffixes, ASR multipart behavior, streaming deltas, TTS JSON body validation, and both SSE and raw audio streaming behaviors.

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]
Loading
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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • infiniflow/ragflow#14605: Foundational OpenAI driver/config updates that this PR extends with audio (ASR/TTS) url_suffixes and method implementations.

Suggested labels

size:XL

Suggested reviewers

  • Haruko386

Poem

🐰 I nibble bytes and hum a tune,

Multipart hops beneath the moon,
Whispers turn to text, then speech,
Streams of audio within my reach,
Tests all green — I dance, I swoon.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title 'fix(go): support OpenAI audio endpoints' is clear, concise, and accurately describes the main change implementing ASR/TTS audio support.
Linked Issues check ✅ Passed All code changes directly address #15102 requirements: adds url_suffix entries for audio/transcriptions and audio/speech, implements TranscribeAudio and AudioSpeech methods with proper multipart and JSON request handling.
Out of Scope Changes check ✅ Passed All changes are directly scoped to #15102: configuration updates for audio URL suffixes, implementation of ASR/TTS methods, and comprehensive test coverage for the new functionality.
Description check ✅ Passed The PR description is complete and well-structured, addressing the required template sections with clear problem statement and type of change.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@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/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

📥 Commits

Reviewing files that changed from the base of the PR and between 111cdc7 and a95f36b.

📒 Files selected for processing (3)
  • conf/models/openai.json
  • internal/entity/models/openai.go
  • internal/entity/models/openai_test.go

Comment thread internal/entity/models/openai_test.go Resolved
Comment thread internal/entity/models/openai.go Resolved
@bitloi

bitloi commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

Ready for review!

@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.

Hi @bitloi, I have requested some changes, hope you could do all of them

Comment thread internal/entity/models/openai.go Resolved
Comment thread internal/entity/models/openai.go Resolved
@bitloi

bitloi commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi @bitloi, I have requested some changes, hope you could do all of them

@Haruko386 I addressed all of them, would you please check the changes?

@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.

@bitloi LGTM

@Haruko386 Haruko386 added the ci Continue Integration label May 22, 2026
@bitloi

bitloi commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

@JinHai-CN Ready for review!

@codecov

codecov Bot commented May 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.12%. Comparing base (e6dd397) to head (0bf6a35).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 432e966 into infiniflow:main May 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: OpenAI Go driver advertises ASR/TTS models but returns no such method

3 participants