zoukankan      html  css  js  c++  java
  • ChatterBot

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

    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对象。

  • 相关阅读:
    httpwebrequest详解【转】
    javascript中event.keycode大全
    public void Delete<T>(List<T> EntityList) where T : class, new() 这是什么意思
    Vue(基础五)_vue中用ref和给dom添加事件的特殊情况
    Vue(基础四)_总结五种父子组件之间的通信方式
    Vue(基础三)_监听器与计算属性
    vue(基础二)_组件,过滤器,具名插槽
    vue(基础一)_基本指令的使用
    JS(基础)_总结获取页面中元素和节点的方式
    node.js(node.js+mongoose小案例)_实现简单的注册登录退出
  • 原文地址:https://www.cnblogs.com/zhuhc/p/7806603.html
Copyright © 2011-2022 走看看