Closed zzulanas closed 3 months ago
Apparently it's not possible to access the updated messages
(and thus setMessages
too) in the onFinish
callback: https://github.com/vercel/ai/issues/525#issuecomment-1697878446
support for passing an update function to a setMessages call has landed in main
Description
Issue
I haven't touched my personal website in months, but I had this code working before and it seems to not anymore. Not sure if the SDK changed in an update or something but when I try to run my useChat completions.
In my code below I have my component
Chatty.tsx
which holds my Client-side component which has the chatbot in it, and I have a route called/api/search-func.ts
which I use for doing some vector embedding searches/prompt injection before completion, but this route also handles the completion itself.Deployed on Vercel this doesn't seem to work either. I thought it was my API Key or my supabase key/config but the stream is completing successfully before it returns, on the front-end messages always is an empty array and I'm not sure why.
Code example
Chatty.tsx
/api/search-func/route.ts
Additional context
Next.js Version: 13.4.7 ai Version: 2.1.3 Node Version: 21.6.2