def test_run_qa(): last_output = "" with rs.Module(name="persqa_test"): @rs.state(cond=rs.sig_startup, write=rawio.prop_in) def persqa_hi(ctx: rs.ContextWrapper): ctx[rawio.prop_in] = "hi" @rs.state(read=rawio.prop_out) def raw_out(ctx: rs.ContextWrapper): nonlocal last_output last_output = ctx[rawio.prop_out] logger.info(f"Output: {ctx[rawio.prop_out]}") ctx = rs.Context("rawio", "ontology", "idle", "interloc", "nlp", "persqa", "persqa_test") @rs.receptor(ctx_wrap=ctx, write=rawio.prop_in) def say(ctx: rs.ContextWrapper, what: str): ctx[rawio.prop_in] = what ctx.emit(rs.sig_startup) while not persqa_hi.wait(.1): ctx.run_once(debug=True) ctx.test() # Wait for name being asked while not raw_out.wait(.1): ctx.run_once(debug=True) ctx.test() assert last_output in verbaliser.get_question_list("NAME") # Say name say("Herbert") # Wait for acknowledgement of name while not raw_out.wait(.1): ctx.run_once() assert persqa.inference.wait(0) assert persqa.react.wait(0) assert "herbert" in last_output.lower() # Wait for any other question via idle:bored while not raw_out.wait(.1): ctx.run_once() # Roboy now asked some predicate. Let's give some response. say("Big Brother") # Wait for Roboy's reaction. while not raw_out.wait(.1): ctx.run_once() assert persqa.inference.wait(0) assert persqa.react.wait(0) # Unfortunately needed until Context adopts Properties as clones. interloc.prop_all.children.clear()
def test_decline_offer(): last_output = "" with rs.Module(name="luigi_test"): @rs.state(cond=rs.sig_startup, read=interloc.prop_all) def luigi_hi(ctx: rs.ContextWrapper): ravestate_ontology.initialized.wait() interloc.handle_single_interlocutor_input(ctx, "hi") @rs.state(cond=rs.sig_shutdown, read=interloc.prop_all) def luigi_bye(ctx: rs.ContextWrapper): interloc.handle_single_interlocutor_input(ctx, "bye") @rs.state(read=rawio.prop_out) def raw_out(ctx: rs.ContextWrapper): nonlocal last_output last_output = ctx[rawio.prop_out] logger.info(f"Output: {ctx[rawio.prop_out]}") ctx = rs.Context("rawio", "ontology", "idle", "interloc", "nlp", "Luigi", "luigi_test") @rs.receptor(ctx_wrap=ctx, write=rawio.prop_in) def say(ctx: rs.ContextWrapper, what: str): ctx[rawio.prop_in] = what ctx.emit(rs.sig_startup) ctx.run_once() assert luigi_hi.wait() # Wait for greeting while not raw_out.wait(.1): ctx.run_once() # Wait for greeting while not raw_out.wait(.1): ctx.run_once() assert last_output in verbaliser.get_question_list("greet_general") say("no") # Wait for acknowledgement of answer while not raw_out.wait(.1): ctx.run_once() assert last_output in verbaliser.get_failure_answer_list("greet_general") ctx.run_once() assert luigi.analyse_ice_cream_suggestion_answer.wait() ctx.emit(rs.sig_shutdown) ctx.run_once() assert luigi_bye.wait() ctx.run_once() assert luigi.customer_left.wait()
def test_unknown_person(): last_output = "" with rs.Module(name="visionio_test"): @rs.state(read=rawio.prop_out) def raw_out(ctx: rs.ContextWrapper): nonlocal last_output last_output = ctx[rawio.prop_out] logger.info(f"Output: {ctx[rawio.prop_out]}") ctx = rs.Context("rawio", "ontology", "verbaliser", "idle", "interloc", "nlp", "persqa", "hibye", "visionio", "visionio_test", "-d", "ontology", "neo4j_pw", "test") @rs.receptor(ctx_wrap=ctx, write=visionio.prop_subscribe_faces) def unknown_person_approaches(ctx: rs.ContextWrapper): faces = Faces() faces.confidence = [0.5] faces.ids = [42] facial_features = FacialFeatures() facial_features.ff = np.zeros(128) faces.face_encodings = [facial_features] ctx[visionio.prop_subscribe_faces] = faces mem.initialized.clear() ctx.emit(rs.sig_startup) ctx.run_once() assert mem.initialized.wait() # Vision io is started assert visionio.reset.wait() unknown_person_approaches() # Wait until greeted counter = 0 while not raw_out.wait(.1) and counter < 100: ctx.run_once() counter += 1 assert last_output in verbaliser.get_phrase_list("greeting") assert visionio.recognize_faces.wait(0) ctx.shutdown() # Unfortunately needed until Context adopts Properties as clones. interloc.prop_all.children.clear()
def test_roboyqa(): phrases = ( "who are you?", "what is your name?", "how old are you?", "what is your age?", "what is your hobby?", "what are your hobbies?", "what do you like?", "where are you from?", "where do you live?", "who is your father/dad?", "who is your brother/sibling?", "who is your friend?", "what do you want to become?", # "what are you a member of?", "what can you do?", "what are your skills?", "what have you learned?", "what are your abilities?") last_output = "" with rs.Module(name="roboyqa_test"): @rs.state(read=rawio.prop_out) def raw_out(ctx: rs.ContextWrapper): nonlocal last_output last_output = ctx[rawio.prop_out] logger.info(f"Output: {ctx[rawio.prop_out]}") ctx = rs.Context("rawio", "ontology", "nlp", "idle", "verbaliser", "roboyqa", "roboyqa_test", "-d", "ontology", "neo4j_pw", "test") @rs.receptor(ctx_wrap=ctx, write=rawio.prop_in) def say(ctx: rs.ContextWrapper, what: str): ctx[rawio.prop_in] = what ctx.emit(rs.sig_startup) ctx.run_once() for phrase in phrases: say(phrase) while not raw_out.wait(.1): ctx.run_once()
import ravestate as rs import ravestate_nlp as nlp import ravestate_ontology as mem from scientio.ontology.node import Node from scientio.ontology.ontology import Ontology from reggol import get_logger logger = get_logger(__name__) ANON_INTERLOC_ID = "anonymous_interlocutor" ANON_INTERLOC_PATH = f"interloc:all:{ANON_INTERLOC_ID}" with rs.Module(name="interloc", depends=(nlp.mod, mem.mod)) as mod: # TODO: Make interloc:all a special property type, that only accepts ScientioNodeProperty as children prop_all = rs.Property(name="all", allow_read=True, allow_write=False, allow_push=True, allow_pop=True) prop_persisted = rs.Property(name="persisted", allow_read=True, allow_write=True, allow_push=True, allow_pop=True, always_signal_changed=True) @rs.state(cond=nlp.sig_intent_hi, read=prop_all, write=prop_all) def push_interlocutor(ctx): interloc_exists = ANON_INTERLOC_PATH in ctx.enum(prop_all)
import ravestate as rs with rs.Module(name="rawio") as mod: prop_in = rs.Property(name="in", default_value="", allow_pop=False, allow_push=False, always_signal_changed=True) prop_out = rs.Property(name="out", default_value="", allow_pop=False, allow_push=False, always_signal_changed=True, wipe_on_changed=False) prop_pic_in = rs.Property(name="pic_in", default_value=None, allow_pop=False, allow_push=False, always_signal_changed=True) def say(ctx, what: str) -> None: """ Calls an internal receptor to write a value to `rawio.prop_in`. Use this function in any IO module that has a state with a long-running loop. """ @rs.receptor(ctx_wrap=ctx, write=prop_in) def write_input(ctx_input, value: str):
import ravestate as rs from ravestate_ros1.ros1_properties import sync_ros_properties, Ros1SubProperty, Ros1PubProperty, Ros1CallProperty CONFIG = { # name of the ROS-Node that is created by ravestate_ros1 ros1_properties.NODE_NAME_CONFIG_KEY: "ravestate_ros1", # frequency for spinning of ROS-Node in spins per second (0: as fast as possible) ros1_properties.SPIN_FREQUENCY_CONFIG_KEY: 10 } with rs.Module(name="ros1", config=CONFIG) as mod: mod.add(sync_ros_properties)
import ravestate as rs 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)
def roboy_getter(doc) -> bool: return any(roboy in doc.text.lower() for roboy in about_roboy) from spacy.tokens import Doc Doc.set_extension('about_roboy', getter=roboy_getter) Doc.set_extension('empty_token', getter=lambda doc: empty_token) Doc.set_extension('triples', getter=extract_triples) Doc.set_extension('yesno', getter=yes_no) return spacy_nlp_en 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")
from scientio.ontology.node import Node from os.path import realpath, dirname, join import random import datetime from reggol import get_logger logger = get_logger(__name__) verbaliser.add_folder(join(dirname(realpath(__file__)), "answering_phrases")) ROBOY_NODE_PROP_CONF_KEY = "roboy_node_properties" with rs.Module(name="roboyqa", config={ROBOY_NODE_PROP_CONF_KEY: { "name": "roboy two" }}, depends=(nlp.mod, verbaliser.mod, idle.mod, rawio.mod)) as mod: @rs.state(cond=idle.sig_bored_by_user, write=rawio.prop_out, weight=1.01, cooldown=30.) def hello_world_roboyqa(ctx): ctx[rawio.prop_out] = verbaliser.get_random_phrase("roboyqa-prompt") @rs.state(cond=nlp.sig_contains_roboy & nlp.sig_is_question, read=nlp.prop_triples, write=rawio.prop_out) def roboyqa(ctx): """
import ravestate as rs import ravestate_emotion as emo import ravestate_rawio as rawio import random SHY_EMOJIS = ["\U0000263A"] SURPRISE_EMOJIS = ["\U0001F914"] HAPPY_EMOJIS = ["\U0001F60A", "\U0001F603"] AFFECTIONATE_EMOJIS = ["\U0001F618", "\U0001F970"] with rs.Module(name="emoji", depends=(emo.mod, rawio.mod)) as mod: @rs.state(cond=emo.sig_shy.detached(), write=rawio.prop_out) def show_shy(ctx: rs.ContextWrapper): ctx[rawio.prop_out] = random.choice(SHY_EMOJIS) @rs.state(cond=emo.sig_surprise.detached(), write=rawio.prop_out) def show_surprise(ctx: rs.ContextWrapper): ctx[rawio.prop_out] = random.choice(SURPRISE_EMOJIS) @rs.state(cond=emo.sig_happy.detached(), write=rawio.prop_out) def show_happy(ctx: rs.ContextWrapper): ctx[rawio.prop_out] = random.choice(HAPPY_EMOJIS) @rs.state(cond=emo.sig_affectionate.detached(), write=rawio.prop_out) def show_affectionate(ctx: rs.ContextWrapper): ctx[rawio.prop_out] = random.choice(AFFECTIONATE_EMOJIS)
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):
{ "FROM": "Location", "LIVE_IN": "Location", "HAS_HOBBY": "Hobby", "FRIEND_OF": "Person", # TODO Robot "STUDY_AT": "University", "MEMBER_OF": "Organization", "WORK_FOR": "Company", "OCCUPIED_AS": "Occupation" }) # TODO "movies", "OTHER" # TODO "sex", "birth date", "full name" # TODO "EQUALS" with rs.Module(name="persqa", depends=(verbaliser.mod, mem.mod, nlp.mod, idle.mod, rawio.mod, interloc.mod)) as mod: # This is a nice demo of using properties as synchronization # primitives. The problem: inference must only run for inputs # that did not trigger new_interloc. Therefore, new_interloc and inference # are mutually exclusive. This is enfored by having both of them # consume the inference_mutex property. prop_inference_mutex = rs.Property(name="inference_mutex") prop_subject = rs.Property(name="subject", default_value="", always_signal_changed=True, allow_pop=False, allow_push=False, is_flag_property=True)
import ravestate as rs import ravestate_rawio as rawio from reggol import get_logger logger = get_logger(__name__) with rs.Module(name="conio", depends=(rawio.mod, )) as mod: @rs.state(cond=rs.sig_startup) def console_input(ctx: rs.ContextWrapper): while not ctx.shutting_down(): input_value = input("> ") rawio.say(ctx, input_value) @rs.state(read=rawio.prop_out) def console_output(ctx): print(ctx["rawio:out:changed"])
import ravestate as rs import ravestate_rawio as rawio from .verbaliser import * from reggol import get_logger logger = get_logger(__name__) with rs.Module(name="verbaliser", depends=(rawio.mod,)) as mod: prop_intent = rs.Property( name="intent", default_value="", allow_push=False, allow_pop=False, always_signal_changed=True, wipe_on_changed=False) @rs.state(read=prop_intent, write=rawio.prop_out) def react_to_intent(ctx): """ Looks for intents written to the verbaliser:intent property and writes a random phrase for that intent to rawio:out """ intent = ctx[prop_intent.changed()] phrase = verbaliser.get_random_phrase(intent) if phrase: ctx[rawio.prop_out] = phrase else: logger.error(f'No phrase for intent {intent} found.')
REDIS_PASS_CONF = "redis_pass" ROS1_FACE_TOPIC_CONFIG = "ros1-node" FACE_CONFIDENCE_THRESHOLD = "min-confidence" PERSON_DISAPPEARED_THRESHOLD = "person-disappeared-threshold" CONFIG = { REDIS_HOST_CONF: "localhost", REDIS_PORT_CONF: 6379, REDIS_PASS_CONF: "", ROS1_FACE_TOPIC_CONFIG: "/roboy/cognition/vision/visible_face_names", FACE_CONFIDENCE_THRESHOLD: 0.85, PERSON_DISAPPEARED_THRESHOLD: 5 } with rs.Module(name="visionio", config=CONFIG, depends=(interloc.mod, mem.mod, ros.mod)) as mod: prop_subscribe_faces = ros.Ros1SubProperty( "face_names", topic="/roboy/cognition/vision/visible_face_names", msg_type=Faces, always_signal_changed=True, wipe_on_changed=False, boring=True) prop_face_filter = rs.Property(name="face_frequencies", default_value=None, always_signal_changed=True, allow_write=True)
def test_legit_order_need_flavor(): last_output = "" with rs.Module(name="luigi_test"): @rs.state(cond=rs.sig_startup, read=interloc.prop_all) def luigi_hi(ctx: rs.ContextWrapper): ravestate_ontology.initialized.wait() interloc.handle_single_interlocutor_input(ctx, "hi") @rs.state(cond=rs.sig_shutdown, read=interloc.prop_all) def luigi_bye(ctx: rs.ContextWrapper): interloc.handle_single_interlocutor_input(ctx, "bye") @rs.state(read=rawio.prop_out) def raw_out(ctx: rs.ContextWrapper): nonlocal last_output last_output = ctx[rawio.prop_out] logger.info(f"Output: {ctx[rawio.prop_out]}") ctx = rs.Context("rawio", "ontology", "idle", "interloc", "nlp", "Luigi", "luigi_test") @rs.receptor(ctx_wrap=ctx, write=rawio.prop_in) def say(ctx: rs.ContextWrapper, what: str): ctx[rawio.prop_in] = what ctx.emit(rs.sig_startup) ctx.run_once() assert luigi_hi.wait() # Wait for greeting while not raw_out.wait(.1): ctx.run_once() while not raw_out.wait(.1): ctx.run_once() assert last_output in verbaliser.get_question_list("greet_general") # Legit order say("chocolate two") # Wait for acknowledgement of order while not raw_out.wait(.1): ctx.run_once() assert luigi.detect_flavors_and_scoops.wait() assert luigi.check_scoops_flavor_combined.wait() assert last_output.replace( "2 scoops of choclate", "{order}") in verbaliser.get_phrase_list("legit_order") say("no") # Wait for acknowledgement of answer while not raw_out.wait(.1): ctx.run_once() assert luigi.analyse_finish_order_answer.wait() assert last_output in verbaliser.get_phrase_list("continue_order") # Only give flavor say("one") # Wait for acknowledgement of flavor while not raw_out.wait(.1): ctx.run_once() assert luigi.detect_flavors_and_scoops.wait() assert last_output.replace("scoop", "scoop{s}").replace( "1", "{scoop}") in verbaliser.get_phrase_list("need_flavor") # Only give scoops say("vanilla") # Wait for acknowledgement of scoop while not raw_out.wait(.1): ctx.run_once() assert luigi.detect_flavors_and_scoops.wait() assert luigi.check_scoops_flavor_combined.wait() assert last_output.replace("1 scoop of vanillla and 2 scoops of choclate", "{order}") in \ verbaliser.get_phrase_list("legit_order") # Order is finished say("yes") # Wait for acknowledgement of answer while not raw_out.wait(.1): ctx.run_once() ctx.emit(rs.sig_shutdown) ctx.run_once() assert luigi_bye.wait()
def test_legit_order(): last_output = "" with rs.Module(name="luigi_test"): @rs.state(cond=rs.sig_startup, read=interloc.prop_all) def luigi_hi(ctx: rs.ContextWrapper): ravestate_ontology.initialized.wait() interloc.handle_single_interlocutor_input(ctx, "hi") @rs.state(cond=rs.sig_shutdown, read=interloc.prop_all) def luigi_bye(ctx: rs.ContextWrapper): interloc.handle_single_interlocutor_input(ctx, "bye") @rs.state(read=rawio.prop_out) def raw_out(ctx: rs.ContextWrapper): nonlocal last_output last_output = ctx[rawio.prop_out] logger.info(f"Output: {ctx[rawio.prop_out]}") ctx = rs.Context("rawio", "ontology", "idle", "interloc", "nlp", "Luigi", "luigi_test") @rs.receptor(ctx_wrap=ctx, write=rawio.prop_in) def say(ctx: rs.ContextWrapper, what: str): ctx[rawio.prop_in] = what ctx.emit(rs.sig_startup) ctx.run_once() assert luigi_hi.wait() # Wait for greeting while not raw_out.wait(.1): ctx.run_once() while not raw_out.wait(.1): ctx.run_once() assert last_output in verbaliser.get_question_list("greet_general") say("yes") # Wait for acknowledgement of answer while not raw_out.wait(.1): ctx.run_once() assert luigi.analyse_ice_cream_suggestion_answer.wait() assert last_output in verbaliser.get_successful_answer_list( "greet_general") say("three scoops of vanilla") # Wait for acknowledgement of answer while not raw_out.wait(.1): ctx.run_once() assert luigi.detect_flavors_and_scoops.wait() assert last_output.replace( "3 scoops of vanillla", "{order}") in verbaliser.get_phrase_list("legit_order") say("yes") # Wait for acknowledgement of answer while not raw_out.wait(0.1): ctx.run_once() assert luigi.analyse_finish_order_answer.wait() assert last_output.replace( "3 scoops of vanillla", "{order}") in verbaliser.get_phrase_list("preparing_order") ctx.emit(rs.sig_shutdown) ctx.run_once() assert luigi_bye.wait() ctx.run_once() assert luigi.customer_left.wait()
LOOK_LEFT_EMOTION = 'lookleft' LOOK_RIGHT_EMOTION = 'lookright' HEARTS_EMOTION = 'hearts' SMILEBLINK_EMOTION = 'smileblink' HYPNO_EMOTION = 'hypno' 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")
from os.path import realpath, dirname, join verbaliser.add_file(join(dirname(realpath(__file__)), "sendpics_phrases.yml")) 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),
def test_known_person(): last_output = "" with rs.Module(name="visionio_test"): @rs.state(read=rawio.prop_out) def raw_out(ctx: rs.ContextWrapper): nonlocal last_output last_output = ctx[rawio.prop_out] logger.info(f"Output: {ctx[rawio.prop_out]}") # Unfortunately needed until Context adopts Properties as clones. interloc.prop_all.children.clear() ctx = rs.Context("rawio", "ontology", "verbaliser", "idle", "interloc", "nlp", "hibye", "visionio", "visionio_test", "-d", "ontology", "neo4j_pw", "test") def register_dummy_known_person_to_db(): onto: Ontology = mem.get_ontology() sess: Session = mem.get_session() person_node = Node(metatype=onto.get_type("Person")) person_node.set_properties({'name': 'visionio_test_person'}) person_node = sess.create(person_node) return person_node def delete_dummy_people(): onto: Ontology = mem.get_ontology() sess: Session = mem.get_session() person_node = Node(metatype=onto.get_type("Person")) person_node.set_properties({'name': 'visionio_test_person'}) # TODO: Delete method is not working! sess.delete(person_node) @rs.receptor(ctx_wrap=ctx, write=visionio.prop_subscribe_faces) def known_person_approaches(ctx: rs.ContextWrapper): person = register_dummy_known_person_to_db() faces = Faces() faces.confidence = [0.85] faces.ids = [person.get_id()] facial_features = FacialFeatures() facial_features.ff = np.zeros(128) faces.face_encodings = [facial_features] ctx[visionio.prop_subscribe_faces] = faces mem.initialized.clear() ctx.emit(rs.sig_startup) ctx.run_once() assert mem.initialized.wait() # Vision io is started assert visionio.reset.wait() known_person_approaches() # Wait until greeted counter = 0 while not raw_out.wait(.1) and counter < 100: ctx.run_once() counter += 1 greeting_phrases = [ phrase.replace('{name}', 'visionio_test_person') for phrase in verbaliser.get_phrase_list("greeting-with-name") ] assert last_output in greeting_phrases assert visionio.recognize_faces.wait(0) ctx.shutdown() delete_dummy_people() # Unfortunately needed until Context adopts Properties as clones. interloc.prop_all.children.clear()
TEMPERATURE_KEY = "temperature" MAX_TOKENS_KEY = "max-tokens" MIN_PROB_KEY = "min-probability" STOP_INDICATORS_KEY = "stop-indicators" CONFIG = { GPT3_API_KEY: "", PROMPT_KEY: PROMPT, HUMAN_PROMPT_PREFIX_KEY: PREFIX_HUMAN, ROBOY_PROMPT_PREFIX_KEY: PREFIX_ROBOY, TEMPERATURE_KEY: 1.2, MAX_TOKENS_KEY: 64, MIN_PROB_KEY: 0.5, STOP_INDICATORS_KEY: ["\n"] } with rs.Module(name="gpt3", config=CONFIG, depends=(rawio.mod, )) as mod: history = [] def append_to_history(who: str, what: str): if what.startswith("Watch your conversation on Raveboard"): return combined = who + what if not history or history[-1] != combined: history.append(combined) @rs.state(cond=rawio.prop_in.changed().detached(), read=rawio.prop_in, boring=True) def input_seen(ctx): append_to_history(ctx.conf(key=HUMAN_PROMPT_PREFIX_KEY),
COIN = 0 PAYPAL = 1 class ScoopingFeedbackMessages(IntEnum): NONE = -1 TIME = -2 class DetectionStates(IntEnum): NOT_SET = -1 OUT = 0 IN = 1 with rs.Module(name="Luigi"): # -------------------- properties -------------------- # prop_flavors = rs.Property(name="flavor", always_signal_changed=False, default_value=[], allow_read=True, allow_write=True) prop_scoops = rs.Property(name="scoops", always_signal_changed=False, default_value=[], allow_read=True, allow_write=True) prop_flavor_scoop_tuple_list = rs.Property(name="flavor_scoop_tuple_list", default_value=[],
import ravestate as rs import ravestate_idle as idle import ravestate_verbaliser as verbaliser import ravestate_phrases_basic_en as lang with rs.Module(name="fillers", depends=(idle.mod, verbaliser.mod)) as mod: @rs.state(cond=idle.sig_impatient, write=verbaliser.prop_intent) def impatient_fillers(ctx: rs.ContextWrapper): ctx[verbaliser.prop_intent] = lang.intent_fillers
AVAILABLE_MODELS = ["convai_gpt", "gpt2", "parlai"] CONFIG = { MODEL_KEY: AVAILABLE_MODELS[0], # one of "convai_gpt", "gpt2", "parlai" SERVER_ADDRESS_KEY: "http://localhost", # can be changed if server is running on its own on a separate machine SERVER_PORT_KEY: 5100, TEMPERATURE_KEY: 0.7, # convai_gpt, gpt2: higher value -> more variation in output MAX_LENGTH_KEY: 20, # convai_gpt, gpt2: maximal length of generated output TOP_K_KEY: 0, # convai_gpt, gpt2: <=0: no filtering, >0: keep only top k tokens with highest probability. TOP_P_KEY: 0.9, # convai_gpt: <=0.0 no filtering, >0.0: keep smallest subset whose total probability mass >= top_p MAX_HISTORY_KEY: 4, # convai_gpt: maximal number of previous dialog turns to be used for output generation } server_started = False with rs.Module(name="wildtalk", config=CONFIG, depends=(rawio.mod,)): @rs.state(cond=rs.sig_startup) def init_wildtalk(ctx): server_address = f"{ctx.conf(key=SERVER_ADDRESS_KEY)}:{ctx.conf(key=SERVER_PORT_KEY)}" if not server_up(server_address): model = ctx.conf(key=MODEL_KEY) if model not in AVAILABLE_MODELS: logger.error( f"{ctx.conf(key=MODEL_KEY)} is not an available wildtalk model. Falling back to using {AVAILABLE_MODELS[0]}") model = AVAILABLE_MODELS[0] global server_started server_started = True logger.info("Starting up wildtalk server") server.run(port=ctx.conf(key=SERVER_PORT_KEY), model=model) # start server server_started = False
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
AXIS2_UPPER_LIMIT_KEY: 0.3, # upper limit for movement on axis 2 HEAD_MOVEMENT_PROBABILITY_KEY: 0.5, # probability for an axis to moves; decided separately for each axis EYE_MOVEMENT_PROBABILITY_KEY: 0.5, # probability for eyes to look left/right/ } LOOK_LEFT_EMOTION = "lookleft" LOOK_RIGHT_EMOTION = "lookright" SHY_EMOTION = "shy" SURPRISE_EMOTION = "surprise" SMILEBLINK_EMOTION = "smileblink" LUCKY_EMOTION = "lucky" KISS_EMOTION = "kiss" with rs.Module( name="roboyio", config=CONFIG, depends=(interloc.mod, rawio.mod, idle.mod, emotion.mod)) as mod: prop_head_axis0 = Ros1PubProperty(name="head_axis0", topic="/sphere_head_axis0/sphere_head_axis0/target", msg_type=Float32) prop_head_axis1 = Ros1PubProperty(name="head_axis1", topic="/sphere_head_axis1/sphere_head_axis1/target", msg_type=Float32) prop_head_axis2 = Ros1PubProperty(name="head_axis2", topic="/sphere_head_axis2/sphere_head_axis2/target", msg_type=Float32) prop_show_emotion = Ros1PubProperty(name="show_emotion", topic="/roboy/cognition/face/show_emotion", msg_type=String) prop_move_eyes = Ros1PubProperty(name="move_eyes", topic="/roboy/cognition/face/show_emotion", msg_type=String) recognized_speech = Ros1SubProperty( name="recognized_speech", topic="/roboy/cognition/speech/recognition", msg_type=RecognizedSpeech, always_signal_changed=True)
import ravestate as rs import ravestate_verbaliser as verbaliser import ravestate_phrases_basic_en as lang import ravestate_interloc as interloc import ravestate_rawio as rawio from scientio.ontology.node import Node from os.path import realpath, dirname, join verbaliser.add_folder(join(dirname(realpath(__file__)), "en")) with rs.Module(name="hibye", depends=(interloc.mod, rawio.mod, verbaliser.mod)) as mod: @rs.state(cond=interloc.prop_all.pushed().min_age(1.), write=rawio.prop_out, read=interloc.prop_all) def greeting(ctx: rs.ContextWrapper): pushed_node_path: str = ctx[interloc.prop_all.pushed()] interloc_node: Node = ctx[pushed_node_path] if interloc_node and interloc_node.get_id() >= 0: phrase = verbaliser.get_random_phrase('greeting-with-name') ctx[rawio.prop_out] = phrase.format(name=interloc_node.get_name()) else: ctx[rawio.prop_out] = verbaliser.get_random_phrase(lang.intent_greeting) @rs.state(cond=interloc.prop_all.popped(), write=verbaliser.prop_intent) def farewell(ctx: rs.ContextWrapper): ctx[verbaliser.prop_intent] = lang.intent_farewells