witai.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:opsdroid 作者: opsdroid 项目源码 文件源码
def parse_witai(opsdroid, message, config):
    """Parse a message against all witai skills."""
    matched_skills = []
    if 'access-token' in config:
        try:
            result = await call_witai(message, config)
        except aiohttp.ClientOSError:
            _LOGGER.error("No response from wit.ai, check your network.")
            return matched_skills

        if 'code' in result:
            _LOGGER.error("wit.ai error - %s %s", str(result['code']),
                          str(result['error']))
            return matched_skills
        elif result['entities'] == {}:
            _LOGGER.error("wit.ai error - No intent found. Did you "
                          "forget to create one?")
            return matched_skills

        try:
            confidence = result['entities']['intent'][0]['confidence']
        except KeyError:
            confidence = 0.0
        if "min-score" in config and confidence < config['min-score']:
            _LOGGER.info("wit.ai score lower than min-score")
            return matched_skills

        if result:
            for skill in opsdroid.skills:
                if "witai_intent" in skill:
                    if (skill['witai_intent'] in
                            [i['value'] for i in
                             result['entities']['intent']]):
                        message.witai = result
                        matched_skills.append({
                            "score": confidence,
                            "skill": skill["skill"],
                            "config": skill["config"],
                            "message": message
                        })
    return matched_skills
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号