[Chore!] Add error verification on callback from stream - #40
Conversation
There was a problem hiding this comment.
✅ This pull request was sent to the PullRequest network.
@letschers you can click here to see the review status or cancel the code review job.
There was a problem hiding this comment.
The change is simple and straightforward with the explanation from the author. But, as stated by the author, this is a breaking change that need to be taking care of by any other code using this
Reviewed with ❤️ by PullRequest
|
Hey guys, any news? |
tylermann
left a comment
There was a problem hiding this comment.
This change makes sense to me.
I could see a non-breaking change variant where we allow something like this:
onData = func (resp *ChatCompletionStreamResponse) {
resp.Stop(errors.New('some error))
}
Although I think your proposed change here is more idiomatic and it is a fairly easy refactor as you mentioned. So lets just go with this.
Thanks for the contribution and sorry for the delay to getting around to this.
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