OvidijusParsiunas / deep-chat

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

Dynamically set additionalBodyProps? #74

Closed RickGroenewegen closed 9 months ago

RickGroenewegen commented 9 months ago

Right now you can set some set values for additionalBodyProps that are the same each message to the server.

Is there a way to dynamically set these additionalBodyProps? The value I would like to pass could change with each message.

OvidijusParsiunas commented 9 months ago

Hi @RickGroenewegen. You can use the requestInterceptor property to change the body/header properties for each request. Let me know if you need further assistance.

RickGroenewegen commented 9 months ago

Thank you, that was what I was looking for!

I also have a question about the responseInterceptor. My server also sends other custom webservice messages besides the chat messages. Currently these throw errors in deep-chat because they do not fit the Response format. Is it possible to make the responseInterceptor ignore the messages that are not meant for deep-chat so I can call my custom methods on them?

Anyway: My compliments on this library. It has been a delight working with it so far!

OvidijusParsiunas commented 9 months ago

Happy to hear it works.

In regards to the responseInterceptor, could you elaborate on what you mean by " ignore the messages"? This property is used to augment the incoming responses to fit the format that Deep Chat is expecting. Hence, it will not be useful to ignore messages.

If you are working with a websocket connection, then responses can be ignored via the use of a handler function where you'll need to define the connection code yourself (which is not hard) and hence control what messages go to Deep Chat.

Let me know more about your use-case, what configuration you are using and what kind of responses you are working with to give you the right pointers. Thanks!

RickGroenewegen commented 9 months ago

I meant that I have one WS server, but this server sends both chat messages (Intended for Deep Chat), and application messages (Custom messages for my application which do not follow the Response type). Deep Chat currently throws errors on those last type of messages.

I though I might be able to use the responseInterceptor to return the valid Deep Chat messages and pass other messages on to my own methods. But since the responseInterceptor must always return a Response I think this is not possible?

I am indeed working with a websocket connection. I am not sure what you means by defining the connection code myself. Do you suggest I create my own WS connection and when I receive a Deep Chat message I am able to pass it on to Deep Chat? How would I do that? Because I see the addMessage method is no longer available?

OvidijusParsiunas commented 9 months ago

The Handler function will enable you to achieve the desired result. It enables you to control the websocket connection and what AI messages go into the chat. The implementation is quite simple and the documentation has a code example of how you can achieve this (by going to this hyperlink and clicking on the Websocket tab).

This is the code from the example which controls what AI messages will be displayed in the Deep Chat: signals.onResponse(response);

You can also watch the example video to help you out.

Let me know if you have any further questions or need help with some of your code. Thanks!

OvidijusParsiunas commented 9 months ago

I will be closing this issue since there has been no further communication. However, if you need any assistance in the topic of this thread feel free to comment below, otherwise you can raise a new issue. Thanks!