示例#1
0
class BotServer:
    def __init__(self, cache_path='cache.json'):
        self.bot = Bot()
        self.cache = {}
        self.cache_path = cache_path
        if os.path.exists(cache_path):
            self.cache = load_json(cache_path)
            logger.info("use cache, cache file: %s" % cache_path)

    def answer(self, query):
        if query in self.cache:
            response = self.cache[query]
        else:
            response = self.bot.answer(query)
            self.cache[query] = response
            if self.cache_path:
                save_json(self.cache, self.cache_path)
                logger.info("save cache.")
        return response
示例#2
0
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description: 
"""
import sys

sys.path.append('..')
from dialogbot import Bot

bot = Bot()

msgs = [
    '北京天气?',
    '上海的呢?',
    '明天晚上能发出来吗?',
    '有5元的东西吗? 哪种口味好吃',
    '这个金额是否达到包邮条件',
    '好的谢谢哦。',
    '好的谢了',
    '姚明多高?',
    '长城哪一年开始修的?',
]
for msg in msgs:
    response = bot.answer(msg, use_task=True)
    print("query:", msg)
    print("response:", response)
示例#3
0
文件: base.py 项目: xyyhcl/dialogbot
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description: 
"""
import sys

sys.path.append('..')
from dialogbot import Bot
bot = Bot()

if __name__ == "__main__":
    print(bot.answer('这车怎么卖?'))
示例#4
0
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description: 
"""
import sys

import torch

sys.path.append('..')
from dialogbot import Bot

if __name__ == '__main__':
    bot = Bot()
    response = bot.answer('姚明多高?')
    print(response)
示例#5
0
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description:  test seq2seq model
"""

import sys

sys.path.append('..')

from dialogbot import GPTBot
from dialogbot import Bot

if __name__ == '__main__':
    bot = Bot()
    response = bot.answer('亲 你吃了吗?',
                          use_gen=True,
                          use_search=False,
                          use_task=False)
    print(response)

    # 具体的指定GPT2生成对话模型
    bot = GPTBot()
    msgs = [
        '你吃了吗?', '明天晚上能发出来吗?', '有5元 的 东西 吗? 哪种口味好吃', '这个金额是否达到包邮条件?', '好的谢谢哦。',
        '好的谢了', '你好苹果怎么卖?'
    ]
    for msg in msgs:
        r = bot.answer(msg)
        print('gpt2', msg, r)
示例#6
0
# -*- coding: utf-8 -*-
"""
@author:XuMing([email protected])
@description: 
"""

import sys

sys.path.append('..')
from dialogbot import Bot

if __name__ == '__main__':
    bot = Bot()
    msgs = [
        '亲 吃了吗',
        '雅阁车二手卖多少钱?',
        '北京天气?',
        '上海的天气呢',
        '明天晚上能发出来吗?',
        '有5元的东西吗? 哪种口味好吃',
        '这个金额是否达到包邮条件',
        '好的谢谢哦。',
        '姚明多高?',
        '长城哪一年开始修的?',
    ]
    for msg in msgs:
        print("query:", msg)
        response = bot.answer(msg)
        print("response:", response)