OvidijusParsiunas / deep-chat

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

How to use a handler function #101

Closed noel1973 closed 5 months ago

noel1973 commented 5 months ago

Hi @OvidijusParsiunas

First I want to thank you for an excellent chat, this chat is really good

I need your assistance

I have the following code

image

image

This code works well in VUE I can get the response back fine from an Azure function, but I'm not able to update the AI response on the chat using :responseInterceptor="(response) => {
return { text: response.choices[0].message.content }; }"

Any ideas how I can solve this? I don't know if this is a bug

Thanks in advance.

OvidijusParsiunas commented 5 months ago

Hi @noel1973. I see you are using the handler function to handle your requests and have assigned it to a function called fetchData.

handler function works by using signal calls as they are passed as the second argument: fetchData(data, signals) {. When you receive the response from your service - instead of return, you should use something like this signals.onResponse({text: data.bot.choices[0].message.content}) and signals.onResponse({error: error}).

This is all documented here and you can watch this video to help you.

Also, when using a handler function, you do not need the url request property and requestInterceptor/responseInterceptor are optional as you can handle everything in the handler.

Let me know if you have any other questions. Thanks.

noel1973 commented 5 months ago

Hi @OvidijusParsiunas

I found another way to do this

I just eliminated that function on the methods and do this instead

:responseInterceptor="async (response) => {
const data = await response.json();
return { text: data.bot }; }"

It works pretty well too :) but I follow your advice as well, thank you so much

OvidijusParsiunas commented 5 months ago

Ya, by looking at your code - you can do without the handler function :D

OvidijusParsiunas commented 5 months ago

I will be closing this issue since the original problem has been resolved. If you have any further questions, you are more than welcome to create a new issue.

Thankyou!