Skip to content

Commit

Permalink
Updated prompts, updated profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurvir committed Apr 6, 2024
1 parent 1d36589 commit 3e6e8be
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dhp:consultation:0.1.0",
"tourism"
],
"description": "This network supports multiple domains e.g. uei:charging for ev chargers, retail:1.1.0 for retail stores including grocceries and pet supplies, hospitality for hotels, dhp:consultation:0.1.0 for doctors or healthcare, tourism for tickets and tours",
"description": "This network supports multiple domains e.g. uei:charging for ev chargers, retail:1.1.0 for retail stores including grocceries, rain wear, rain cpats, umbrellas and pet supplies, hospitality for hotels/stays/accomodations, dhp:consultation:0.1.0 for doctors or healthcare, tourism for tickets and tours",
"bap_subscriber_id": "mit-ps-bap.becknprotocol.io",
"bap_subscriber_url": "https://mit-ps-bap.becknprotocol.io",
"version": "1.1.0"
Expand Down
10 changes: 5 additions & 5 deletions controllers/Bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,8 @@ async function process_text(req, res) {
}
else if(ai.action?.action == null) {
// get ai response
response.formatted = await ai.get_ai_response_to_query(message, session.text, session.profile);
response.formatted = await ai.get_ai_response_to_query(message, session.text);
logger.info(`AI response: ${response.formatted}`);

// update session
session.text.push({ role: 'user', content: message });
session.text.push({ role: 'assistant', content: response.formatted });
}
else{
response = await process_action(ai.action, message, session, sender);
Expand All @@ -163,6 +159,10 @@ async function process_text(req, res) {
}
}

// update session
session.text.push({ role: 'user', content: message });
session.text.push({ role: 'assistant', content: response.formatted });

// update session
await db.update_session(sender, session);

Expand Down
2 changes: 1 addition & 1 deletion controllers/ControlCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const updateCatalog = async (req, res) => {
export const notify = async (req, res) => {
try {
const { userNo = TWILIO_RECEPIENT_NUMBER } = req.body;
const messageBody = TRIGGER_BLIZZARD_MESSAGE;
const messageBody = req.body.message || TRIGGER_BLIZZARD_MESSAGE;
const sendWhatsappNotificationResponse = await action.send_message(
userNo,
messageBody
Expand Down
6 changes: 3 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import express from 'express'
import bodyParser from 'body-parser'
import logger from './utils/logger.js'
import messageController from './controllers/Bot.js'
// import DBService from './services/DBService.js'
import DBService from './services/DBService.js'
import {
cancelBooking,
updateCatalog,
Expand All @@ -28,8 +28,8 @@ app.post('/update-catalog', updateCatalog)


// Reset all sessions
// const db = new DBService()
// await db.clear_all_sessions()
const db = new DBService()
await db.clear_all_sessions()

// Start the Express server
app.listen(process.env.SERVER_PORT, () => {
Expand Down
22 changes: 15 additions & 7 deletions services/AI.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class AI {
*/
async get_beckn_action_from_text(text, context=[]){
const openai_messages = [
{ role: 'system', content: `Your job is to analyse the latest user input and check if its a valid action based on the supported actions given here : : ${JSON.stringify(openai_config.SUPPORTED_ACTIONS)}` },
{ role: 'system', content: `Your job is to analyse the latest user input and check if it is one of the actions given in the following json with their descriptions : ${JSON.stringify(openai_config.SUPPORTED_ACTIONS)}` },
{ role: 'system', content: `You must return a json response with the following structure : {'action':'SOME_ACTION_OR_NULL'}`},
{ role: 'system', content: `'action' must be null if its not from the given set of actions.` },
{ role: 'system', content: `'action' must be null if its not from the given set of actions. For e.g. planning a trip is not an action. 'find hotels near a place' is a search action.` },
...(context.length > 0 ? context.slice(-1) : []), // only use teh last message for context here
{ role: 'user', content: text }
]
Expand Down Expand Up @@ -61,7 +61,9 @@ class AI {
*/
async get_ai_response_to_query(instruction, context=[], profile = {}){
const openai_messages = [
{ role: 'system', content: 'If you are asked to prepare an itinerary or plan a trip, you should have information about the user preferences such as journey dates, journey destination, number of members, mode of transport etc. You must check if these details are available in the user profile or not. If not, you should ask for these details before proceeding further. If the detail are available, or partial details are available you should ask for the missing details and show the details you have that wil be used for planning the trip for confirmation.'},
{ role: 'system', content: 'If you are asked to prepare an itinerary or plan a trip, you should have information about the user preferences such as journey dates, journey destination, number of members, mode of transport etc.'},
{ role: 'system', content: 'You must come back with a response immedietaley, do not respond back saying that you will come back with a resopnse.'},
{ role: 'system', content: 'While preparing an itinerary, you should also share a short list of bookings that needs to be made and ask the user which one they want to book first.'},
{ role: 'system', content: `User profile : ${JSON.stringify(profile)}`},
...context,
{ role: 'user', content: instruction}
Expand Down Expand Up @@ -291,15 +293,21 @@ class AI {
"name": "",
"email": "",
"phone": "",
"address": "",
"gender": "",
"age" : ""
"travel_source": "",
"travel_destination": "",
"current_location_gps": "",
"vehicle-type":"",
"connector-type": "",
"pet-friendly_yn":0,
"ev-charging-yn":0,
"accomodation_type":"",
"number_of_family_members":""
}

const openai_messages = [
{ role: 'system', content: `Please analyse the given user message and extract profile information about the user which is not already part of their profile. The desired outout format should be the following json ${JSON.stringify(desired_output)}` },
{ role: 'system', content: `You must not send any vague or incomplete information or anything that does not tell something about the user profile.` },
{ role: 'system', content: `Any profile infromation that does not match the desired output should be sent under a key 'misc'. You are not always required to return a response, return empty json if no profile information extracted.` },
{ role: 'system', content: `Return empty json if no profile information extracted.` },
{ role: 'system', content: `Existing profile : ${JSON.stringify(profile)}`},
{ role: 'user', content: message }
]
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/services/ai.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,6 @@ describe('Test cases for get_profile_from_text', () => {
expect(response.data.email).to.eq('[email protected]');
})

it('Should return misc. information about user if shared', async ()=> {
const response = await ai.get_profile_from_text('I just bough an EV and wanted to take it for a spin.');
expect(response.status).to.be.true;
expect(response.data).to.have.property('misc');
})

it('Should return nothing if no profile information available', async ()=> {
const response = await ai.get_profile_from_text('Yes please');
expect(response.status).to.be.true;
Expand Down

0 comments on commit 3e6e8be

Please sign in to comment.