[英]Run mysql query through Wit.ai
在将Wit.ai集成到网站中时,是否有某种方法可以执行数据库查询,因为必须从数据库中获取用户问题的答案,而无法对Chatbot进行培训。
as you see in the tutorial you define actions in wit.ai, those actions can involve variables who can be send as a response to the users. 正如您在教程中看到的那样,您在wit.ai中定义了操作,这些操作可能涉及可以作为对用户的响应发送的变量。 So, you should make the query to the database in the actions defined by you, if you haven't defined them, then do it, because there is where you can make your logic happens.
因此,您应该在您定义的操作中对数据库进行查询,如果您尚未定义它们,那么请执行此操作,因为您可以在其中进行逻辑运算。 Also, take into account that you may handle non synchronized petitions to your database, then you should implement a block mechanism to return the context in each action just after you have done you're query.
此外,考虑到您可以处理数据库的非同步请求,然后您应该实现一个块机制,以便在您完成查询后立即返回每个操作中的上下文。
I know you want to make an implementation in python, but I already have an implementation on node.js, so here is my sample code. 我知道你想在python中实现一个实现,但是我已经在node.js上有了一个实现,所以这是我的示例代码。
getFullName({sessionId, context, entities}) {
let session;
let fbid = sessionId.split("-")[0];
return fbTypingOn(fbid)
.then(() => {
return model.getSesion(fbid);
})
.then(sesion => {
session = sesion;
return callFbUserAPI(session);
})
.then(first_name => {
session.context.fullNameGreeting = utilsBot.buildGreeting(session);
return model.setSesion(session);
})
.then( sesion => {
return session.context;
})
.catch( error => {
console.log("Error in getFullName " + error);
session.context.fullNameGreeting = "Hola";
return context;
});
}
Make sure you read all documentation in the official page, because if there isn't something, then you should do it. 请务必阅读官方页面中的所有文档,因为如果没有,那么您应该这样做。 Also, there's already an implementation in python 2, I guess.
另外,我猜想已经在python 2中实现了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.