Skip to content

Commit

Permalink
Merge pull request #71 from beckn/added_direction_url
Browse files Browse the repository at this point in the history
Added missing condition and direction url
  • Loading branch information
mayurvir authored Apr 8, 2024
2 parents fcae920 + 9c452fa commit 6bd07ee
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/openai.json
Original file line number Diff line number Diff line change
@@ -1,7 +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": "select_route", "description": "If the user selects one of the routes from the routes shared 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
19 changes: 19 additions & 0 deletions controllers/Bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,25 @@ async function process_text(req, res) {
session.text.push({ role: 'user', content: message });
session.text.push({ role: 'assistant', content: response.formatted });
}
else if(ai.action?.action === 'select_route'){
const details_response = await ai.get_details_by_description(`Get the index of selected item based this input from user : ${message}`, [], `{index:1}`);
let route_response = {
message: ''
}
if(details_response && details_response.index){
session.selected_route = session.routes[details_response.index];
const url = `https://www.google.com/maps/dir/${session.selected_route.source_gps.lat},${session.selected_route.source_gps.lng}/${session.selected_route.destination_gps.lat},${session.selected_route.destination_gps.lng}/`;
route_response.message = `Your route has been actived. Here is the link to navigate : ${url}. What do you want to do next?`;

}
const formatting_response = await ai.format_response(route_response, [{ role: 'user', content: message },...session.text]);
response.formatted = formatting_response.message;

logger.info(`AI response: ${response.formatted}`);

session.text.push({ role: 'user', content: message });
session.text.push({ role: 'assistant', content: response.formatted });
}
else if(ai.action?.action == null) {

// get ai response
Expand Down
9 changes: 8 additions & 1 deletion services/MapService.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ class MapsService {
}
else{
// generate routes
response.data.routes = await this.getRoutes(source_gps, destination_gps);
const routes = await this.getRoutes(source_gps, destination_gps);
response.data.routes = routes.map(route=>{
return {
...route,
source_gps: source_gps,
destination_gps: destination_gps
}
})
response.data.routes_formatted = {
"description": `these are the various routes that you can take. Which one would you like to select:`,
"routes": response.data.routes.map((route, index) => `Route ${index+1}: ${route.summary}`)
Expand Down
8 changes: 4 additions & 4 deletions tests/apis/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import logger from '../../utils/logger.js'
import DBService from '../../services/DBService.js'
const expect = chai.expect

beforeEach(async () => {
before(async () => {
// Reset all sessions
const db = new DBService()
await db.clear_all_sessions()
Expand Down Expand Up @@ -240,7 +240,7 @@ describe('test cases for generating routes', ()=>{
})
})

describe('test cases for generating routes and selecting a route', ()=>{
describe.only('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?";
Expand All @@ -253,8 +253,8 @@ describe('test cases for generating routes and selecting a route', ()=>{

})

it('Should share routes when asked to share routes.', async () => {
const ask = "Lets select the first one.";
it('should select a route and share directions.', async () => {
const ask = "Lets select the first route.";
const response = await request(app).post('/webhook').send({
"From": process.env.TEST_RECEPIENT_NUMBER,
"Body": ask
Expand Down

0 comments on commit 6bd07ee

Please sign in to comment.