[Chore!] Add error verification on callback from stream #40
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was trying to implement a similar feature like the "Stop Generating" from ChatGPT and I noticed that there's no mechanism to stop the stream call coming from the OpenAI. I had the problem where even if I return from my callback, it will be called again and again. The most simple way I found was to return an error from the callback and validate this error.
This is a breaking change for every application that uses this lib (but also pretty simple to refactor), but I guess is important as much as necessary; if my callback is returning an error and anything is being done from the clientside, the server will keep generating chunks and wasting tokens.
I made in only one stream function to see what you guys think about it, but if it's relevant I'm willing to change the remaining stream methods