与Wit.ai的Python集成

问题描述 投票:0回答:1

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

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函数。

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'},我想打个招呼。谢谢!

python chatbot wit.ai
1个回答
1
投票

如果我正确理解了你想要什么:

def interactive(self, handle_message=None, context=None)我想说的是,您可以在与机器人进行互动对话时输入所需的消息


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

如果要使用某些功能来自定义消息,则可以执行以下操作:


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

© www.soinside.com 2019 - 2024. All rights reserved.