fix(audio): treat DIARIZED_JSON as a JSON response format (#652)#744
Open
spor3006 wants to merge 1 commit into
Open
fix(audio): treat DIARIZED_JSON as a JSON response format (#652)#744spor3006 wants to merge 1 commit into
spor3006 wants to merge 1 commit into
Conversation
AudioResponseFormat.isJson() omitted DIARIZED_JSON from its when() branches and fell through to the `else -> false` default. As a result, `AudioTranscriptionService.create(...)` with `response_format = DIARIZED_JSON` parsed the response body as plain text — the entire diarized JSON payload was dropped into `TranscriptionCreateResponse.transcription.text` instead of populating `TranscriptionCreateResponse.diarized`. Callers had to round-trip the text field through an external Jackson reader to recover the structured result. Add `DIARIZED_JSON -> true` to isJson() and add an AudioResponseFormatTest that enumerates every value of AudioResponseFormat.Known explicitly, so any future format added to the enum forces a conscious decision about whether it is JSON — the same class of bug cannot regress when a new format is introduced. Fixes openai#652 Signed-off-by: Sparshal Kothari <41056517+spor3006@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #652.
Problem
AudioResponseFormat.isJson()was missing aDIARIZED_JSON -> truebranch:When a caller requested
response_format = DIARIZED_JSONfromaudio.transcriptions().create(...), the SDK treated the response as plain text. The entire diarized JSON payload was stuffed intoTranscriptionCreateResponse.transcription.text, leavingTranscriptionCreateResponse.diarizedempty. The only workaround was to manually re-parse the raw text field through Jackson:Fix
Two small changes:
AudioResponseFormat.isJson():AudioResponseFormatTestthat enumerates every value ofAudioResponseFormat.Knownexplicitly and asserts the expectedisJson()return value. Because the test exhaustively switches onKnown, adding any new format to the enum will fail compilation of the test until the test author explicitly choosestrueorfalsefor it. The same class of bug cannot regress.Tests
Verified the second test (
diarizedJson_isReportedAsJson) fails onmainwithout the production change — the response would be reported as non-JSON.Scope
AudioResponseFormat.kt(one line) and the new test file change. No public API surface change.TranscriptionCreateResponse.isValid()follow-up symptom noted in the issue (server-side response missing required fields per the OpenAPI spec) is left out — that's a spec/server question, not an SDK bug.Fixes #652