deep-chat
deep-chat copied to clipboard
Dynamically add responses for long-running tasks
There are use-cases where agent can be asked to perform a task which can take time much longer than typical web request timeout limit. For example: "Research and prepare a report", "Confirm with James if this task is ready to be picked up?"
Is there a way for a custom backend to push a message into a visible chat thread? If the user were to reload the page, initialMessages
could be updated, but this is not ideal.
Perhaps this can be achieved simply by an automatic periodic refresh of the conversation using setInterval
?
Perhaps this can be done by manually using the "deepChatInstance. addMessage" method after receiving the message to add the content to the current conversation process
@buzhou9 Yeah, just got to know about _addMessage
. That might work too.
@buzhou9 is doing an amazing job with the responses, I have been very short on free-time so thankyou so much!!!!
@nileshtrivedi if @buzhou9's suggestion for using _addMessage
works for you then I am very happy.
I have a few other alternative suggestions that you can also use:
-
You can use the request handler to control the request logic and return the response exactly when you need to.
-
You can make the request using your code and respond in the responseInterceptor. It is a slightly more complicated approach to above, but it is still something that works:
- Set demo to true
- Use the requestInterceptor to listen for when a user sends a message. When that is triggered - make the request in your own code.
- Change the responseInterceptor code to be something as follows, where you store the
resolve
argument in your own state, and trigger it (using the Response format) when you have the eventual response from your server:
async (response) => {
return new Promise((resolve) => {
// save the resolve argument in your app's state and call it when ready
});
}
If the user has opened up a fresh new page or reloaded it and you still want to add a message after it, I recommend immediately triggering the submitUserMessage method with their request text to display the loading message and prevent the user from creating another request, then handling the response using any of the above suggestions.
Huge shoutout to @buzhou9 for helping out!!!!!!
Hi, the functionality mentioned in this issue is now available in Deep Chat version 2.0.0
.