简体   繁体   English

Python 与 Wit.ai 集成

[英]Python integration with Wit.ai

I am new to Wit.ai and I am trying to make a chatbot.我是 Wit.ai 的新手,我正在尝试制作一个聊天机器人。 This is the chatbot straight from the quickstart.这是直接来自快速入门的聊天机器人。 What am I doing wrong?我究竟做错了什么?

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')

I would like to execute the functions set_temperature and get_temperature.我想执行 set_temperature 和 get_temperature 函数。

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'}

Instead of {'_text': 'make the temperature 45', 'entities': {'intent': [{'confidence': 0.986478544826, 'value': 'set_temperature'}]}, 'WARNING': 'DEPRECATED', 'msg_id': '1CyIOWaEfapF9bbh0'} I'd like hi to be printed.而不是{'_text': 'make the temperature 45', 'entities': {'intent': [{'confidence': 0.986478544826, 'value': 'set_temperature'}]}, 'WARNING': 'DEPRECATED', 'msg_id': '1CyIOWaEfapF9bbh0'}我想打印你好。 Thanks!谢谢!

If I understood correctly what you want:如果我理解正确你想要什么:

def interactive(self, handle_message=None, context=None) I would say you can put your desired messages when starting the interactive conversation with your bot def interactive(self, handle_message=None, context=None)我想说你可以在开始与你的机器人进行交互式对话时输入你想要的消息


client.interactive(handle_message = "I will handle the temperature")

If you want to customise your message using some functions, you can do something like this:如果您想使用某些功能自定义消息,可以执行以下操作:


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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM