Exemplo n.º 1
0
def test_chat_with_tagger_no_parse():
    bot = Minette(
        default_dialog_service=TaggerDialog,
        tagger=JanomeTagger, tagger_max_length=0)
    assert bot.tagger.max_length == 0
    res = bot.chat("今日はいい天気です。")
    assert res.messages[0].text == "今日はいい天気です。"
    words = res.messages[0].payloads[0].content
    assert words == []
Exemplo n.º 2
0
def test_chat_with_tagger():
    bot = Minette(
        default_dialog_service=TaggerDialog,
        tagger=JanomeTagger)
    res = bot.chat("今日はいい天気です。")
    assert res.messages[0].text == "今日はいい天気です。"
    words = res.messages[0].payloads[0].content
    assert words[0].surface == "今日"
    assert words[1].surface == "は"
    assert words[2].surface == "いい"
    assert words[3].surface == "天気"
    assert words[4].surface == "です"
Exemplo n.º 3
0
def test_chat_parse_morph_manually():
    bot = Minette(
        default_dialog_service=TaggerManuallyParseDialog,
        tagger=JanomeTagger, tagger_max_length=0)
    bot.dialog_uses(tagger=bot.tagger)
    res = bot.chat("今日はいい天気です。")
    assert res.messages[0].text == "今日はいい天気です。"
    words = res.messages[0].payloads[0].content
    assert words[0].surface == "今日"
    assert words[1].surface == "は"
    assert words[2].surface == "いい"
    assert words[3].surface == "天気"
    assert words[4].surface == "です"
Exemplo n.º 4
0
def test_chat_parse_morph_manually_generator():
    bot = Minette(
        default_dialog_service=TaggerManuallyParseGeneratorDialog,
        tagger=JanomeTagger, tagger_max_length=0)
    bot.dialog_uses(tagger=bot.tagger)
    res = bot.chat("今日はいい天気です。")
    assert res.messages[0].text == "今日はいい天気です。"
    assert isinstance(res.messages[0].payloads[0].content, GeneratorType)
    words = [w for w in res.messages[0].payloads[0].content]
    assert words[0].surface == "今日"
    assert words[1].surface == "は"
    assert words[2].surface == "いい"
    assert words[3].surface == "天気"
    assert words[4].surface == "です"
Exemplo n.º 5
0
"""
import random
from minette import Minette, DialogService


# Custom dialog service
class DiceDialogService(DialogService):
    # Process logic and build context data
    def process_request(self, request, context, connection):
        context.data = {
            "dice1": random.randint(1, 6),
            "dice2": random.randint(1, 6)
        }

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


if __name__ == "__main__":
    # Create bot
    bot = Minette(default_dialog_service=DiceDialogService)
    # Start conversation
    while True:
        req = input("user> ")
        res = bot.chat(req)
        for message in res.messages:
            print("minette> " + message.text)
Exemplo n.º 6
0
def test_chat_timezone():
    bot = Minette(default_dialog_service=MyDialog, timezone=timezone("Asia/Tokyo"))
    res = bot.chat("hello")
    # bot.timezone itself is +9:19
    assert res.messages[0].timestamp.tzinfo == datetime.now(tz=bot.timezone).tzinfo
Exemplo n.º 7
0
def test_chat_dialog_error():
    bot = Minette(default_dialog_service=ErrorDialog)
    res = bot.chat("hello")
    assert res.messages[0].text == "?"
Exemplo n.º 8
0
def test_chat_messagelog_error():
    bot = Minette(default_dialog_service=MyDialog)
    bot.messagelog_store = None
    res = bot.chat("hello")
    assert res.messages[0].text == "res:hello"
Exemplo n.º 9
0
def test_chat_error():
    bot = Minette(default_dialog_service=MyDialog)
    bot.connection_provider = None
    res = bot.chat("hello")
    assert res.messages == []
Exemplo n.º 10
0
def test_chat():
    bot = Minette(default_dialog_service=MyDialog)
    res = bot.chat("hello")
    assert res.messages[0].text == "res:hello"