示例#1
0
def test_broker_from_config():
    cfg = utils.read_endpoint_config(EVENT_BROKER_ENDPOINT_FILE,
                                     "event_broker")
    actual = PikaProducer.from_endpoint_config(cfg)

    expected = PikaProducer("localhost", "username", "password", "queue")

    assert actual.host == expected.host
    assert actual.credentials.username == expected.credentials.username
    assert actual.queue == expected.queue
def run(core_dir, nlu_dir):
    pika_broker = None

    if ENABLE_ANALYTICS:
        pika_broker = PikaProducer(url, username, password, queue=queue)

    configs = {
        'user': os.getenv('ROCKETCHAT_BOT_USERNAME'),
        'password': os.getenv('ROCKETCHAT_BOT_PASSWORD'),
        'server_url': os.getenv('ROCKETCHAT_URL'),
    }

    input_channel = RocketChatInput(user=configs['user'],
                                    password=configs['password'],
                                    server_url=configs['server_url'])

    _tracker_store = InMemoryTrackerStore(domain=None,
                                          event_broker=pika_broker)

    _endpoints = AvailableEndpoints.read_endpoints(None)
    _interpreter = NaturalLanguageInterpreter.create(nlu_dir)

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

    http_server = start_server([input_channel], "", "", 5005, _agent)

    try:
        http_server.serve_forever()
    except Exception as exc:
        logger.exception(exc)
示例#3
0
def create_agent(model: Text,
                 endpoints: Text = None) -> 'Agent':
    from rasa_core.broker import PikaProducer
    from rasa_core.interpreter import RasaNLUInterpreter
    import rasa_core.run
    from rasa_core.tracker_store import TrackerStore
    from rasa_core.utils import AvailableEndpoints

    core_path, nlu_path = get_model_subdirectories(model)
    _endpoints = AvailableEndpoints.read_endpoints(endpoints)

    _interpreter = None
    if os.path.exists(nlu_path):
        _interpreter = RasaNLUInterpreter(model_directory=nlu_path)
    else:
        _interpreter = None
        logging.info("No NLU model found. Running without NLU.")

    _broker = PikaProducer.from_endpoint_config(_endpoints.event_broker)

    _tracker_store = TrackerStore.find_tracker_store(None,
                                                     _endpoints.tracker_store,
                                                     _broker)
    return rasa_core.run.load_agent(core_path, interpreter=_interpreter,
                                    tracker_store=_tracker_store,
                                    endpoints=_endpoints)
示例#4
0
def do_interactive_learning(cmdline_args, stories, additional_arguments):
    _endpoints = AvailableEndpoints.read_endpoints(cmdline_args.endpoints)
    _interpreter = NaturalLanguageInterpreter.create(cmdline_args.nlu,
                                                     _endpoints.nlu)

    if cmdline_args.core:
        if cmdline_args.finetune:
            raise ValueError("--core can only be used without "
                             "--finetune flag.")

        logger.info("Loading a pre-trained model. This means that "
                    "all training-related parameters will be ignored.")

        _broker = PikaProducer.from_endpoint_config(_endpoints.event_broker)
        _tracker_store = TrackerStore.find_tracker_store(
            None, _endpoints.tracker_store, _broker)

        _agent = Agent.load(cmdline_args.core,
                            interpreter=_interpreter,
                            generator=_endpoints.nlg,
                            tracker_store=_tracker_store,
                            action_endpoint=_endpoints.action)
    else:
        if cmdline_args.out:
            model_directory = cmdline_args.out
        else:
            model_directory = tempfile.mkdtemp(suffix="_core_model")

        _agent = train_dialogue_model(cmdline_args.domain, stories,
                                      model_directory, _interpreter,
                                      _endpoints, cmdline_args.dump_stories,
                                      cmdline_args.config[0], None,
                                      additional_arguments)

    interactive.run_interactive_learning(
        _agent,
        stories,
        finetune=cmdline_args.finetune,
        skip_visualization=cmdline_args.skip_visualization)
示例#5
0
def do_interactive_learning(cmdline_args, stories, additional_arguments):
    _endpoints = AvailableEndpoints.read_endpoints(cmdline_args.endpoints)
    _interpreter = NaturalLanguageInterpreter.create(cmdline_args.nlu,
                                                     _endpoints.nlu)

    if (isinstance(cmdline_args.config, list)
            and len(cmdline_args.config) > 1):
        raise ValueError("You can only pass one config file at a time")
    if cmdline_args.core and cmdline_args.finetune:
        raise ValueError("--core can only be used without --finetune flag.")
    elif cmdline_args.core:
        logger.info("loading a pre-trained model. "
                    "all training-related parameters will be ignored")

        _broker = PikaProducer.from_endpoint_config(_endpoints.event_broker)
        _tracker_store = TrackerStore.find_tracker_store(
            None, _endpoints.tracker_store, _broker)

        _agent = Agent.load(cmdline_args.core,
                            interpreter=_interpreter,
                            generator=_endpoints.nlg,
                            tracker_store=_tracker_store,
                            action_endpoint=_endpoints.action)
    else:
        if not cmdline_args.out:
            raise ValueError("you must provide a path where the model "
                             "will be saved using -o / --out")

        _agent = train_dialogue_model(cmdline_args.domain, stories,
                                      cmdline_args.out, _interpreter,
                                      _endpoints, cmdline_args.dump_stories,
                                      cmdline_args.config[0], None,
                                      additional_arguments)
    interactive.run_interactive_learning(
        _agent,
        stories,
        finetune=cmdline_args.finetune,
        skip_visualization=cmdline_args.skip_visualization)
示例#6
0
    arg_parser = create_argument_parser()
    cmdline_args = arg_parser.parse_args()

    logging.getLogger('werkzeug').setLevel(logging.WARN)
    logging.getLogger('matplotlib').setLevel(logging.WARN)

    utils.configure_colored_logging(cmdline_args.loglevel)
    utils.configure_file_logging(cmdline_args.loglevel,
                                 cmdline_args.log_file)

    logger.info("Rasa process starting")

    _endpoints = AvailableEndpoints.read_endpoints(cmdline_args.endpoints)
    _interpreter = NaturalLanguageInterpreter.create(cmdline_args.nlu,
                                                     _endpoints.nlu)
    _broker = PikaProducer.from_endpoint_config(_endpoints.event_broker)

    _tracker_store = TrackerStore.find_tracker_store(
        None, _endpoints.tracker_store, _broker)
    _agent = load_agent(cmdline_args.core,
                        interpreter=_interpreter,
                        tracker_store=_tracker_store,
                        endpoints=_endpoints)
    serve_application(_agent,
                      cmdline_args.connector,
                      cmdline_args.port,
                      cmdline_args.credentials,
                      cmdline_args.cors,
                      cmdline_args.auth_token,
                      cmdline_args.enable_api,
                      cmdline_args.jwt_secret,
示例#7
0
def test_broker_not_in_config():
    cfg = utils.read_endpoint_config(DEFAULT_ENDPOINTS_FILE, "event_broker")

    actual = PikaProducer.from_endpoint_config(cfg)

    assert actual is None