Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
add stack training endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ricwo committed Mar 5, 2019
1 parent c5a389e commit 5c969d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rasa_core/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import logging
import sys

import rasa_core.cli.arguments
from gevent.pywsgi import WSGIServer
Expand Down Expand Up @@ -155,7 +156,6 @@ def serve_application(initial_agent,
def load_agent(core_model, interpreter, endpoints,
tracker_store=None):
from rasa_core import agent

if endpoints.model:
return agent.load_from_server(
interpreter=interpreter,
Expand Down
28 changes: 22 additions & 6 deletions rasa_core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

from rasa_core import utils, constants
from rasa_core.channels import CollectingOutputChannel, UserMessage
from rasa_core.test import test
from rasa_core.events import Event
from rasa_core.domain import Domain
from rasa_core.events import Event
from rasa_core.policies import PolicyEnsemble
from rasa_core.test import test
from rasa_core.trackers import DialogueStateTracker, EventVerbosity
from rasa_core.version import __version__

Expand Down Expand Up @@ -486,8 +486,7 @@ def load_model():
logger.debug("Finished loading new agent.")
return '', 204

@app.route("/evaluate",
methods=['POST', 'OPTIONS'])
@app.route("/evaluate", methods=['POST', 'OPTIONS'])
@requires_auth(app, auth_token)
@cross_origin(origins=cors_origins)
def evaluate_stories():
Expand All @@ -505,8 +504,25 @@ def evaluate_stories():
"Evaluation could not be created. Error: {}"
"".format(e))

@app.route("/domain",
methods=['GET', 'OPTIONS'])
@app.route("/jobs", methods=['POST', 'OPTIONS'])
@requires_auth(app, auth_token)
@cross_origin(origins=cors_origins)
def train_stack():
from rasa.cli.train import train
from argparse import Namespace

# TODO LOCAL: validate namespace json in request
args = Namespace(**request.get_json())
print('have args', args)
try:
model_name = train(args)
return jsonify({'info': 'new model trained', 'model': model_name})
except Exception as e:
# TODO local: except specific training exception that can occur
return error(400, "TrainingError",
"Rasa stack model could not be trained.", e)

@app.route("/domain", methods=['GET', 'OPTIONS'])
@cross_origin(origins=cors_origins)
@requires_auth(app, auth_token)
@ensure_loaded_agent(agent)
Expand Down

0 comments on commit 5c969d8

Please sign in to comment.