首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wit.ai与python的对话

wit.ai与python的对话
EN

Stack Overflow用户
提问于 2017-04-05 20:03:37
回答 1查看 1.7K关注 0票数 0

我正在使用wit.ai python API创建一个聊天机器人。我希望在这方面使用converse。在这些示例中,它只存在用于逆向的节点示例。有没有人可以帮我举一个使用python进行wit.ai转换的例子。

下面是他们的节点示例。

代码语言:javascript
复制
//Extract an entity value from the entities returned by Wit
const firstEntityValue = (entities, entity) => {
  const val = entities && entities[entity] &&
    Array.isArray(entities[entity]) &&
    entities[entity].length > 0 &&
    entities[entity][0].value
  ;
  if (!val) {
    return null;
  }
  return typeof val === 'object' ? val.value : val;
};

//Define your bot functions here
const actions = {
  send(request, response) {
    const {sessionId, context, entities} = request;
    const {text, quickreplies} = response;
    return new Promise(function(resolve, reject) {
        console.log('user said...', request.text);
        console.log('sending...', JSON.stringify(response));
        return resolve();
    });
  },
  ['compute-result']({context,entities}) {
    return new Promise(function(resolve, reject) {
      const movie_title = firstEntityValue(entities, 'movie');
      if (movie_title) {
        context.movie = movie_title;
      }
      //call the API here
      return resolve(context);
  });
 },
};
EN

回答 1

Stack Overflow用户

发布于 2017-04-22 03:15:33

您可以在https://github.com/wit-ai/pywit/blob/master/examples上查看Wit的python示例,文件joke.py足以了解python的基本工作原理。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43230660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档