Beispiel #1
0
def test_socketio_channel():
    from rasa_core.channels.socketio import SocketIOInput
    from rasa_core.agent import Agent
    from rasa_core.interpreter import RegexInterpreter

    # load your trained agent
    agent = Agent.load(MODEL_PATH, interpreter=RegexInterpreter())

    input_channel = SocketIOInput(
        # event name for messages sent from the user
        user_message_evt="user_uttered",
        # event name for messages sent from the bot
        bot_message_evt="bot_uttered",
        # socket.io namespace to use for the messages
        namespace=None)

    # set serve_forever=True if you want to keep the server running
    s = agent.handle_channels([input_channel], 5004, serve_forever=False)
    # END DOC INCLUDE
    # the above marker marks the end of the code snipped included
    # in the docs
    try:
        assert s.started
        routes_list = utils.list_routes(s.application)
        assert routes_list.get("/webhooks/socketio/").startswith(
            'socketio_webhook.health')
    finally:
        s.stop()
Beispiel #2
0
def run(core_dir, nlu_dir):

    input_channel = SocketIOInput(user_message_evt="user_uttered",
                                  bot_message_evt="bot_uttered",
                                  session_persistence=True,
                                  namespace=None)

    _endpoints = AvailableEndpoints.read_endpoints('endpoints.yml')
    _interpreter = NaturalLanguageInterpreter.create(nlu_dir)

    elastic_user = os.getenv('ELASTICSEARCH_USER')
    if elastic_user is None:
        _tracker_store = ElasticTrackerStore(
            domain=os.getenv('ELASTICSEARCH_URL', 'elasticsearch:9200'))
    else:
        _tracker_store = ElasticTrackerStore(
            domain=os.getenv('ELASTICSEARCH_URL', 'elasticsearch:9200'),
            user=os.getenv('ELASTICSEARCH_USER', 'user'),
            password=os.getenv('ELASTICSEARCH_PASSWORD', 'password'),
            scheme=os.getenv('ELASTICSEARCH_HTTP_SCHEME', 'http'),
            scheme_port=os.getenv('ELASTICSEARCH_PORT', '80'))

    _agent = load_agent(core_dir,
                        interpreter=_interpreter,
                        tracker_store=_tracker_store,
                        endpoints=_endpoints)

    WEBCHAT_PORT = os.getenv('WEBCHAT_PORT', 3000)
    http_server = start_server([input_channel], "", "", int(WEBCHAT_PORT),
                               _agent)

    try:
        http_server.serve_forever()
    except Exception as exc:
        logger.exception(exc)
Beispiel #3
0
def run():
    agent = Agent.load("models/current/dialogue")
    #agent.handle_channels();
    # agent.predict_next()
    input_channel = SocketIOInput(
        # event name for messages sent from the user
        user_message_evt="user_uttered",
        # event name for messages sent from the bot
        bot_message_evt="bot_uttered",
        # socket.io namespace to use for the messages
        namespace=None)
    s = agent.handle_channels([input_channel], 5500, serve_forever=True)
def start_server_local(dialogue_model_path, server_endpoints):
    """Start a server which serve a local model.

    Environment variables:
    ----------
    SOCKET_PORT:    int
                    Set the port, the server should listen on
                    (default: 5005)

    Parameters:
    ----------
    dialogue_model_path:    str
                            Path to the local model directiory
    server_endpoints:       AvailableEndpoints
                            tuple with the endpoints nlg, nlu, action and model
    """

    # Check SOCKET_PORT
    socket_port = int(
        os.environ['SOCKET_PORT']) if "SOCKET_PORT" in os.environ else 5005

    # define nlu-server
    rasaNLU = RasaNLUHttpInterpreter(project_name="damage_report_1.0.0",
                                     endpoint=server_endpoints.nlu)

    # initialize the agent
    agent = Agent.load(dialogue_model_path,
                       interpreter=rasaNLU,
                       action_endpoint=server_endpoints.action)

    # define all channels the server should listen to.
    # SocketIOInput - socketIO for the webchat
    # RestInput     - Rest-Api for other services
    channels = [
        SocketIOInput(
            # event name for messages sent from the user
            user_message_evt="user_uttered",
            # event name for messages sent from the bot
            bot_message_evt="bot_uttered",
            # socket.io namespace to use for the messages
            namespace=None),
        RestInput()
    ]

    # Start the server
    agent.handle_channels(channels, socket_port)
from rasa_core.agent import Agent
from rasa_core.channels.socketio import SocketIOInput
from rasa_core.agent import Agent

# load your trained agent
agent = Agent.load('models/dialogue', interpreter='models/current/nlu')

input_channel = SocketIOInput(
    # event name for messages sent from the user
    user_message_evt="user_uttered",
    # event name for messages sent from the bot
    bot_message_evt="bot_uttered",
    # socket.io namespace to use for the messages
    namespace=None)

# set serve_forever=False if you want to keep the server running
s = agent.handle_channels([input_channel], 5500, serve_forever=True)
Beispiel #6
0
from rasa_core.channels.socketio import SocketIOInput
from rasa_core.agent import Agent
from rasa_core.interpreter import RasaNLUInterpreter

interpreter = RasaNLUInterpreter("models/six/nlu/")
agent = Agent.load("models/six/dialogue", interpreter=interpreter)
agent.handle_channels([SocketIOInput()], 5500, serve_forever=True)