IBM / watson-discovery-sdu-with-assistant

Build a Node.js chatbot that uses Watson services and webhooks to query an owner's manual
https://developer.ibm.com/learningpaths/get-started-watson-discovery/smart-document-understanding-search-skill/
Apache License 2.0
21 stars 35 forks source link

Hi, How can I set the credentials in .env file to access to Watson Assistant Service in London? #26

Closed Mmalik83 closed 4 years ago

Mmalik83 commented 4 years ago

Hi, How can I set the credentials in .env file to access to Watson Assistant Service in London?

rhagarty commented 4 years ago

@Mmalik83 - try adding the London service URL in your .env file:

ASSISTANT_URL=

You can find the URL on the credentials panel for your Assistant service instance.

Mmalik83 commented 4 years ago

Dear rhagarty

Thank you. It worked. One more thing. The Action code in Function is fetching all information from the discovery, i.e. score, ids, etc. (copied below). How can i only bring passage text. and if i am bringing only 3 passages, how can i bring them only?

{"matching_results":77,"passages":[{"document_id":"1f62c0428fbfa031069fae7b619acdfb_2","end_offset":12,"field":"title","passage_score":16.43179379613475,"passage_text":"Annual Leave","start_offset":0},{"document_id":"1f62c0428fbfa031069fae7b619acdfb_7","end_offset":154,"field":"subtitle","passage_score":10.921512532969782,"passage_text":"No Carryover: 2.4. Emergency Leave and Annual Leave: 2.5.","start_offset":97},{"document_id":"1f62c0428fbfa031069fae7b619acdfb_62","end_offset":38,"field":"subtitle","passage_score":10.921512532969782,"passage_text":"2.4. Emergency Leave and Annual Leave:","start_offset":0}],"results":[{"enriched_text":{"categories":[{"label":"/law, govt and politics","score":0.826077},{"label":"/law, govt and politics/government/government contracting and procurement","score":0.722601},{"label":"/society/work","score":0.707239}],"concepts":[{"dbpedia_resource":"http://dbpedia.org/resource/Leave_of_absence","relevance":0.91136,"text":"Leave of absence"},{"dbpedia_resource":"http://dbpedia.org/resource/Contract","relevance":0.909498,"text":"Contract"},{"dbpedia_resource":"http://dbpedia.org/resource/Emergency","relevance":0.908211,"text":"Emergency"},{"dbpedia_resource":"http://dbpedia.org/resource/Returning","relevance":0.90641,"text":"Returning"},{"dbpedia_resource":"http://dbpedia.org/resource/Entitlement","relevance":0.881577,"text":"Entitlement"},{"dbpedia_resource":"http://dbpedia.org/resource/Leave","relevance":0.8704,"text":"Leave"},{"dbpedia_resource":"http://dbpedia.org/resource/Entitlement_(fair_division)","relevance":0.865193,"text":"Entitlement"},{"dbpedia_resource":"http://dbpedia.org/resource/Employment","relevance":0.861676,"text":"Employment"}],"entities":[{"count":1,"relevance":0.721856,"sentiment":{"label":"neutral","score":0},"text":"Functional Director","type":"JobTitle"},{"count":1,"relevance":0.721856,"sentiment":{"label":"neutral","score":0},"text":"one year","type":"Quantity"},{"count":1,"relevance":0.721856,"sentiment":{"label":"neutral","score":0},"text":"10 days","type":"Quantity"}],"sentiment":{"document":{"label":"negative","score":-0.58501}}},"extracted_metadata":{"author":["Brian.Donaldson"],"file_type":"word","filename":"Chapter 7 - Leave Holidays - Edited Final, March 2018.doc","sha1":"11f117b3a92520963e9368db8aadfeea12017dbd"},"id":"1f62c0428fbfa031069fae7b619acdfb_7","result_metadata":{"confidence":0.26630976417778063,"score":3.2414713},"segment_metadata":{"id":"25062278-fee3-4238-bc32-b7bd4df622ae","parent_id":"1f62c0428fbfa031069fae7b619acdfb","total_segments":9},"subtitle":["1. Purpose","2. Policy 2.1. Permanent Employees:","2.2. Non-permanent Employees: no entitlement 2.3. No Carryover:","2.4. Emergency Leave and Annual Leave:","2.5. Completion of Forms:","3. Procedure 3.1. Employee via Self-service:","3.2. Evidence:","3.3. No Evidence Provided:","3.4. Emergency Leave and Air Tickets:","3.5. No Annual Leave Accrued:","3.6. Emergency Leave Records:"],"text":"The company’s Emer gency Leave policy is intended to assist an employee in emergency situations. Decisions on Emergency Leave will be prompt with no right of appeal. If it becomes apparent that an application is motivated by other than a genuine emergency, the company will take the appropriate disciplinary action. Permanent employees are eligible for Emergency Leave of up to 10 calendar days without pay per contract year. .","title":["Emergency Leave"]},{"enriched_text":{"categories":[{"label":"/education/special education","score":0.997125}],"concepts":[{"dbpedia_resource":"http://dbpedia.org/resource/Medicine","relevance":0.896356,"text":"Medicine"},{"dbpedia_resource":"http://dbpedia.org/resource/Arabic_language","relevance":0.856658,"text":"Arabic language"},{"dbpedia_resource":"http://dbpedia.org/resource/Saudi_Arabia","relevance":0.8188,"text":"Saudi Arabia"},{"dbpedia_resource":"http://dbpedia.org/resource/Management","relevance":0.778482,"text":"Management"},{"dbpedia_resource":"http://dbpedia.org/resource/Sharia","relevance":0.756193,"text":"Sharia"}],"entities":[{"count":1,"relevance":0.797687,"sentiment":{"label":"neutral","score":0},"text":"Saudi Consulate","type":"Organization"},{"count":1,"relevance":0.640201,"sentiment":{"label":"neutral","score":0},"text":"KSA","type":"Organization"},{"count":1,"relevance":0.639198,"sentiment":{"label":"neutral","score":0},"text":"Company Doctor","type":"JobTitle"},{"count":1,"relevance":0.446679,"sentiment":{"label":"neutral","score":0},"text":"Official","type":"JobTitle"}],"sentiment":{"document":{"label":"negative","score":-0.913835}}},"extracted_metadata":{"author":["Brian.Donaldson"],"file_type":"word","filename":"Chapter 7 - Leave Holidays - Edited Final, March 2018.doc","sha1":"11f117b3a92520963e9368db8aadfeea12017dbd"},"id":"1f62c0428fbfa031069fae7b619acdfb_18","result_metadata":{"confidence":0.25957898597694834,"score":3.2029493679663483},"segment_metadata":{"id":"d8525061-398b-4164-8ed8-6eade902d204","parent_id":"1f62c0428fbfa031069fae7b619acdfb","total_segments":77},"subtitle":["2.5. Sickness during Annual Leave:"],"text":"The employee cannot extend leave for the number of days taken as sick absence as it impacts on the management of the functional Leave Plan; the number of sick days will be added to the employee’s annual leave balance"},{"enriched_text":{"categories":[{"label":"/travel/traveling with kids","score":0.991994},{"label":"/society/work","score":0.877221}],"concepts":[{"dbpedia_resource":"http://dbpedia.org/resource/Law","relevance":0.9044,"text":"Law"}],"entities":[{"count":1,"relevance":0.33,"sentiment":{"label":"neutral","score":0},"text":"Saudi Labor Law","type":"Organization"}],"sentiment":{"document":{"label":"neutral","score":0}}},"extracted_metadata":{"author":["Brian.Donaldson"],"file_type":"word","filename":"Chapter 7 - Leave Holidays - Edited Final, March 2018.doc","sha1":"11f117b3a92520963e9368db8aadfeea12017dbd"},"id":"1f62c0428fbfa031069fae7b619acdfb_10","result_metadata":{"confidence":0.29935867272446104,"score":3.0081944949017787},"segment_metadata":{"id":"680c1949-a5fa-4cf3-b329-1bd6c64a7737","parent_id":"1f62c0428fbfa031069fae7b619acdfb","total_segments":77},"subtitle":["1. Policy"],"text":"1.1. To grant employees their annual vacation in compliance with Saudi Labor Law."}],"retrieval_details":{"document_retrieval_strategy":"untrained"},"session_token":"1_TxEjcW91PF6ffvc1_rWjtz6xiG"}

rhagarty commented 4 years ago

@Mmalik83 - all of that additional info (score, ids, etc) is the basic response from Disco. But it's easy enough to ignore by just grabbing the info you are looking for.

Have you tried playing around with the Disco service tooling? You can try to create a query there that gets you the response that you want, and then change the query in https://github.com/IBM/watson-discovery-sdu-with-assistant/blob/master/actions/disco-action.js to match.

Mmalik83 commented 4 years ago

@rhagarty

I have edited the code to add a loop on 'data' to separate 'text' from the passages and return the formatted data. I am new to node.js and scripting. The code gives errors. Is the below code right? or I have to do something else??

/*

const assert = require('assert'); const DiscoveryV1 = require('watson-developer-cloud/discovery/v1');

/*

rhagarty commented 4 years ago

If you are happy with the results from Disco, but just want to customize the data for your UI, you should focus your changes here - https://github.com/IBM/watson-discovery-sdu-with-assistant/blob/master/src/main.js#L84.

Mmalik83 commented 4 years ago

This is in the main.js file. If I want to filter the results in the disco file to return only 'Text' fields from the passages, can't i do that?