输入适配器的作用就是从给定的数据源读取数据,并将其转化为机器人能够识别的格式。
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
对象。