def start_server(input_channels, cors, auth_token, port, initial_agent, enable_api=True): """Run the agent.""" if enable_api: app = server.create_app(initial_agent, cors_origins=cors, auth_token=auth_token) else: app = Flask(__name__) CORS(app, resources={r"/*": {"origins": cors or ""}}) if input_channels: rasa_core.channels.channel.register(input_channels, app, initial_agent.handle_message, route="/webhooks/") if logger.isEnabledFor(logging.DEBUG): utils.list_routes(app) http_server = WSGIServer(('0.0.0.0', port), app) logger.info("Rasa Core server is up and running on " "{}".format(constants.DEFAULT_SERVER_URL)) http_server.start() return http_server
def run_online_learning(agent, finetune=False, serve_forever=True): # type: (Agent, bool, bool) -> WSGIServer """Start the online learning with the model of the agent.""" app = server.create_app(agent) return _serve_application(app, finetune, serve_forever)
def start_server(input_channels, cors, auth_token, port, initial_agent, enable_api=True, jwt_secret=None, jwt_method=None): """Run the agent.""" if enable_api: app = server.create_app(initial_agent, cors_origins=cors, auth_token=auth_token, jwt_secret=jwt_secret, jwt_method=jwt_method) else: app = Flask(__name__) CORS(app, resources={r"/*": {"origins": cors or ""}}) if input_channels: rasa_core.channels.channel.register(input_channels, app, initial_agent.handle_message, route="/webhooks/") if logger.isEnabledFor(logging.DEBUG): utils.list_routes(app) http_server = WSGIServer(('0.0.0.0', port), app) logger.info("Rasa Core server is up and running on " "{}".format(constants.DEFAULT_SERVER_FORMAT.format(port))) http_server.start() return http_server
def core_server_secured(default_agent): app = server.create_app(default_agent, auth_token="rasa", jwt_secret="core") channel.register([RestInput()], app, default_agent.handle_message, "/webhooks/") return app
async def core_server_secured(prepared_agent): app = server.create_app(prepared_agent, auth_token="rasa", jwt_secret="core") channel.register([RestInput()], app, "/webhooks/") return app
def run_interactive_learning(agent: Agent, stories: Text = None, finetune: bool = False, serve_forever: bool = True, skip_visualization: bool = False) -> WSGIServer: """Start the interactive learning with the model of the agent.""" app = server.create_app(agent) return _serve_application(app, stories, finetune, serve_forever, skip_visualization)
def core_server(tmpdir_factory): model_path = tmpdir_factory.mktemp("model").strpath agent = Agent("data/test_domains/default.yml", policies=[AugmentedMemoizationPolicy(max_history=3)]) training_data = agent.load_data(DEFAULT_STORIES_FILE) agent.train(training_data) agent.persist(model_path) return server.create_app(model_path, interpreter=RegexInterpreter())
def configure_app(input_channels=None, cors=None, auth_token=None, enable_api=True, jwt_secret=None, jwt_method=None, route="/webhooks/", port=None): """Run the agent.""" from rasa_core import server if enable_api: app = server.create_app(cors_origins=cors, auth_token=auth_token, jwt_secret=jwt_secret, jwt_method=jwt_method) else: app = Sanic(__name__) CORS(app, resources={r"/*": { "origins": cors or "" }}, automatic_options=True) if input_channels: rasa_core.channels.channel.register(input_channels, app, route=route) else: input_channels = [] if logger.isEnabledFor(logging.DEBUG): utils.list_routes(app) # configure async loop logging async def configure_logging(): if logger.isEnabledFor(logging.DEBUG): utils.enable_async_loop_debugging(asyncio.get_event_loop()) app.add_task(configure_logging) if "cmdline" in {c.name() for c in input_channels}: async def run_cmdline_io(running_app: Sanic): """Small wrapper to shut down the server once cmd io is done.""" await asyncio.sleep(1) # allow server to start await console.record_messages( server_url=constants.DEFAULT_SERVER_FORMAT.format(port)) logger.info("Killing Sanic server now.") running_app.stop() # kill the sanic serverx app.add_task(run_cmdline_io) return app
def run_interactive_learning(agent, stories, finetune=False, serve_forever=True, skip_visualization=False): # type: (Agent, Text, bool, bool, bool) -> WSGIServer """Start the interactive learning with the model of the agent.""" app = server.create_app(agent) return _serve_application(app, stories, finetune, serve_forever, skip_visualization)
def test_list_routes(default_agent): from rasa_core import server app = server.create_app(default_agent, auth_token=None) routes = utils.list_routes(app) assert set(routes.keys()) == { 'hello', 'version', 'execute_action', 'append_event', 'replace_events', 'list_trackers', 'retrieve_tracker', 'retrieve_story', 'respond', 'predict', 'parse', 'train_stack', 'log_message', 'load_model', 'evaluate_stories', 'get_domain', 'continue_training', 'status', 'tracker_predict' }
def run_server_bot(serve_forever=True, model_path='./models/dialogue', nlu_model_path='./models/nlu/default/current'): nlu_interpreter = RasaNLUInterpreter(nlu_model_path) action_endpoint = EndpointConfig(url="http://localhost:5055/webhook", serve_forever=serve_forever) agent = Agent.load(model_path, interpreter=nlu_interpreter, action_endpoint=action_endpoint) bot_app = server.create_app(agent) http_server = WSGIServer(('0.0.0.0', 5005), bot_app) http_server.start() http_server.serve_forever() return http_server
def core_server(tmpdir_factory): model_path = tmpdir_factory.mktemp("model").strpath agent = Agent("data/test_domains/default.yml", policies=[AugmentedMemoizationPolicy(max_history=3)]) training_data = agent.load_data(DEFAULT_STORIES_FILE) agent.train(training_data) agent.persist(model_path) loaded_agent = Agent.load(model_path, interpreter=RegexInterpreter()) app = server.create_app(loaded_agent) channel.register([RestInput()], app, agent.handle_message, "/webhooks/") return app
def run(serve_forever=True): download("en") download("de") interpreter = RasaNLUInterpreter("models/current/nlu") bot = server.create_app("models/dialogue", interpreter=interpreter) logger.info("Started http server on port %s" % '8080') http_server = WSGIServer(('0.0.0.0', 8080), bot) logger.info("Up and running") try: http_server.serve_forever() except Exception as exc: logger.exception(exc) return bot
def start_server(input_channels, cors, auth_token, port, initial_agent, enable_api=True, jwt_secret=None, jwt_method=None): """Run the agent.""" from rasa_core import server from flask import Flask from flask_cors import CORS, cross_origin if enable_api: app = server.create_app(initial_agent, cors_origins=cors, auth_token=auth_token, jwt_secret=jwt_secret, jwt_method=jwt_method) else: from rasa_core.version import __version__ app = Flask(__name__) CORS(app, resources={r"/*": {"origins": cors or ""}}) cors_origins = cors or [] @app.route("/", methods=['GET', 'OPTIONS']) @cross_origin(origins=cors_origins) def hello(): """Check if the server is running and responds with the version.""" return "hello from Rasa Core: " + __version__ if input_channels: rasa_core.channels.channel.register(input_channels, app, initial_agent.handle_message, route="/webhooks/") if logger.isEnabledFor(logging.DEBUG): utils.list_routes(app) http_server = WSGIServer(('0.0.0.0', port), app) logger.info("Rasa Core server is up and running on " "{}".format(constants.DEFAULT_SERVER_FORMAT.format(port))) http_server.start() return http_server
def start_server(input_channels, cors, auth_token, port, initial_agent, enable_api=True, jwt_secret=None, jwt_method=None): """Run the agent.""" if enable_api: app = server.create_app(initial_agent, cors_origins=cors, auth_token=auth_token, jwt_secret=jwt_secret, jwt_method=jwt_method) # print('I am a Not a flask app'); else: app = Flask(__name__) app.logger.setLevel(logging.ERROR) # print('I am a flask app'); app.debug = False CORS(app, resources={r"/*": {"origins": cors or ""}}) if input_channels: rasa_core.channels.channel.register(input_channels, app, initial_agent.handle_message, route="/webhooks/") if logger.isEnabledFor(logging.DEBUG): utils.list_routes(app) http_server = WSGIServer(('0.0.0.0', port), application=app, log=None, backlog=None, error_log=None) # http://www.gevent.org/api/gevent.pywsgi.html; Log level details; logger.info("Rasa Core server is up and running on " "{}".format(constants.DEFAULT_SERVER_FORMAT.format(port))) http_server.start() return http_server
def serve_agent(agent, serve_forever=True, get_next_message=None): app = server.create_app(agent) return serve_application(app, serve_forever, get_next_message)
async def core_server(prepared_agent): app = server.create_app(prepared_agent) channel.register([RestInput()], app, "/webhooks/") return app
def test_list_routes(default_agent): from rasa_core import server app = server.create_app(default_agent, auth_token=None) routes = utils.list_routes(app) assert len(routes) > 0
def _add_visualization_routes(app: Flask, image_path: Text = None) -> None: """Add routes to serve the conversation visualization files.""" @app.route(VISUALIZATION_TEMPLATE_PATH, methods=["GET"]) def visualisation_html(): return send_file(visualization.visualization_html_path()) @app.route("/visualization.dot", methods=["GET"]) def visualisation_png(): try: response = send_file(os.path.abspath(image_path)) response.headers['Cache-Control'] = "no-cache" return response except FileNotFoundError: abort(404) def run_interactive_learning(agent: Agent, stories: Text = None, finetune: bool = False, serve_forever: bool = True, skip_visualization: bool = False, **ssl_args: Any = None) -> WSGIServer: """Start the interactive learning with the model of the agent.""" app = server.create_app(agent) return _serve_application(app, stories, finetune, serve_forever, skip_visualization, *ssl_args)