OpenAI
OpenAI copied to clipboard
The data couldn’t be read because it isn’t in the correct format.
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?
Have the same issue today while using ChatStream
Started suddnly getting this error too (when streaming), although it was supposedly fixed in #104
Also started getting this error suddenly today when streaming
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?
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)
Perfect. Yes, that fixes it, and makes sense. Thank you @svkozak :)
Same here, receive this error while using chatsStream