Use Query needs additional functions
I need help with this, how do we know the use query value is not changing anymore? Maybe an additional hook with useQuery so an event is fired when there are no changes.
Currently, I am streaming the response storing it in DB and using query to show on the frontend I want to render a button when a response is complete so for this case I am not able to figure out how can we handle this.
4 Replies
In general the result of a useQuery call always might change again in the future. You could detect that it hasn't changed so far for say ten seconds though.
But since you control the result of your query you could return a different value when you know the query has stopped changing: return whether the result is finished, like
@ballingt result is streaming from LLM so even I don't know when it will be complete so I am not sure how to implement the second approach.
That's why I thought It would be nice if useQuery could give additional helper callback functions
@Abhishek assuming your code looks something like mine here:
https://stack.convex.dev/ai-chat-with-convex-vector-search#serving-traffic-answering-a-question
After the for loop you know the response is done, and you can mutate the document again to mark it as such.
Or use a while loop instead of a for loop, then you can probably detect that the stream is over along with the last chunk (to avoid 2 writes at the end).
Build AI Chat with Convex Vector Search
Convex is a full-stack development platform and cloud database, including built-in vector search. In this third post in our [series](https://stack.con...
Thanks @Michal Srb this is what I was looking for 🤗