forked from charlesXu86/Chatbot_RASA
/
bot.py
executable file
·50 lines (36 loc) · 1.1 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
'''
@Author : Xu
@Software: PyCharm
@File : bot.py
@Time : 2019-09-25 14:23
@Desc : 可用于代码断点调试
'''
import rasa
import pathlib
import os
from rasa.core.agent import Agent
from rasa.core import config
basedir = str(pathlib.Path(os.path.abspath(__file__)).parent)
model = basedir + "/models"
endpoints = "config/endpoints.yml"
credentials = "credentials.yml"
#
ss = rasa.run(model=model,
endpoints=endpoints,
credentials=credentials
)
def train_dialogue_transformer(domain_file="mobile_domain.yml",
model_path="models/dialogue_transformer",
training_data_file="data/mobile_edit_story.md"):
# 通过加载yml配置文件方式配置policy
policies = config.load('./policy/attention_policy.yml')
agent = Agent(domain_file,
policies=policies)
training_data = agent.load_data(training_data_file)
agent.train(
training_data,
validation_split=0.2
)
agent.persist(model_path)
return agent