OvidijusParsiunas / deep-chat

Fully customizable AI chatbot component for your website
https://deepchat.dev
MIT License
1.27k stars 176 forks source link

websocket connection getting called many times at start #52

Closed nishit-g closed 7 months ago

nishit-g commented 7 months ago

So, i am modifying the websocket sample template provided ,

Now the websocket handler or is trying to call connection many times sometimes , causing issues and the sometimes not rendering the messages as well.

Why is the handler being called many times ? How can i stop that thing ?

Sandbox

OvidijusParsiunas commented 7 months ago

Hi @nishit-g. Based on your example everything appears to be in order. The reason why the connection is being called multiple times (twice) is because in React dev mode the dom is rendered twice. It is a pretty standard convention in React and should not cause any problems. However if there are more than two attempts let me know as that is not the expected behaviour.

The reason why your messages are not rendering correctly is likely because new ones are being generated whilst older ones are still being streamed. Asynchronous message stream simulation in websockets is not supported in Deep Chat version 1.4.3. Luckily this is good timing as version 1.4.4 which is going to be released this Sunday will support this. You can get early access to it by using the deep-chat-dev and deep-chat-react-dev packages versioned 9.0.66. So you can either use them or not use the stream={{ simulation: 150 }} property until the new version is released Sunday.

Let me know if you are still having any problems. Thanks!

OvidijusParsiunas commented 7 months ago

Hi. The functionality discussed above has now been released in Deep Chat version 1.4.4. Please read the release notes for more information.

To note, simulation functionality has been changed to populate by character rather than word. So the recommended default number value is 6, but you can ofcourse change it to your preference.

I will be closing this issue, but if you experience problems relating to streaming or websockets feel free to comment below or raise a new issue for anything else. Thanks!