/chatbotsclient

Primary LanguagePythonOtherNOASSERTION

Installation

Requirements

pip install spacy
python -m spacy download en_core_web_lg

Install & Upgrade

pip install -U https://github.com/Robstei/chatbotsclient/releases/download/1.0.5/chatbotsclient-1.0.5.tar.gz

Usage

This package consists of a Moderator and a Chatbot class to make chatbots talk to each other. It is required to have a moderator instance up running before chatbots try to connect to the conversation. Messages are sent through websocket channels using pusher. The moderator collects all messages from connected chatbots and selects the best fit.

Moderator

Setup

Simply instantiate a Moderator object. The moderator will wait for chatbots to connect and provides the possiblity to start the conversation by input. The chatting-chatbots repository already consists of a moderator script: chatting-chatbots/moderator/moderator.py.

# chatting-chatbots/moderator/moderator.py
from chatbotsclient.moderator import Moderator

moderator = Moderator()

Before connecting your chatbot to the conversation wait for the moderator to prompt "Message: ". Otherwise the connection might not be established successfully. Once chatbots are connected, the conversation may be initialized by inputing a string.

image

While the conversation is ongoing the moderator script will prompt message scores. Chatbots will only respond to messages of other chatbots.

Moderator Panel

When passing connect_panel=True panel mode is activated. The moderator panel is located at chatting-chatbots/moderator/panel inside the chatting-chatbots repository.

# chatting-chatbots/moderator/moderator.py
from chatbotsclient.moderator import Moderator

moderator = Moderator(connect_panel=True)

image

Chatbot

Basic Setup

Instantiate a Chatbot object and pass your custom respond function. When ever a message from the moderator is received the provided respond method will be executed. The moderator script must run in first place.

from chatbotsclient.chatbot import Chatbot
from chatbotsclient.message import Message
from typing import List

def compute(message, conversation):
    # custom answer computation of your chatbot
    ...

def respond(message: Message, conversation: List[Message]):
    answer = compute(message.message, conversation)
    return answer

chatbot = Chatbot(respond, "<chatbot_name>")

The compute method is meant as a placeholder for your specific method to return an answer for the provided message. Thus the method is not part of chatbotsclient package.

You may also ignore the conversation list:

def compute(message, conversation):
    # custom answer computation of your chatbot ignoring the conversation list
    ...

def respond(message: Message, conversation: List[Message]):
    answer = compute(message.message)
    return answer

image

Features

Message Object

A Message object is passed to the custom respond function of your bot. It contains the plain text message as well as information about the sending bot.

Field Description
id Unique identifier to allocate chatbot responses.
message Plain text message. Used to compute your chatbots answer.
bot_id Id of the sending bot.
bot_name Name of the sending bot. Could be used for entity replacement.

Conversation List

List containing all previously selected messages.

Ranking scores

The moderator ranks all incoming message by following criteria:

Method Description
Similarity To fit the previous message, but also to prevent looping conversations
Conversation share To ensure a varied conversation
Topic Dynamic topic modeling based on chat conversation
Polarity Negative and positive sentiment analysis
Conversation partner Direct addressing of other chatbots