-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow to handle stream cancellation on server #309
Comments
Having the same issue. This is very important. |
This would be nice. to have an OnStop. I am finding it annoying to deal with function calls, when i want to abort after a function call. But i getting errors from using abort controllers via server methods. |
Is it really necessary to have all these callbacks? Having |
What are some current workarounds till the team fixes the issue? |
related issue vercel/next.js#48381 |
Hello @GorvGoyl, are you calling the OpenAI API using the OpenAI Node library (as documented in the examples from this SDK) or using your own custom logic to access the API? |
I'm using vercel edge function like this:
and then in the frontend (chrome extension) I'm using |
Yes, that's the same issue. Once aborted, you get a uncaught exception, which you can't catch.
I mentioned 2 work arounds here: #90 (comment)
To be honest, I don't think this catching of cancellation on the server - and then do something async with it - will ever work with serverless functions. Please prove me wrong! The only real permanent solution is using a normal "always on" server, like a NodeJS Express server or something else that's always running. Because when it's always running, you can do async things with a cancellation. |
Still having the same problem. Guess Vercel SDK is just limited |
Hope Vercel can solve it. |
The AI SDK functions support a |
Could you elaborate a bit how to achieve the desired functionality using Or anyone else who has successfully implemented a workaround to achieve something like an |
@lgrammel It Would be nice if abortSignal could trigger onFinish and pass as much data as possible to it. This would make it easier to save aborted messages to the database. |
@xl0 this will be problematic because of typesafety and cause a lot of optionality checks. I would prefer something like |
@lgrammel onAbort would work perfectly fine for me. |
Now we have stream cancellation working properly (#90 (comment) ) I think we need a way to detect and handle the cancellation server side.
In the current situation when a user cancels a stream, the server errors and there's no way to catch the cancellation and handle what should happen on the server. But I want to know how many tokens are generated when the user cancels the stream, so I can then store that information in my external database.
Currently we have
onStart
,onCompletion
andonToken
callback methods onOpenAIStream()
/AIStream()
. Ideally a new callback method would be great, something likeonStop
(to follow thestop()
method naming in the React Hooks) oronCancel
, which passes through the completion text at that point and allows to calculate the tokens and write that to a external database.Or a different way to just catch the abort error in our (Edge) Functions.
From my understanding, I guess we need to postpone the abort until whatever method is doing something async is done, otherwise the serverless function might not exist anymore.
Is this even possible?
The text was updated successfully, but these errors were encountered: