Closed rvangari96 closed 7 months ago
Hi @rvangari96.
There are a couple of ways this can be achieved. Here is sample code for two different ways - this is using React syntax but you can pretty much tailor it to your framework:
demo
property will need to be replaced with request
to your specific API:
<DeepChat
demo={{response: {html: '<div>Response</div> <button class="regenerate">regenerate</button>'}}}
htmlClassUtilities={{
regenerate: {
events: {
click: (event) => {
// insert logic to retrieve a new response
const newText = 'New Response';
// find text element and insert there
const previousSibling = (event.target as HTMLElement).previousElementSibling as HTMLElement;
previousSibling.textContent = newText;
},
},
},
}}
/>
overwrite
response property and controlling everything in a websocket based handler
function. Your connection ofcourse doesn't need to be a websocket and you can insert your code as noted by the comments:
const ref = React.useRef<DeepChatCore>(null);
let signalsRef: any = null;
return ( <DeepChat ref={ref} request={{ handler: (_, signals) => { signalsRef = signals; signals.onOpen(); signals.newUserMessage.listener = () => { // insert logic to retrieve a response signals.onResponse({html: '
Let me know if you have any questions.
Thanks!
Closing this issue since there has been no further communication. Feel free to comment below for anything related to this issue or create a new one for other topics. Thankyou!
Hi, I need to regenerate a response with the same prompt used before. Please advise on how to do it.