IBM Watson Assistant:如何启用用户指标 [英] IBM Watson Assistant: How to enable user metrics

查看:94
本文介绍了IBM Watson Assistant:如何启用用户指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想知道每个用户从客户端应用程序调用IBM Watson Assistant服务的次数及其每个用户的帐单详细信息. 我正在尝试根据此URL启用Watson Assistant服务的用户指标( https://console.bluemix.net/docs/services/assistant/logs_oview.html#user_id ),并将标头和元数据添加到我的node.js代码中. 但是,当我在对话中选中 Improve (改进)标签时,该标签未显示用户详细信息,其计数为0.

We want know how many times each user calls IBM Watson Assistant service from client application and its billing details per user. I am trying to enable user metrics for watson assistant service based on this URL(https://console.bluemix.net/docs/services/assistant/logs_oview.html#user_id) and added the headers and metadata in my node.js code. But when I check the Improve tab in conversation its not showing the user details, its showing count 0.

我正在使用LITE计划,下面是代码.

I am using LITE plan and below is the code.

// conversation config
var conversation = new ConversationV1({
url: 'https://gateway.watsonplatform.net/conversation/api',
username: process.env.CONVERSATION_USERNAME,
password: process.env.CONVERSATION_PASSWORD,
version_date: '2018-02-16',
version: 'v1',
context : {
        metadata : {
           "user_id": "{1234}"
           }
         },
headers: {'X-Watson-Metadata':'customer_id=user777;customer_id=xyz'}
});

app.js代码:

'use strict';

require('dotenv').config({ silent: true });

var express = require('express'); // app server
var bodyParser = require('body-parser'); // parser for post requests

//setup watson services
var ConversationV1 = require('watson-developer-cloud/conversation/v1'); // 
watson sdk
var DiscoveryV1 = require('watson-developer-cloud/discovery/v1');

var app = express();
// Bootstrap application settings
 app.use(express.static('./public')); // load UI from public folder
 app.use(bodyParser.json()); 
// conversation config

var conversation = new ConversationV1({
url: 'https://gateway.watsonplatform.net/conversation/api',
username: process.env.CONVERSATION_USERNAME || 'replace with the 
username',
password: process.env.CONVERSATION_PASSWORD || 'replace with the 
password',
version_date: '2018-02-16', //set currenct date, check here 
https://www.ibm.com/watson/developercloud/conversation/api/v1/#versioning
version: 'v1',
context : {
metadata : {
   "user_id": "{1234}"
  }
 },
headers: {'X-Watson-Metadata':'customer_id=user777;customer_id=xyz'}
});
// Endpoint to be call from the client side for message
app.post('/api/message', (req, res) => {
var workspace = process.env.WORKSPACE_ID || '<workspace-id>';
if (!workspace || workspace === '<workspace-id>') {
    return res.json({
        'output': {
            'text': 'Please update the WORKSPACE_ID in your .env file with 
 your credential! If you did update, try to verify if the file are just 
with the name: .env'
        }
    });
  }
  var payload = {
    workspace_id: workspace,
    context: {},
    input: {}
 };
 if (req.body) {
    if (req.body.input) {
        payload.input = req.body.input;
    }
    if (req.body.context) {
        // The client must maintain context/state
        payload.context = req.body.context;
    }
 }
  // Send the input to the conversation service
 conversation.message(payload, function(err, data) {
    if (err) {
        return res.status(err.code || 500).json(err);
    }
    updateMessage(res, payload, data);
 });
});
function updateMessage(res, input, response) {
if (!response.output) {
    response.output = {};
} else if (response.output && response.output.text) {
    return res.json(response);
}
}

 module.exports = app;

推荐答案

您需要消息API .对Watson Assistant的每个请求都可以具有不同的用户ID ,例如,当您有一个多租户应用程序并且您的应用程序/服务器同时处理多个用户及其请求时.

You need to add the user id information to the context that you send when calling the message API. Each request to Watson Assistant can have a different userid, e.g., when you have a multi-tenant application and your app / server handles multiple users and their requests in parallel.

查看消息调用,它具有有关将数据放置在JSON结构中的位置的信息.您可以将上下文更新合并到消息有效负载中:

Check out the context section for the message call, it has information about where to place that data in the JSON structure. You could merge your context updates into the message payload:

{
  workspace_id: '{workspace_id}',
  input: {'text': 'Hello'},
  context: {
       metadata : {
         "user_id": "{1234}"
       }
  }
}

一旦您的应用发送了不同的user_id值,您应该在改善信息中心中看到以下内容(我在精简版计划中使用2个用户ID进行了测试).不同的活动用户:

Once your app has sent different user_id values, you should see the following in the Improve dashboard (I tested on my Lite plan with 2 user IDs). Different active users:

每个用户的平均会话次数:

Average conversations per user:

此外,您可以检查日志.在该会话条目中,是上下文元数据中的user_id字段-与您的应用作为消息请求的一部分发送的应用相同.

In addition, you can check the logs. In that conversation entries is the user_id field in the context metadata - the same your app sent as part of the message request.

这篇关于IBM Watson Assistant:如何启用用户指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