From 3fffa315fea3364b6a1511d66df4eeeb1a1a8c87 Mon Sep 17 00:00:00 2001 From: Rajendra Date: Thu, 13 Oct 2016 02:33:04 +0530 Subject: [PATCH 1/2] Implemented Real AI capabilities Implemented Real AI capabilities with the help of api,ai API. --- js/speech.js | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/js/speech.js b/js/speech.js index b8a87aa..081fb7c 100644 --- a/js/speech.js +++ b/js/speech.js @@ -32,12 +32,40 @@ var speechModule = (function () { samaritanModule.showImages(photosURL); }); } - + //Added Real Power of AI - with AI API from api.ai + var accessToken = "Client access token from api.ai";//Please use your own accessToken. + var baseUrl = "https://api.api.ai/v1/"; + var _send = function (phrase) { + console.log('Welcome to Samaritan ASI!'); + console.log('processing send'); + var text = phrase; + $.ajax({ + type: "POST", + url: baseUrl + "query?v=20160910", + contentType: "application/json; charset=utf-8", + dataType: "json", + headers: { + "Authorization": "Bearer " + accessToken + }, + data: JSON.stringify({ q: text, lang: "en" }), + success: function(data) { + var txt = data.result.fulfillment.speech; + samaritanModule.write(txt); + console.log(txt); + }, + error: function() { + samaritanModule.write('Internal Server Error'); + } + }); + samaritanModule.write('...'); + }; + //Added Real Power of AI - Ends Here + var _commands = { 'locate the machine': _writeWrapper('Target can not be reached !'), - 'where are you': _writeWrapper("I am everywhere , i am god"), - 'who am I': _writeWrapper("Asset"), - 'who are you': _writeWrapper('i am samaritan !'), + //'where are you': _writeWrapper("I am everywhere , i am god"),//implemented in AI + 'who am I': _writeWrapper("Admin"), + //'who are you': _writeWrapper('i am samaritan !'),//implemented in AI 'find Finch': _writeWrapper('Locating Harold Finch ?'), 'yes': _writeWrapper('yes what ?'), 'no': _writeWrapper('ok then what is your suggestion ?'), @@ -49,10 +77,8 @@ var speechModule = (function () { 'find (me) *name': _flickrSearch, 'search (for) *name': _flickrSearch, 'show (me) *name': _flickrSearch, - //repeats everything if it's not one of the above - '*phrase': function (phrase) { - samaritanModule.write(phrase); - } + //This is now handled by AI + '*phrase': _send }; //PUBLIC ********************************** From 32ba49d80221ebc03158a703a069a04643bb527a Mon Sep 17 00:00:00 2001 From: Rajendra Date: Thu, 13 Oct 2016 02:38:35 +0530 Subject: [PATCH 2/2] api.ai instructions addedapi.ai instructions --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 564db6b..fa5319a 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -[Samaritan 2.0!](https://rodrigograca31.github.io/Samaritan/) +[Samaritan 2.1!](https://rodrigograca31.github.io/Samaritan/) ========= Features: * Speech recognition * Voice image search +* Added natural language interactions with api.ai (Endless possibilities, refer docs at https://docs.api.ai/) +Demo at https://iocare.dlinkddns.com/Samaritan/ (Ask question related to relations, feelings, vacations, travel, education, hobbies etc) Technologies: * HTML