Introducing the BOT framework Minette for Python

I couldn't find the de facto standard chatbot framework for Python, so I made one.

Minette for Python https://github.com/uezo/minette-python

5 features

1. Move immediately

You can install it with the pip command, write just a few lines of code, and the bot will work without any database or application server settings.

2. All channels with a unified architecture

Includes adapters for LINE and Clova. You can develop LINE BOT and Clova skills immediately by adding initialization code. In addition, the user-implemented part is not affected by the difference in channels, so development can proceed in the same procedure for both.

3. Context user management and task scheduler are standard equipment

Sessions (contexts) can be used across remarks to realize context-aware dialogue scenarios. In addition, the acquisition and storage of user information is automatically performed without the developer being aware of it. Furthermore, since it has a task scheduler for automating regular processing, it can be completed with the resources of the BOT application without setting cron or the like.

4. Support for natural language analysis (morphological analysis)

If you have MeCab installed, you can automatically morphologically analyze the user's utterance and receive the result. It also supports Janome, which is pure Python, and can also support cloud services such as Google Cloud Platform by extending it by itself, so it is possible to realize advanced dialogue using natural language analysis in any environment. I will.

5. Multi-skill / multi-character structure

We are developing and operating a LINE BOT called Ito BOT, which has more than 10 types of skills (functions), and the know-how cultivated here is reflected in the architecture.

Installation

$ pip install minette

This is OK with one shot. The latest version under development can be installed from the following.

$ pip install git+https://github.com/uezo/minette-python

Creation of Echolalia BOT

After starting the chatbot itself, throw the user's utterance and a response will be returned.

echo.py


from minette import Minette, EchoDialogService

#Start Minette using the Echolalia part (EchoDialogService)
bot = Minette(default_dialog_service=EchoDialogService)

#Start dialogue
while True:
    req = input("user> ")
    res = bot.chat(req)
    for message in res.messages:
        print("minette> " + message.text)
$ python echo.py
user>Hello
minette> You said:Hello
user>Is it working?
minette> You said:Is it working?

Very easy.

Create custom skills

Next time, as a custom skill, I will make a BOT that rolls two dice no matter what.

dice.py


import random
from minette import Minette, DialogService


#Custom interactive parts
class DiceDialogService(DialogService):
    #Process logic and store results in context
    def process_request(self, request, context, connection):
        context.data = {
            "dice1": random.randint(1, 6),
            "dice2": random.randint(1, 6)
        }

    #Assemble response data using contextual information
    def compose_response(self, request, context, connection):
        return "Dice1:{} / Dice2:{}".format(
            str(context.data["dice1"]), str(context.data["dice2"]))


if __name__ == "__main__":
    #Start BOT
    bot = Minette(default_dialog_service=DiceDialogService)
    #Start dialogue
    while True:
        req = input("user> ")
        res = bot.chat(req)
        for message in res.messages:
            print("minette> " + message.text)

Execution result


$ python dice.py
user> test
minette> Dice1:3 / Dice2:5
user> d
minette> Dice1:4 / Dice2:3

Briefly, process_request finds two random numbers from 1 to 6 and stores them in context.data with the keys dice1 and dice2, respectively. compose_response extracts those values and creates a response statement.

I would like to put all the processing of this level into compose_response, but by separating the skill (function) and the character (personality), maintainability can be maintained even in a complicated dialogue scenario. We recommend that you keep them separate.

Also, by passing DiceDialogService as the argument default_dialog_service in the BOT generation process (Minette), when BOT is executed, the process will be passed to the part implemented this time.

Other samples

Please refer to the README on Github for a code example of the translated BOT. https://github.com/uezo/minette-python

Minette architecture

For BOT development using Minette, let's check the overall architecture diagram to see what the developer should do specifically.

Architecture

Basically, the core of development work is to implement the following four methods.

--register_intents () Set the dialogue part (DialogService) to be called according to the utterance intention (intent). --ʻExtract_intent () Extract intents and entities from utterances -- process_request () Application logic processing -- compose_response () `Assemble the response message

Related posts

-Create a LINE BOT with Minette for Python (LINE integration, use chat API) -Make a LINE BOT with Raspberry Pi Zero W

Recommended Posts

Introducing the BOT framework Minette for Python
Launch the Discord Python bot for 24 hours.
Create a LINE BOT with Minette for Python
Create a Twitter BOT with the GoogleAppEngine SDK for Python
See python for the first time
What is the python underscore (_) for?
Command for the current directory Python
I made a scaffolding tool for the Python web framework Bottle
Python Master RTA for the time being
MongoDB for the first time in Python
Introducing the addModuleCleanup / doModuleCleanups function for unittest
Pandas of the beginner, by the beginner, for the beginner [Python]
I tried the Python Tornado Testing Framework
2016-10-30 else for Python3> for:
python [for myself]
The fastest way for beginners to master Python
[Python] I tried substituting the function name for the function name
The story of low learning costs for Python
Created a Python wrapper for the Qiita API
vprof --I tried using the profiler for Python
[Python] matplotlib: Format the diagram for your dissertation
Wagtail is the best CMS for Python! (Perhaps)
Upgrade the Azure Machine Learning SDK for Python
Use logger with Python for the time being
I tried python programming for the first time.
Try using the Python web framework Tornado Part 1
Tips for hitting the ATND API in Python
Python: Prepare a serializer for the class instance:
[Python] I searched for the longest Pokemon Shiritori
Image processing? The story of starting Python for
Use the Python framework "cocotb" to test Verilog.
[Python] Predict the appropriate rent for an apartment
Code for checking the operation of Python Matplotlib
Try using the Python web framework Tornado Part 2
Call Polly from the AWS SDK for Python
Knowledge notes needed to understand the Python framework
Learning notes for the migrations feature in the Django framework (2)
[Trainer's Recipe] I touched the flame of the Python framework.
What I got into Python for the first time
I tried Python on Mac for the first time.
Around the installation of the Python project management framework Trac
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
[Python] Measures and displays the time required for processing
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 1 ~
HoloViews may become the standard for Python visualization tools
I tried python on heroku for the first time
Information for controlling the motor with Python on RaspberryPi
Electron is the best solution for Python multi-platform development
Learning notes for the migrations feature in the Django framework (3)
Python program that looks for the same file name
[For play] Let's make Yubaba a LINE Bot (Python)
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 2 ~
Learning notes for the migrations feature in the Django framework (1)
python memo (for myself): About the development environment virtualenv
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 3 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 4 ~
[CRUD] [Django] Create a CRUD site using the Python framework Django ~ 5 ~
About Python for loops
Find the maximum Python
Django python web framework
Python basics ② for statement