Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End session button disabled and need to know about DB changes for new features #1

Open
datacrud8 opened this issue Aug 30, 2023 · 3 comments

Comments

@datacrud8
Copy link

Hi, I checked out this latest code base & build in local its working. but End session button is always disabled: please sees the screen shot:
Capture2

Can you please tell me what is the possible code change d i need to do to make it visible.?

Another question, suppose want to one more features like "Travel Booking Status" - what kind of changes do I need to do in database side ?
I tried but its always looking field like :

Category:

Name:
Product-Code:
Price:
Variations:

How to implement this for other business area (other than ecom)?

@supershaneski
Copy link
Owner

By design, the EndSession button is shown if the AI decides to end the session but you can control it by manipulating isSessionEnded state variable. Just remove the conditional (Line 442, components/chat.jsx) to always show it.

If you want to adapt this to other business application, you need to fix the function calling. Refer to app/chat2/route.js file. There are several parts you need to edit:

Line 9, is the start of the function definition used in function calling. You need to add your own functions (e.g. get_user_booking, etc.).

Line 61, is the function calling system prompt. Edit it to reflect your function, etc.

Between Line 114 and 158, is the "external API call" part. Change it and put your own code there that will consume the result of the function calling.

Let say you have get_user_booking that has the output { name: 'John Doe', bookingNo: '1234567' }, then you can use it to retrieve data from your own DB or API.

@datacrud8
Copy link
Author

Thank you for the details:
I have the have get_user_booking that has the output
{ name: 'John Doe', bookingNo: '1234567', status: 'success', amunt: '123', date: '2023-09-01' }, for this do I need insert this value in mongodb first then do the code change ?

actually I am trying replicate how "order inquery" status working for order status , like wise planning to add one more for booking inquery. no need to add UI part , just want to insert few records in db and like check the status in chat and voice.
Can you please share your contact email if you can.

@supershaneski
Copy link
Owner

Assuming that you are trying to add booking entry, yes you need to insert the output to your own MongoDB. Then you need to tell Chat API the result (if insert is successful or not). Refer to Line 249 of app/chat2/route.js. For example:

If insert failed

messages.push({ role: 'assistant', content: null, function_call: { name: 'get_user_booking', arguments: `{\n  "name": "John Doe", "bookingNo": "1234567", "status":"error","amount": "123", "date": "2023-09-01" \n}` }})
messages.push({ role: 'function', name: 'get_user_booking', content: JSON.stringify({ error: "Failed to add booking. Missing parameter." }) })

If successful

messages.push({ role: 'assistant', content: null, function_call: { name: 'get_user_booking', arguments: `{\n  "name": "John Doe", "bookingNo": "1234567", "status":"success","amount": "123", "date": "2023-09-01" \n}` }})
messages.push({ role: 'function', name: 'get_user_booking', content: JSON.stringify({ message: "Booking added. Thank you..." }) })

This part is most important so that Chat api can decide what to do next. For example, if it failed and you said in the error message that "contact number" is missing, the AI will ask the user for the contact number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants