我在對話服務中創建了示例培訓數據,現在我正在嘗試爲該服務創建一個後調用使用節點js來創建一個聊天應用程序。我創建了一個後期調用,它正在工作,但並不如預期的那樣。它給了我任何調用的默認響應。爲什麼當我在節點j中創建了一個post調用時,Watson對話對於任何請求都返回相同的默認響應
我開始知道我們需要傳遞我們在響應中獲得的上下文值以進行下一次調用,但不知道該怎麼做。有人可以幫助我。下面是我的代碼
var express = require('express');
var conversationV1 = require('watson-developer-cloud/conversation/v1');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: false
}));
var conversation = new conversationV1({
username: 'xxxxxx-1a06-4a90-xxxxx-xxxxxxxxxxx',
password: 'xxxxxxxxxx',
version_date: conversationV1.VERSION_DATE_2016_09_20
});
const updateMessage = (input, response) => {
var responseText = null;
if (!response.output) {
response.output = {};
} else {
return response;
}
if (response.intents && response.intents[0]) {
var intent = response.intents[0];
if (intent.confidence >= 0.75) {
responseText = 'I understood your intent was ' + intent.intent;
} else if (intent.confidence >= 0.5) {
responseText = 'I think your intent was ' + intent.intent;
} else {
responseText = 'I did not understand your intent';
}
}
response.output.text = responseText;
return response;
};
app.post('/api/message', (req, res, next) => {
const workspace = '254654de-2bfe-423a-92ec-6aa66620625a';
if (!workspace || workspace === '<workspace-id>') {
return res.json({
output: {
text: 'Please check the workspace'
}
});
}
const payload = {
workspace_id: workspace,
input: req.body.input || {},
context: req.body.context || {}
};
// Send the input to the conversation service
conversation.message(payload, (error, data) => {
if (error) {
return next(error);
}
return res.json(updateMessage(payload, data));
});
});
app.listen(process.env.PORT || 3000);
exports.app = app
有人可以幫助我,我們如何可以通過上下文,使其work..Can有人help.U可以運行在您的本地測試代碼。
這只是對話的一個副本 - 簡單嗎?所以它應該可以開箱即用。我會建議您查看對話ID不會更改。如果是這樣,那麼問題與您的應用程序。如果沒有,那麼問題在於對話,所以你需要在那裏調試。 –
@ SimonO'Doherty對話標識每次都會更改 – user7350714
如果您更改了任何對話簡單應用程序,請在此處查看。您發佈的內容不夠用。 –