-
Notifications
You must be signed in to change notification settings - Fork 714
/
manage.py
executable file
·46 lines (38 loc) · 1.33 KB
/
manage.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
from flask.cli import AppGroup, with_appcontext
from app import create_app
app = create_app()
cli = AppGroup('manage', help='migrate commands')
@cli.command('migrate')
@with_appcontext
def migrate():
from app.repository.models import Bot
from app.admin.bots import import_json
from app.bot.nlu.training import train_pipeline
# Create default bot
try:
bot = Bot()
bot.name = "default"
bot.save()
print("Created default bot")
except Exception as e:
print(f"Default bot creation failed or already exists: {e}")
# Import default intents
try:
with open("migrations/default_intents.json", "r") as json_file:
stories = import_json(json_file)
print(f"Imported {len(stories)} Stories")
except FileNotFoundError:
print("Error: 'migrations/default_intents.json' file not found.")
except Exception as e:
print(f"Failed to import intents: {e}")
# Train models
try:
print("Training models..")
train_pipeline(app)
print("Training models finished.")
except Exception as e:
error_message = str(e)
if error_message == "NO_DATA":
error_message = "Load data first into MongoDB. Refer to the README."
print(f"Could not train models: {error_message}")
app.cli.add_command(cli)