Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-JSON formatted data or verbose JSON data on AudioTranscriptions couldn’t decode #130

Open
usagimaru opened this issue Nov 22, 2023 · 1 comment

Comments

@usagimaru
Copy link

usagimaru commented Nov 22, 2023

Describe the bug

I have tested the behavior of new response_format parameter implemented with #114. However, my frontend code always returned a JSON decoding error.

I traced from the breakpoint and found that it catches the error at this line in the method performRequest<ResultType: Codable>() of OpenAI.swift. Errors seems to occur when anything but a specific JSON structure (e.g. plain text) is entered.

  • Serialized data is also returned as UTF-8 plain text
  • JSON structure seems to have several patterns (e.g. Verbose JSON)

I tried all formats in the new enum AudioResponseFormat and found that only .json worked fine, text, Verbose JSON, srt and vtt caught any errors.

  • AudioResponseFormat.json
  • AudioResponseFormat.text
  • AudioResponseFormat.verboseJson
  • AudioResponseFormat.srt
  • AudioResponseFormat.vtt

I have not tried testing with the AudioTranslations API, but it may contain same problems.


Error example 1

APIErrorResponse(error: OpenAI.APIError(message: "1 validation error for Request\nbody -> response_format\n value is not a valid enumeration member; permitted: 'json', 'text', 'vtt', 'srt', 'verbose_json' (type=type_error.enum; enum_values=[<ResponseFormat.JSON: 'json'>, <ResponseFormat.TEXT: 'text'>, <ResponseFormat.VTT: 'vtt'>, <ResponseFormat.SRT: 'srt'>, <ResponseFormat.VERBOSE_JSON: 'verbose_json'>])", type: "invalid_request_error", param: nil, code: nil))

Error example 2

dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Unexpected character 'W' around line 1, column 1." UserInfo={NSDebugDescription=Unexpected character 'W' around line 1, column 1., NSJSONSerializationErrorIndex=0})))

Expected behavior

Correctly decode returned data as JSON or plain text (including vtt, srt).

Desktop (please complete the following information):

  • OS: macOS
  • Version 14.1.1
@paulz
Copy link

paulz commented Apr 30, 2024

    func audioTranscriptions(
        query: AudioTranscriptionQuery
    ) async throws -> AudioTranscriptionResult {

incorrectly throws JSON decoding error for AudioResponseFormat.srt

we could not use other formats as we need time codes

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

No branches or pull requests

2 participants