ChatterBot - 05 Input Adapters 输入适配器

输入适配器的作用就是从给定的数据源读取数据,并将其转化为机器人能够识别的格式。

1. 变量输入类适配器

chatterbot.input.VariableInputTypeAdapter (***kwargs*)

这个适配器可以接受几种不同类型的输入变量:json、text、object,或者可以说成是:strings、dictionaries、Statements

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.VariableInputTypeAdapter"
)

2. 终端输入适配器

chatterbot.input.TerminalAdapter (***kwargs*)

顾名思义,可以通过终端与机器人交流,该适配器会获取终端的输入,转化给机器人。

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.TerminalAdapter"
)

3. Gitter 输入适配器

chatterbot.input.Gitter (***kwargs*)

链接Gitter的一个房间,可以在该房间与机器人进行交流,该适配器会获取该房间的输入。

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.Gitter",
    gitter_api_token="my-gitter-api-token",
    gitter_room="my-room-name",
    gitter_only_respond_to_mentions=True,
)

4. HipChat 输入适配器

chatterbot.input.HipChat (***kwargs*)

类似Gitter

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.HipChat",
    hipchat_host="https://mydomain.hipchat.com",
    hipchat_room="my-room-name",
    hipchat_access_token="my-hipchat-access-token",
)

5. Mailgun 输入适配器

chatterbot.input.Mailgun (***kwargs*)

通过邮件交流

# -*- coding: utf-8 -*-
from chatterbot import ChatBot
from settings import MAILGUN

'''
To use this example, create a new file called settings.py.
In settings.py define the following:

MAILGUN = {
    "CONSUMER_KEY": "my-mailgun-api-key",
    "API_ENDPOINT": "https://api.mailgun.net/v3/my-domain.com/messages"
}
'''

# Change these to match your own email configuration
FROM_EMAIL = "mailgun@salvius.org"
RECIPIENTS = ["gunthercx@gmail.com"]

bot = ChatBot(
    "Mailgun Example Bot",
    mailgun_from_address=FROM_EMAIL,
    mailgun_api_key=MAILGUN["CONSUMER_KEY"],
    mailgun_api_endpoint=MAILGUN["API_ENDPOINT"],
    mailgun_recipients=RECIPIENTS,
    input_adapter="chatterbot.input.Mailgun",
    output_adapter="chatterbot.output.Mailgun",
    storage_adapter="chatterbot.storage.SQLStorageAdapter",
    database="../database.db"
)

# Send an example email to the address provided
response = bot.get_response("How are you?")
print("Check your inbox at ", RECIPIENTS)

6. 微软机器人平台输入适配器

chatterbot.input.Microsoft (***kwargs*)

chatbot = ChatBot(
    "My ChatterBot",
    input_adapter="chatterbot.input.Microsoft",
    directline_host="https://directline.botframework.com",
    directline_conversation_id="IEyJvnDULgn",
    direct_line_token_or_secret="RCurR_XV9ZA.cwA.BKA.iaJrC8xpy8qbOF5xnR2vtCX7CZj0LdjAPGfiCpg4Fv0",
)

7. 创建自定义输入适配器

创建自定义输入适配器需要继承InputAdapter抽象类,并且实现必要的方法。

chatterbot.input.InputAdapter (***kwargs*)

实现process_input方法,并且返回Statement对象。

转载于:https://www.cnblogs.com/zhuhc/p/7806603.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值