Beispiel #1
0
        allow_write=True)
    prop_payment_option_detection = rs.Property(
        name="payment_option_detection",
        always_signal_changed=False,
        default_value=DetectionStates.NOT_SET,
        allow_read=True,
        allow_write=True)
    prop_yesno_detection = rs.Property(name="yesno_detection",
                                       always_signal_changed=False,
                                       default_value=DetectionStates.NOT_SET,
                                       allow_read=True,
                                       allow_write=True)

    # -------------------- signals -------------------- #

    sig_finish_order_question = rs.Signal("finish_order_question")
    sig_start_payment = rs.Signal("start_payment")
    sig_finished_payment = rs.Signal("finished_payment")
    sig_payment_incomplete = rs.Signal("payment_incomplete")
    sig_yesno_detected = rs.Signal("yesno")
    sig_changed_flavor_or_scoops = rs.Signal("changed_flavor_or_scoops")
    sig_changed_payment_option = rs.Signal("changed_payment_option")
    sig_ice_cream_desire = rs.Signal("ice_cream_desire")
    sig_suggested_ice_cream = rs.Signal("suggested_ice_cream")
    sig_insert_coins_or_scan_qr = rs.Signal("insert_coins_or_scan_qr")
    sig_ask_again_order = rs.Signal("ask_again_order")
    sig_asked_payment_method = rs.Signal("asked_payment_method")
    sig_send_to_scooping = rs.Signal("send_to_scooping")
    sig_loop_feedback = rs.Signal("loop_feedback")
    sig_wait_for_cup = rs.Signal("wait_for_cup")
    sig_wait_for_telegram_customer_to_come_close = rs.Signal(
Beispiel #2
0
import ravestate_interloc as interloc

from reggol import get_logger
logger = get_logger(__name__)

IMPATIENCE_THRESHOLD_CONFIG_KEY = "impatience_threshold"
BORED_THRESHOLD_CONFIG_KEY = "bored_threshold"
CONFIG = {
    # duration in seconds how long ":pressure" should be true before getting impatient
    IMPATIENCE_THRESHOLD_CONFIG_KEY: 1.0,
    BORED_THRESHOLD_CONFIG_KEY: 3.0
}

with rs.Module(name="idle", config=CONFIG, depends=(interloc.mod, )) as mod:

    sig_impatient = rs.Signal(name="impatient")
    sig_bored = rs.Signal(name="bored")
    sig_bored_by_user = rs.Signal(name="bored-by-user")

    @rs.state(cond=rs.prop_activity.changed().min_age(
        rs.ConfigurableAge(key=BORED_THRESHOLD_CONFIG_KEY)).max_age(-1),
              read=rs.prop_activity,
              signal=sig_bored)
    def am_i_bored(ctx: rs.ContextWrapper):
        """
        Emits idle:bored signal if no states are currently partially fulfilled
        """
        if ctx[rs.prop_activity] == 0:
            return rs.Emit(wipe=True)

    @rs.state(cond=sig_bored, read=interloc.prop_all, signal=sig_bored_by_user)
Beispiel #3
0
USE_EMOTIONS = "emotions"
CONFIG = {
    USE_EMOTIONS: False
    # defines if Roboy's emotions will be used
}

if ROS_AVAILABLE:

    with rs.Module(name="charades",
                   config=CONFIG,
                   depends=(nlp.mod, idle.mod, rawio.mod, ros1.mod,
                            verbaliser.mod)) as mod:

        # signals
        sig_mentioned_charades = rs.Signal("mentioned_charades")
        sig_offered_charades = rs.Signal("offer_game")
        sig_offered_rules = rs.Signal("play_offered_rules")
        sig_rules_decision_done = rs.Signal("rules_decision_done")
        sig_activity_choice_prompted = rs.Signal("activity_choice_propmted")
        sig_readiness_check_started = rs.Signal("readiness_check_started")
        sig_action_captured = rs.Signal("action_captured")
        sig_label_named = rs.Signal("action_captured")
        sig_asked_to_continue = rs.Signal("asked_to_continue")
        sig_continue_game = rs.Signal("continue_game")
        sig_feedback_unclear = rs.Signal("feedback_not_understood")
        sig_feedback_repeat = rs.Signal("feedback_repeat")

        # properties
        prop_stop_game = rs.Property(name="prop_stop_game",
                                     always_signal_changed=True,
Beispiel #4
0
spacy_nlp_en = init_spacy()


with rs.Module(name="nlp", depends=(rawio.mod,)) as mod:

    prop_tokens = rs.Property(name="tokens", default_value="", always_signal_changed=True, allow_pop=False, allow_push=False)
    prop_postags = rs.Property(name="postags", default_value="", always_signal_changed=True, allow_pop=False, allow_push=False)
    prop_lemmas = rs.Property(name="lemmas", default_value="", always_signal_changed=True, allow_pop=False, allow_push=False)
    prop_tags = rs.Property(name="tags", default_value="", always_signal_changed=True, allow_pop=False, allow_push=False)
    prop_ner = rs.Property(name="ner", default_value="", always_signal_changed=True, allow_pop=False, allow_push=False)
    prop_triples = rs.Property(name="triples", default_value="", always_signal_changed=True, allow_pop=False, allow_push=False)
    prop_roboy = rs.Property(name="roboy", default_value="", always_signal_changed=True, allow_pop=False, allow_push=False)
    prop_yesno = rs.Property(name="yesno", default_value=YesNoWrapper(""), always_signal_changed=True, allow_pop=False, allow_push=False)

    sig_contains_roboy = rs.Signal(name="contains-roboy")
    sig_is_question = rs.Signal(name="is-question")
    sig_intent_play = rs.Signal(name="intent-play")
    sig_intent_hi = rs.Signal(name="intent-hi")
    sig_intent_bye = rs.Signal(name="intent-bye")

    @rs.state(read=rawio.prop_in, write=(prop_tokens, prop_postags, prop_lemmas, prop_tags, prop_ner, prop_triples, prop_roboy, prop_yesno))
    def nlp_preprocess(ctx):
        text = ctx[rawio.prop_in]
        if not text:
            return False
        text = text.lower()
        nlp_doc = spacy_nlp_en(text)

        nlp_tokens = tuple(str(token) for token in nlp_doc)
        ctx[prop_tokens] = nlp_tokens
Beispiel #5
0
    def _load_modules(self, modules: List[str]):
        super()._load_modules(modules)

        with rs.Module(name=RAVEBOARD, config=RAVEBOARD_CONFIG, depends=(rawio.mod, verbaliser.mod, nlp.mod)) as mod:

            sig_last_output = rs.Signal(name="last-output")
            sig_heartbeat = rs.Signal(name="heartbeat")
            prop_connections = rs.Property(name="connections")

            @rs.state(cond=rs.sig_startup.detached().min_age(1.), write=rawio.prop_out)
            def startup(ctx):
                session_db_path = ctx.conf(mod=RAVEBOARD, key=SESSION_DB_KEY)
                if session_db_path:
                    self.session_client = SessionClient(db_path=session_db_path, port=ctx.conf(key=PORT_CONFIG_KEY))
                self.config_parsed.set()
                if ctx.conf(key=URL_ANNOUNCE_KEY) == ANNOUNCE_URL_YES:
                    sio_uri = urllib.parse.quote(f"{ctx.conf(key=URL_PREFIX_KEY)}:{ctx.conf(key=PORT_CONFIG_KEY)}")
                    url = f"{ctx.conf(key=URL_PREFIX_KEY)}:{ctx.conf(key=PORT_CONFIG_KEY)}/ravestate/index.html?rs-sio-url={sio_uri}"
                    logger.info(f"Raveboard URL: {url}")
                    ctx[rawio.prop_out] = f"Watch your conversation on Raveboard here! {url}"

            @rs.state(cond=rs.sig_startup | sig_heartbeat.min_age(1.), signal=sig_heartbeat, emit_detached=True, boring=True)
            def heartbeat(ctx):
                self.config_parsed.wait()
                if self.session_client and not self.session_client.dead():
                    self.session_client.heartbeat()
                    return rs.Emit()

            @rs.state(read=rawio.prop_out, signal=sig_last_output, emit_detached=True, boring=True)
            def emit_output(ctx):
                self.sio.emit("output", {"type": "output", "text": ctx[rawio.prop_out.changed()]})
                return rs.Emit(wipe=True)

        self._add_ravestate_module(mod)

        @rs.receptor(ctx_wrap=self, write=(rawio.prop_in,))
        def receive_input(ctx, _, new_input_event):
            if 'text' not in new_input_event:
                logger.error("Bad socket.io message for input event!")
                return
            ctx[rawio.prop_in] = new_input_event['text']
        self.sio.on("input", receive_input)

        @rs.receptor(ctx_wrap=self, write=(rawio.prop_in,))
        def new_connection(ctx):
            if ctx.conf(mod=RAVEBOARD, key=GREETING_KEY) == GREET_ON_CONNECT:
                ctx[rawio.prop_in] = "hi"

            @rs.state(
                cond=sig_last_output.min_age(rs.ConfigurableAge(key=SESSION_TIMEOUT_KEY)).max_age(-1).detached(),
                write=verbaliser.prop_intent,
                boring=True)
            def end_session(ctx):
                if self.session_client:
                    self.session_client.killme()
                    ctx[verbaliser.prop_intent] = lang.intent_farewells

            mod.add(end_session)
            ctx.add_state(end_session)

        self.new_connection = new_connection
Beispiel #6
0
REDIS_HOST_CONF = "redis_host"
REDIS_PORT_CONF = "redis_port"
REDIS_PASS_CONF = "redis_pass"
CONFIG = {
    REDIS_HOST_CONF: "localhost",
    REDIS_PORT_CONF: 6379,
    REDIS_PASS_CONF: None
}

with rs.Module(name="sendpics",
               config=CONFIG,
               depends=(rawio.mod, nlp.mod, idle.mod, verbaliser.mod)) as mod:

    prop_face_vec = rs.Property(name="face_vec", always_signal_changed=True)

    sig_repeat_name = rs.Signal("repeat_name")

    @rs.state(cond=idle.sig_bored_by_user,
              write=rawio.prop_out,
              weight=0.8,
              cooldown=30.)
    def prompt_send(ctx):
        ctx[rawio.prop_out] = verbaliser.get_random_phrase("sendpics-prompt")

    @rs.state(read=rawio.prop_pic_in,
              write=(rawio.prop_out, prop_face_vec),
              emit_detached=True)
    def prompt_name(ctx):
        # Get face ancoding
        face = recognize_face_from_image_file(ctx[rawio.prop_pic_in])
        # Prompt name
Beispiel #7
0
SHY_PROB_KEY = "shy_probability"
SURPRISED_PROB_KEY = "surprise_probability"
HAPPY_PROB_KEY = "happy_probability"
AFFECTIONATE_PROB_KEY = "affectionate_probability"
CONFIG = {
    SHY_PROB_KEY: 0.2,  # Probability for being shy when input is about Roboy
    SURPRISED_PROB_KEY: 0.1,  # Probability for being surprised when input is question
    HAPPY_PROB_KEY: 0.1,  # Probability for being happy when output is generated
    AFFECTIONATE_PROB_KEY: 0.5,  # Probability for being affectionate when keyword is in input and input is about Roboy
}

AFFECTIONATE_LIST = ["cute", "nice", "cool", "awesome", "funny"]

with rs.Module(name="emotion", config=CONFIG, depends=(rawio.mod, nlp.mod)) as mod:

    sig_shy = rs.Signal(name="shy")
    sig_surprise = rs.Signal(name="surprise")
    sig_happy = rs.Signal(name="happy")
    sig_affectionate = rs.Signal(name="affectionate")

    @rs.state(signal=sig_shy, cond=nlp.sig_contains_roboy)
    def is_shy(ctx: rs.ContextWrapper):
        if random.random() < ctx.conf(key=SHY_PROB_KEY):
            logger.debug(f"Emitting {sig_shy.name}")
            return rs.Emit()
        return rs.Resign()

    @rs.state(signal=sig_surprise, cond=nlp.sig_is_question)
    def is_surprised(ctx: rs.ContextWrapper):
        if random.random() < ctx.conf(key=SURPRISED_PROB_KEY):
            logger.debug(f"Emitting {sig_surprise.name}")
Beispiel #8
0
                                 is_flag_property=True)

    prop_answer = rs.Property(name="answer",
                              default_value="",
                              always_signal_changed=True,
                              allow_pop=False,
                              allow_push=False,
                              is_flag_property=True)

    prop_follow_up_prop = rs.Property(name="follow_up",
                                      default_value="",
                                      always_signal_changed=True,
                                      allow_pop=False,
                                      allow_push=False)

    sig_follow_up = rs.Signal(name="follow-up")

    sig_predicate_asked = rs.Signal(name="predicate-asked")

    def find_empty_relationship(dictonary: Dict):
        for key in dictonary:
            if not dictonary[key] and key in PREDICATE_SET:
                return key
        return None

    def retrieve_or_create_node(node: Node):
        sess: Session = mem.get_session()
        node_list = sess.retrieve(node)
        if not node_list:
            node = sess.create(node)
        elif len(node_list) > 0:
Beispiel #9
0
is_busy = False
first_yes = False
ws = 'ws://localhost:8765'  # TODO change to cloud address

with rs.Module(name="Luigi"):

    # -------------------- properties -------------------- #

    prop_suggested_ice_cream = rs.Property(name="suggested_ice_cream", always_signal_changed=False, default_value=False,
                                           allow_read=True, allow_write=True)
    prop_location = rs.Property(name="location", always_signal_changed=False, default_value=[], allow_read=True,
                                allow_write=True)

    # -------------------- signals -------------------- #

    sig_location_question = rs.Signal("location_question")
    sig_yesno_detected = rs.Signal("yesno")
    sig_ice_cream_desire_and_not_location = rs.Signal("ice_cream_desire_and_not_location")
    sig_ice_cream_desire_and_location = rs.Signal("ice_cream_desire_and_location")
    sig_suggested_ice_cream = rs.Signal("suggested_ice_cream")
    sig_asked_for_location = rs.Signal("asked_for_location")
    sig_decide_to_call_customer = rs.Signal("decide_to_call_customer")

    # -------------------- detection methods -------------------- #

    # def detect_triple_ice_cream_desire(ctx):
    #     triples = ctx[nlp.prop_triples]
    #     lemmas = ctx[nlp.prop_lemmas]
    #     ice_cream_desire = False
    #     print("INSIDE ICE CREAM DESIRE")
    #     for i in range(0, len(triples)):