OpenAI icon indicating copy to clipboard operation
OpenAI copied to clipboard

The data couldn’t be read because it isn’t in the correct format.

Open TalentDev0401 opened this issue 1 year ago • 7 comments

I am implementing OpenAI into my iOS app. I integrated OpenAI library into my iOS app using swiftpackage. I configured OpenAI api key and implemented "Completion" with prompt text. But, I have got above issue.

Below are my code.

let openAI = OpenAI(apiToken: "YOUR_TOKEN_HERE") let query = CompletionsQuery(model: .textDavinci_003, prompt: "What is 42?", temperature: 0, maxTokens: 100, topP: 1, frequencyPenalty: 0, presencePenalty: 0, stop: ["\n"]) openAI.completions(query: query) { result in switch result { case .success(let result): print(result.choices) case .failure(let error): //Handle chunk error here print(error.localizedDescription) } }

But, I have got error message - "The data couldn’t be read because it isn’t in the correct format." How can I solve this issue shortly?

TalentDev0401 avatar Nov 21 '23 10:11 TalentDev0401

Have the same issue today while using ChatStream

JanusChoi avatar Jan 27 '24 07:01 JanusChoi

Started suddnly getting this error too (when streaming), although it was supposedly fixed in #104

svkozak avatar Jan 29 '24 23:01 svkozak

Also started getting this error suddenly today when streaming

neelvirdy avatar Jan 30 '24 22:01 neelvirdy

I've started to suddenly get this error while using chatStream too, and very often. A bit concerning as my app is in production. Trying to find a quick fix. Any suggestions?

prateekshac1 avatar Jan 31 '24 01:01 prateekshac1

This looks like the best fix: https://github.com/MacPaw/OpenAI/pull/151#issuecomment-1913703132

And the reason is that if stringContent starts or ends with a separator (in our case data:), the .components(separatedBy:) adds an empty string to the array (reference)

svkozak avatar Jan 31 '24 01:01 svkozak

Perfect. Yes, that fixes it, and makes sense. Thank you @svkozak :)

prateekshac1 avatar Jan 31 '24 02:01 prateekshac1

Same here, receive this error while using chatsStream

iamklim avatar Jan 31 '24 21:01 iamklim