gpt4 book ai didi

javascript - 我在命令提示符下从 MySQL 获取值。但是这些值如何在聊天机器人中显示呢?

转载 作者:行者123 更新时间:2023-11-29 16:06:08 25 4
gpt4 key购买 nike

我正在使用 IbmWatson 创建一个聊天机器人。当用户向我的聊天机器人询问某些产品的成本时,这些值来自 MySQL 服务器。我完成了所有设置并获得了值。但该值显示在命令提示符中,而不是聊天机器人中。

如何在聊天机器人中显示值。

我正在使用 Node.js

我正在尝试这段代码:

  function updateMessage(input, response){

var responseText = null;
if (response.intents && response.intents[0]) {

var intent = response.intents[0];
if (intent.intent==='Sales-1'){
var rsp = con.query("SELECT Mobiles from Salestb", function (err,
result, fields) {
if (err) throw err;
console.log(result);
result.forEach( (row) => {
console.log(`${row.Mobiles}`);

});

});


response.output.text = "This is the modified Output :"+ rsp;
} }

我正在尝试上面的代码来获取命令提示符中的值:

[ RowDataPacket { Mobiles: '2,894,564' } ]

2,894,564

在聊天机器人中:这是修改后的输出:[object Object]

值以对象格式显示。但我想要显示值。如何解决这个问题?

最佳答案

您在命令提示符中获得输出,因为 yopu 使用 console.log:

console.log(`${row.Mobiles}`);

您应该将响应更改为:

response.output.text = "This is the modified Output :"+ ${row.Mobiles};  

编辑像这样将你的查询函数放入

function updateMessage(input, response){

var responseText = null;
if (response.intents && response.intents[0]) {

var intent = response.intents[0];
if (intent.intent==='Sales-1'){
var rsp = con.query("SELECT Mobiles from Salestb", function (err,result, fields) {
if (err) throw err;
console.log(result);
result.forEach( (row) => {
console.log(`${row.Mobiles}`);
});
response.output.text = "This is the modified Output :"+ ${row.Mobiles};
});
}
}
}

关于javascript - 我在命令提示符下从 MySQL 获取值。但是这些值如何在聊天机器人中显示呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55725771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com