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

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

Open
TalentDev0401 opened this issue Nov 21, 2023 · 7 comments
Open

Comments

@TalentDev0401
Copy link

TalentDev0401 commented Nov 21, 2023

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?

@JanusChoi
Copy link

Have the same issue today while using ChatStream

@svkozak
Copy link

svkozak commented Jan 29, 2024

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

@neelvirdy
Copy link
Contributor

Also started getting this error suddenly today when streaming

@prateekshac1
Copy link

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?

@svkozak
Copy link

svkozak commented Jan 31, 2024

This looks like the best fix: #151 (comment)

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)

@prateekshac1
Copy link

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

@iamklim
Copy link

iamklim commented Jan 31, 2024

Same here, receive this error while using chatsStream

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

6 participants