alfianlosari/ChatGPTSwift

Stream occasionally skips words

PallavAg opened this issue · 8 comments

I am not exactly sure what changed, but after updating the package from version 1.3.3 to 1.4.0 I noticed that while streaming the response, words were occasionally being skipped. Downgrading to 1.3.3 resolved this issue. Might be worth looking into.

I don't have a reproducible example but about every 100 words I notice a missing word.
It's much more noticeable while generating code since the syntax error becomes evident.

Yep seeing the same thing

Yes, same issue here.

Vk12 commented

I'm seeing this issue as well. Anyone find a fix?

I noticed this issue as well. I moved to https://github.com/MacPaw/OpenAI

The transition was pretty simple, only took a few minutes, and it seems to be better overall.

Downgrading to version 1.3.3 or using the MacPaw library seems to be the best solution for now

Same here

I debugged this a bit today and it seems that always the first token is disappearing from the URLsession.bytes stream in the sendMessageStream function in ChatGPTAPI.swift. When I put "for try await line in result.lines" before the "return AsyncThrowingStream ..." section all tokens are there. Only inside the "return AsyncThrowingStream closure", the first token is missing and replaced by a "delta":{"content":","}. Does anyone with more understanding of this code have any idea? Thx!

I wonder if the issue is similar to the one fixed here: MacPaw/OpenAI#104
The MacPaw library would end the stream when a partial json object was received in the chunk.
This library may be simply skipping the json objects that come in partially - hence the seemingly random missing tokens.