首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python与Wit.ai的集成

Python与Wit.ai的集成
EN

Stack Overflow用户
提问于 2020-05-21 03:49:39
回答 1查看 211关注 0票数 0

我是Wit.ai的新手,我正在尝试制作一个聊天机器人。这是直接从快速入门开始的聊天机器人。我做错了什么?

代码语言:javascript
复制
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import sys
from wit import Wit

if len(sys.argv) != 2:
    print('usage: python ' + sys.argv[0] + ' <wit-token>')
    exit(1)
access_token = sys.argv[1]

client = Wit(access_token=access_token)
client.interactive()

def set_temperature(temp):
    print('hi')

def get_temperature():
    print('bye')

我想执行函数set_temperature和get_temperature。

代码语言:javascript
复制
python3 wit_test.py IG3OBYOAQJJPDCQFNLPVVXDCM6TS5ZPN
> make the temperature 45                                                       
{'_text': 'make the temperature 45', 'entities': {'intent': [{'confidence': 0.986478544826, 'value': 'set_temperature'}]}, 'WARNING': 'DEPRECATED', 'msg_id': '1CyIOWaEfapF9bbh0'}
> what is the temperature                                                       
{'_text': 'what is the temperature', 'entities': {'intent': [{'confidence': 0.98791564105294, 'value': 'get_temperature'}]}, 'WARNING': 'DEPRECATED', 'msg_id': '1qPNFDlSmECpUN8UG'}

我希望打印的不是{'_text': 'make the temperature 45', 'entities': {'intent': [{'confidence': 0.986478544826, 'value': 'set_temperature'}]}, 'WARNING': 'DEPRECATED', 'msg_id': '1CyIOWaEfapF9bbh0'},而是hi。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-21 04:07:09

如果我没弄错你想要什么:

def interactive(self, handle_message=None, context=None)我想说的是,你可以在开始与机器人的互动对话时输入你想要的信息

代码语言:javascript
复制
client.interactive(handle_message = "I will handle the temperature")

如果你想使用一些函数定制你的消息,你可以这样做:

代码语言:javascript
复制
def set_temperature(temp, msg):
    return "{0} I am setting the temperature to {1}".format(msg,temp)

client.interactive(handle_message = set_temperature("hi",25))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61921691

复制
相关文章

相似问题

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