Skip to content

Commit

Permalink
Added route selection capability
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurvir committed Apr 8, 2024
1 parent d56f1ad commit fcae920
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 48 deletions.
1 change: 1 addition & 0 deletions config/openai.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"SUPPORTED_ACTIONS": [
{ "action": "get_routes", "description": "If the user has requested for routes for a travel plan between two places or asked to plan a trip." },
{ "action": "select_route", "description": "If the user selects one of the routes from one of the routes shared earlier by the assistant." },
{ "action": "search", "description": "If the user clearly indicates to perform a search for a specific product. Sample instructions : 'find a hotel', 'find an ev charger', 'find tickets'" },
{ "action": "select", "description": "If the user likes or selects any item, this action should be used. This action can only be called if a search has been called before." },
{ "action": "init", "description": "If the user wants to place an order after search and select and has shared the billing details. This action can only be called if a select has been called before." },
Expand Down
2 changes: 1 addition & 1 deletion controllers/Bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async function process_text(req, res) {
}
else if(ai.action?.action === 'get_routes'){
const routes = await mapService.generate_routes(message, session.text);
const formatting_response = await ai.format_response(routes.data?.routes_formatted || routes.errors, [...session.actions.formatted, { role: 'user', content: message },...session.text]);
const formatting_response = await ai.format_response(routes.data?.routes_formatted || routes.errors, [{ role: 'user', content: message },...session.text]);
response.formatted = formatting_response.message;
session.routes = routes.data?.routes || session.routes;
logger.info(`AI response: ${response.formatted}`);
Expand Down
57 changes: 57 additions & 0 deletions tests/apis/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import app from '../../server.js'
import request from 'supertest'
import * as chai from 'chai'
import logger from '../../utils/logger.js'
import DBService from '../../services/DBService.js'
const expect = chai.expect

beforeEach(async () => {
// Reset all sessions
const db = new DBService()
await db.clear_all_sessions()
})

describe.skip('API tests for /webhook endpoint for an end to end search > select > init > confirm use case', () => {
it('Should test succesful search response using /webhook endpoint', async () => {
Expand Down Expand Up @@ -208,4 +214,55 @@ describe.skip('Test cases for booking collection', ()=>{
expect(response.status).equal(200);
}
})
})

describe('test cases for generating routes', ()=>{
it('Should share routes when asked to share routes.', async () => {
const ask = "Can you get routes from Denver to Yellowstone national park?";
const response = await request(app).post('/webhook').send({
"From": process.env.TEST_RECEPIENT_NUMBER,
"Body": ask
})
logger.info(JSON.stringify(response.text, null, 2));
expect(response.status).to.be.eq(200)

})

it('Should come back asking for more details.', async () => {
const ask = "Can you get routes to Yellowstone national park?";
const response = await request(app).post('/webhook').send({
"From": process.env.TEST_RECEPIENT_NUMBER,
"Body": ask
})
logger.info(response.text);
expect(response.status).to.be.eq(200)

})
})

describe('test cases for generating routes and selecting a route', ()=>{

it('Should share routes when asked to share routes.', async () => {
const ask = "Can you get routes from Denver to Yellowstone national park?";
const response = await request(app).post('/webhook').send({
"From": process.env.TEST_RECEPIENT_NUMBER,
"Body": ask
})
logger.info(JSON.stringify(response.text, null, 2));
expect(response.status).to.be.eq(200)

})

it('Should share routes when asked to share routes.', async () => {
const ask = "Lets select the first one.";
const response = await request(app).post('/webhook').send({
"From": process.env.TEST_RECEPIENT_NUMBER,
"Body": ask
})
logger.info(JSON.stringify(response.text, null, 2));
expect(response.status).to.be.eq(200)

})


})
48 changes: 1 addition & 47 deletions tests/unit/controllers/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const expect = chai.expect
const mapService = new MapsService()
const ai = new AI();
const actionsService = new ActionService()
import request from 'supertest'
import app from '../../../server.js'

describe.only('Test cases for AI', () => {
it('Should return message with location polygon', async () => {
Expand Down Expand Up @@ -151,50 +149,6 @@ describe.only('Test cases for Google maps', () => {
const route_image = `https://maps.googleapis.com/maps/api/staticmap?size=300x300${polygon_path}${markers_path}&key=${process.env.GOOGLE_MAPS_API_KEY}`;
logger.info(`route_image: ${route_image}`);
expect(routes).to.be.an('array');
})

it('It should share a set of routes when given an instruction.', async () => {
const ask = "Can you plan a trip from Denver to Yellowstone national park?";

// generate routes
const routesResponse = await mapService.generate_routes(ask);
expect(routesResponse).to.have.property('status');
expect(routesResponse).to.have.property('data');
expect(routesResponse.status).to.be.true;
expect(routesResponse.data.routes).to.be.an('array').that.is.not.empty;
})

it('It should ask for details when given an incomplete instruction.', async () => {
const ask = "Can you plan a trip to Yellowstone national park?";

// generate routes
const routesResponse = await mapService.generate_routes(ask);
expect(routesResponse).to.have.property('status');
expect(routesResponse).to.have.property('errors');
expect(routesResponse.status).to.be.false;
expect(routesResponse.errors).to.be.an('array').that.is.not.empty;
})

it('Should share routes when asked to share routes.', async () => {
const ask = "Can you get routes from Denver to Yellowstone national park?";
const response = await request(app).post('/webhook').send({
"From": process.env.TEST_RECEPIENT_NUMBER,
"Body": ask
})
logger.info(JSON.stringify(response.text, null, 2));
expect(response.status).to.be.eq(200)

})

it('Should come back asking for more details.', async () => {
const ask = "Can you get routes to Yellowstone national park?";
const response = await request(app).post('/webhook').send({
"From": process.env.TEST_RECEPIENT_NUMBER,
"Body": ask
})
logger.info(response.text);
expect(response.status).to.be.eq(200)

})
})
})

0 comments on commit fcae920

Please sign in to comment.