Exemple #1
0
def start_alice_server(model_config, https=False, ssl_key=None, ssl_cert=None, port=None):
    server_config_path = get_settings_path() / SERVER_CONFIG_FILENAME
    server_params = get_server_params(server_config_path, model_config)

    https = https or server_params['https']

    if not https:
        ssl_key = ssl_cert = None
    else:
        ssh_key = Path(ssl_key or server_params['https_key_path']).resolve()
        if not ssh_key.is_file():
            e = FileNotFoundError('Ssh key file not found: please provide correct path in --key param or '
                                  'https_key_path param in server configuration file')
            log.error(e)
            raise e

        ssh_cert = Path(ssl_cert or server_params['https_cert_path']).resolve()
        if not ssh_cert.is_file():
            e = FileNotFoundError('Ssh certificate file not found: please provide correct path in --cert param or '
                                  'https_cert_path param in server configuration file')
            log.error(e)
            raise e

    host = server_params['host']
    port = port or server_params['port']
    model_endpoint = server_params['model_endpoint']

    model = build_model(model_config)
    skill = DefaultStatelessSkill(model, lang='ru')
    agent = DefaultAgent([skill], skills_processor=DefaultRichContentWrapper())

    start_agent_server(agent, host, port, model_endpoint, ssl_key, ssl_cert)
Exemple #2
0
    def learn(self, train):
        h = pd.read_csv('./app/database/hello_skill.csv')
        hello = PatternMatchingSkill(responses=[
            x for x in h['responses'].tolist() if x != ' ' and x == x
        ],
                                     patterns=[
                                         x for x in h['patterns'].tolist()
                                         if x != ' ' and x == x
                                     ])

        b = pd.read_csv('./app/database/bye_skill.csv')
        bye = PatternMatchingSkill(responses=[
            x for x in b['responses'].tolist() if x != ' ' and x == x
        ],
                                   patterns=[
                                       x for x in b['patterns'].tolist()
                                       if x != ' ' and x == x
                                   ])

        f = pd.read_csv('./app/database/fallback_skill.csv')
        fallback = PatternMatchingSkill(responses=[
            x for x in f['responses'].tolist() if x != ' ' and x == x
        ],
                                        default_confidence=0.1)
        faq = SimilarityMatchingSkill(data_path=self.DATANAME,
                                      x_col_name='Question',
                                      y_col_name='Answer',
                                      save_load_path=self.MODELNAME,
                                      config_type='tfidf_autofaq',
                                      train=train)

        self.d = DefaultAgent([hello, bye, faq, fallback],
                              skills_selector=HighestConfidenceSelector())
Exemple #3
0
 def get_default_agent():
     model_config = read_json(model_config_path)
     model = build_model_from_config(model_config)
     skill = DefaultStatelessSkill(model)
     agent = DefaultAgent([skill],
                          skills_processor=DefaultRichContentWrapper())
     return agent
 def setup(self):
     # print(configs.aiml_skill)
     config_ref = configs.skills.rasa_skill
     install_from_config(config_ref)
     # rasa_skill = build_model(
     #     "/home/alx/Workspace/DeepPavlov/deeppavlov/configs/aiml_skill/rasa_skill.json",
     #     download=True)
     rasa_skill = build_model(config_ref, download=True)
     self.agent = DefaultAgent([rasa_skill],
                               skills_selector=HighestConfidenceSelector())
Exemple #5
0
def interact_model_by_telegram(config, token=None):
    server_config_path = Path(get_settings_path(), SERVER_CONFIG_FILENAME)
    server_config = read_json(server_config_path)
    token = token if token else server_config['telegram_defaults']['token']
    if not token:
        e = ValueError(
            'Telegram token required: initiate -t param or telegram_defaults/token '
            'in server configuration file')
        log.error(e)
        raise e

    model = build_model(config)
    model_name = type(model.get_main_component()).__name__
    skill = DefaultStatelessSkill(model)
    agent = DefaultAgent([skill], skills_processor=DefaultRichContentWrapper())
    init_bot_for_model(agent, token, model_name)
Exemple #6
0
def make_hello_bot_agent() -> DefaultAgent:
    """Builds agent based on PatternMatchingSkill and HighestConfidenceSelector.

    This is agent building tutorial. You can use this .py file to check how hello-bot agent works.

    Returns:
        agent: Agent capable of handling several simple greetings.
    """
    skill_hello = PatternMatchingSkill(['Hello world'],
                                       patterns=['hi', 'hello', 'good day'])
    skill_bye = PatternMatchingSkill(['Goodbye world', 'See you around'],
                                     patterns=['bye', 'chao', 'see you'])
    skill_fallback = PatternMatchingSkill(
        ['I don\'t understand, sorry', 'I can say "Hello world"'])

    agent = DefaultAgent([skill_hello, skill_bye, skill_fallback],
                         skills_processor=HighestConfidenceSelector())

    return agent
