watson-developer-cloud / assistant-with-discovery-openwhisk

DEPRECATED: this repo is no longer actively maintained
Apache License 2.0
21 stars 43 forks source link

Response of Discovery service is not optimized #51

Closed AlaGarali closed 6 years ago

AlaGarali commented 6 years ago

I'm trying to build Customer Support Agent with Watson Conversation and Discovery Service and uploading FAQs documents (.docx, .pdf, .html) to Discovery service.

I would like to know, how can I have the right answer of a question asked, from documents (html, docx, pdf, ...) uploaded on discovery service ? How can I configure discovery service or discovery.query (){} to return the best answer of user's question ? Should I use another service such as WKS or not ? Please find below my discovery.js file code:

     function sendToDiscovery(query) {
      return new Promise(function(resolve, reject) {
        var DiscoveryV1 = require('watson-developer-cloud/discovery/v1');

        var discovery = new DiscoveryV1({
          username: process.env.DISCOVERY_USERNAME,
          password: process.env.DISCOVERY_PASSWORD,
          version_date: '2018-03-05'
        });

        var environment_id = process.env.ENVIRONMENT_ID;
        var collection_id = process.env.COLLECTION_ID;
        var params = {query: query,
            //natural_language_query: query
            //filter: score>0.8,
            highlight: true,
            passages_count: 1,
            passages: true,
            return_fields: ['text'],
            count:1,
            return: 'text'
            //aggregation:
            //'[term(enriched_text.entities.text).term(enriched_text.sentiment.document.label),' +
            //'term(enriched_text.categories.label).term(enriched_text.sentiment.document.label),' +
            //'term(enriched_text.concepts.text).term(enriched_text.sentiment.document.label),' +
            //'term(enriched_text.keywords.text).term(enriched_text.sentiment.document.label),' +
            //'term(enriched_text.entities.type).term(enriched_text.sentiment.document.label)]'
        }
        discovery.query({
          environment_id: environment_id,
          collection_id: collection_id,
          configuration_id: process.env.DISCOVERY_CONFIGURATION_ID,
          query : params
        }, function(error, response) {
            if (error) {
              reject(error);
            } else {
              if (response.results == null) {
                console.log("The call to the Discovery service is complete, but he has not returned any replies. Check the format of the data injected into the Discovery service.");
                reject(error);
              } else {
                console.log(response.results[0].text);
                resolve(response.results[0].text);
              }
            }
        });
      });
    }
    module.exports = sendToDiscovery;

Could you help me please ?

Best regards.

germanattanasio commented 6 years ago

@AlaGarali I don't think there is a way to return an answer directly from Discovery. Discovery will provide the document where the answer is but it's up to you to work on how to "from a collection of sentences in a document" create the response for the user.

I'm closing this because you are not having a problem, with this code.

I recommend you post this question in the Watson dWanswers forum: https://developer.ibm.com/answers/topics/watson/