lzell / AIProxySwift

Client for AIProxy
https://www.aiproxy.pro
73 stars 9 forks source link

Do not json deserialize whisper response for 'text' responseFormat #40

Closed lzell closed 2 months ago

lzell commented 2 months ago

If a customer specifies that the whisper response format is text, then we don't want to json deserialize the http response body from OpenAI.

Before this change, a request format like the following would raise on the let response = try line:

let requestBody = OpenAICreateTranscriptionRequestBody(
    file: try Data(contentsOf: url),
    model: "whisper-1",
    responseFormat: "text"
)
let response = try await openAIService.createTranscriptionRequest(body: requestBody)

This patch skips the use of Decodable and instead instantiates the OpenAICreateTranscriptionResponseBody directly using the http response body.

Thanks to Pierre for reporting!