Exemple #7
0
def start_alice_server(model_config_path,
                       https=False,
                       ssl_key=None,
                       ssl_cert=None):
    if not https:
        ssl_key = ssl_cert = None

    server_config_dir = Path(__file__).parent
    server_config_path = server_config_dir.parent / SERVER_CONFIG_FILENAME

    server_params = get_server_params(server_config_path, model_config_path)
    host = server_params['host']
    port = server_params['port']
    model_endpoint = server_params['model_endpoint']

    model = init_model(model_config_path)
    skill = DefaultStatelessSkill(model, lang='ru')
    agent = DefaultAgent([skill], skills_processor=DefaultRichContentWrapper())

    start_agent_server(agent, host, port, model_endpoint, ssl_key, ssl_cert)
 def setup(self):
     config_ref = configs.skills.aiml_skill
     install_from_config(config_ref)
     aiml_skill = build_model(config_ref, download=True)
     self.agent = DefaultAgent([aiml_skill],
                               skills_selector=HighestConfidenceSelector())
 def __post_init__(self):
     self.cells.append(self.fallback)
     skills = [cell.get_pattern_matching_skill() for cell in self.cells]
     self.agent = DefaultAgent(skills)
Exemple #10
0
 def get_default_agent() -> DefaultAgent:
     model = build_model(model_config)
     skill = DefaultStatelessSkill(model) if default_skill_wrap else model
     agent = DefaultAgent([skill],
                          skills_processor=DefaultRichContentWrapper())
     return agent
Exemple #11
0
from deeppavlov.skills.pattern_matching_skill import PatternMatchingSkill
from deeppavlov.agents.default_agent.default_agent import DefaultAgent 
from deeppavlov.agents.processors.highest_confidence_selector import HighestConfidenceSelector

hello = PatternMatchingSkill(responses=['Hello world!'], patterns=["hi", "hello", "good day"])
bye = PatternMatchingSkill(['Goodbye world!', 'See you around'], patterns=["bye", "chao", "see you"])
fallback = PatternMatchingSkill(["I don't understand, sorry", 'I can say "Hello world!"'])

HelloBot = DefaultAgent([hello, bye, fallback], skills_selector=HighestConfidenceSelector())

print(HelloBot(['Hello!', 'Boo...', 'Bye.']))

Exemple #12
0
    responses=['Добро пожаловать', 'Приветствую тебя, друг мой'],
    patterns=['Привет', 'Здравствуйте', 'Здравствуй', 'Здорово', 'Ку'],
    default_confidence=0.01)
bye = PatternMatchingSkill(
    responses=['На этом прощаюсь с тобой', 'Всего доброго'],
    patterns=['До свидания'])
help = PatternMatchingSkill(responses=[
    'Вопрос любой задать мне можешь. Мудрый совет постараюсь я дать.'
],
                            patterns=['Что ты умеешь', 'Помощь'])
welcome = PatternMatchingSkill(responses=[
    'Приветствую тебя, друг мой. Вопрос любой задать мне можешь. Мудрый совет постараюсь я дать.'
],
                               patterns=['^\s*$'],
                               regex=True,
                               default_confidence=0.01)
fallback = PatternMatchingSkill(
    responses=['Мысль свою изложи подробнее, юный падаван'],
    default_confidence=0.01)
faq = SimilarityMatchingSkill(save_load_path='./model', train=False)

agent = DefaultAgent([hello, bye, help, welcome, faq, fallback],
                     skills_selector=HighestConfidenceSelector())

start_agent_server(agent,
                   host='0.0.0.0',
                   port=5000,
                   endpoint='/faq',
                   ssl_key='/etc/letsencrypt/live/serg.ml/privkey.pem',
                   ssl_cert='/etc/letsencrypt/live/serg.ml/fullchain.pem')
Exemple #13
0
from deeppavlov.agents.processors.highest_confidence_selector import HighestConfidenceSelector

# hello = PatternMatchingSkill(responses=["Hello world!"], patterns=["(hi|hello|good day)"], regex = True)
# sorry = PatternMatchingSkill(responses=["don't be sorry", "Please don't"], patterns=["(sorry|excuse)"], regex = True)
# perhaps = PatternMatchingSkill(responses=["Please be more specific"], patterns=["(.*)perhaps(.*)"], regex = True)

hello = PatternMatchingSkill(responses=['Hi, I am a chatbot'],
                             patterns=['hi', 'hello', 'How are you'],
                             default_confidence=0.3)
faq = SimilarityMatchingSkill(
    data_path='http://files.deeppavlov.ai/faq/dataset.csv',
    x_col_name='Question',
    y_col_name='Answer',
    save_load_path='./model',
    config_type='tfidf_autofaq',
    edit_dict={},
    train=False)
bye = PatternMatchingSkill(responses=['have a nice day'],
                           patterns=['bye', 'goodbye'],
                           default_confidence=0.3)

agent = DefaultAgent([hello, bye, faq],
                     skills_selector=HighestConfidenceSelector())

# agent = DefaultAgent([hello, sorry, perhaps], skills_selector=HighestConfidenceSelector())
# q = agent(['hi, how are you', 'I am sorry', 'perhaps I am not sure'])

q = agent(['Hello', 'How can I get a visa?'])

print(q)