简体   繁体   English

通过Wit.ai运行mysql查询

[英]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.

相关问题 设置wit.ai语音API的录制时间 - Set recording time for wit.ai speech API 如何在wit.ai中从“机器人发送”中提取实体 - How to extract entities from 'bot sends' in wit.ai 通过pymysql执行查询未返回与在MySQL中运行相同的结果 - Executing query through pymysql not returning the same results as running in MySQL 如何使用pymysql通过存储过程将pyodbc mssql查询返回的列表插入到mysql中 - How can I insert a list returned from pyodbc mssql query into mysql through stored procedure using pymysql 通过TCP套接字将MySQL选择查询的结果从PHP发送到Python - Sending result of mysql select query from php to python through a tcp socket PyQt5 Python:如何 go 通过来自 Z62A004B9591DCCA7AZ 查询结果的单个行的数据 - PyQt5 Python: How to go through Individual Row of Data from MySQL Query Result 通过Python运行TreeTagger - run TreeTagger through Python 如何让 Django 对我的 MySql 5.7 db 运行不区分大小写的查询? - How do I get Django to run a case-insensitive query against my MySql 5.7 db? For 循环遍历元组 A 并增加元组 Ai 给定大小 N 到可迭代的 Ni - For loop through tuple A and increace tuple Ai given size N to Ni of iterable Python 3和mysql通过SQLAlchemy - Python 3 and mysql through SQLAlchemy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM