예제 #1
0
파일: condition.py 프로젝트: deepmipt/deepy
def offered_topic_choice_declined_condition(ctx: Context, actor: Actor, *args,
                                            **kwargs) -> bool:

    prev_bot_uttr = int_ctx.get_last_bot_utterance(ctx, actor)["text"]
    # asked what to talk about
    shared_memory = int_ctx.get_shared_memory(ctx, actor)
    greeting_step_id = shared_memory.get("greeting_step_id", 0)
    was_linking_topic_offering = (GREETING_STEPS[greeting_step_id -
                                                 1] == "what_to_talk_about"
                                  if greeting_step_id > 0 else False)
    user_asked_for_topic = any([
        resp.lower() in prev_bot_uttr.lower()
        for resp in common_greeting.GREETING_QUESTIONS["what_to_talk_about"]
    ])

    was_active = "dff_friendship_skill" == int_ctx.get_last_bot_utterance(
        ctx, actor).get("active_skill", "")
    # offered choice between two topics
    offered_topics = shared_memory.get("offered_topics", [])
    # and user declined
    declined = int_cnd.is_no_vars(ctx, actor)
    if was_active and offered_topics and was_linking_topic_offering and not user_asked_for_topic and declined:
        # was offered particular linking question, and user said no
        return True
    return False
예제 #2
0
def activity_answer_response(ctx: Context, actor: Actor, *args,
                             **kwargs) -> str:
    response = ""
    if is_yes_vars(ctx, actor):
        set_can_continue(ctx, actor, CAN_NOT_CONTINUE)
        set_confidence(ctx, actor, SMALLTALK_CONF)
        shared_memory = get_shared_memory(ctx, actor)
        preferred_weather = shared_memory.get("preferred_weather", "")
        save_to_shared_memory(ctx, actor, preferred_weather="")
        if preferred_weather:
            response = WEATHER_DICT[preferred_weather]["answer"]
    else:
        set_can_continue(ctx, actor, CAN_NOT_CONTINUE)
        set_confidence(ctx, actor, ZERO_CONF)
    return response
예제 #3
0
파일: condition.py 프로젝트: deepmipt/deepy
def std_greeting_condition(ctx: Context, actor: Actor, *args,
                           **kwargs) -> bool:
    flag = True
    # flag = flag and not condition_utils.is_new_human_entity(vars)
    # flag = flag and not condition_utils.is_switch_topic(vars)
    # flag = flag and not condition_utils.is_opinion_request(vars)
    # flag = flag and not condition_utils.is_lets_chat_about_topic_human_initiative(vars)
    # flag = flag and not condition_utils.is_question(vars)
    # flag = flag and condition_utils.is_begin_of_dialog(vars)
    if flag:
        shared_memory = int_ctx.get_shared_memory(ctx, actor)
        flag = flag and shared_memory.get("greeting_step_id",
                                          0) < len(GREETING_STEPS)

    return flag
예제 #4
0
def random_funfact_response(ctx: Context, actor: Actor, *args, **kwargs) -> str:
    response = ""
    set_confidence(ctx, actor, CONF_HIGH)
    set_can_continue(ctx, actor, MUST_CONTINUE)
    funfact_list = copy.deepcopy(FUNFACT_LIST)
    random.shuffle(funfact_list)
    shared_memory = get_shared_memory(ctx, actor)
    given_funfacts = []
    if shared_memory:
        given_funfacts = shared_memory.get("given_funfacts", [])
    for funfact, topic in funfact_list:
        if funfact not in given_funfacts:
            given_funfacts.append(funfact)
            save_to_shared_memory(ctx, actor, given_funfacts=given_funfacts)
            link_question = make_question(topic)
            response = f"{funfact} {link_question}"
            break
    if not response:
        set_confidence(ctx, actor, CONF_ZERO)
    return response
예제 #5
0
def get_not_used_and_save_sentiment_acknowledgement(ctx: Context,
                                                    actor: Actor,
                                                    sentiment=None):
    if sentiment is None:
        sentiment = int_ctx.get_human_sentiment(ctx, actor)
        if is_yes_vars(ctx, actor) or is_no_vars(ctx, actor):
            sentiment = "neutral"

    shared_memory = int_ctx.get_shared_memory(ctx, actor)
    last_acknowledgements = shared_memory.get("last_acknowledgements", [])

    ack = common_utils.get_not_used_template(
        used_templates=last_acknowledgements,
        all_templates=GENERAL_ACKNOWLEDGEMENTS[sentiment])

    used_acks = last_acknowledgements + [ack]
    int_ctx.save_to_shared_memory(ctx,
                                  actor,
                                  last_acknowledgements=used_acks[-2:])
    return ack