def unused_handler(ctx: Context, actor: Actor) -> str: used = ctx.misc.get("used_phrases", []) confidences = [1] * len(phrases) for idx, phrase in enumerate(phrases): times: int = used.count(id(phrase)) if times == 0: used.append(id(phrase)) ctx.misc["used_phrases"] = used return initial + phrase confidences[idx] *= 0.4**times if exit_on_exhaust: label = ctx.last_label actor.plot[label[0]][label[1]].transitions = { ("global_flow", "fallback", 2): cnd.true() } return initial target_idx = confidences.index(max(confidences)) target_phrase = phrases[target_idx] used.append(id(target_phrase)) ctx.misc["used_phrases"] = used return initial + target_phrase
import logging from df_engine.core.keywords import TRANSITIONS, RESPONSE from df_engine.core import Actor import df_engine.conditions as cnd from . import response as loc_rsp logger = logging.getLogger(__name__) flows = { "story_flow": { "start_node": { RESPONSE: loc_rsp.programy_reponse, TRANSITIONS: { "start_node": cnd.true(), }, } } } actor = Actor(flows, start_label=("story_flow", "start_node"))
# `RESPONSE` - contains the response that the dialog agent will return when transitioning to this node. # `TRANSITIONS` - describes transitions from the current node to other nodes. # `TRANSITIONS` are described in pairs: # - the node to which the agent will perform the transition # - the condition under which to make the transition flows = { GLOBAL: { TRANSITIONS: { ("greeting", "node1"): cnd.regexp(r"\bhi\b"), }, }, "sevice": { "start": { RESPONSE: "", TRANSITIONS: {("greeting", "node1"): cnd.true()}, }, "fallback": { RESPONSE: "Ooops", TRANSITIONS: { lbl.previous(): cnd.regexp(r"previous", re.IGNORECASE), lbl.repeat(0.2): cnd.true(), }, }, }, "greeting": { LOCAL: { PROCESSING: { "set_confidence": int_prs.set_confidence(1.0), "set_can_continue": int_prs.set_can_continue(), # "fill_responses_by_slots": int_prs.fill_responses_by_slots(),
loc_cnd.art_skill_switch, cnd.neg(loc_cnd.check_flag("art_skill_active")) ]), } }, "art": { "drawing_q": { RESPONSE: "Do you like drawing?", TRANSITIONS: { ("drawing", "what_painter", 2): cnd.any([ int_cnd.is_yes_vars, cnd.regexp(templates.LIKE_PATTERN), ], ), lbl.forward(): cnd.true(), }, PROCESSING: { "set_flag": loc_prs.set_flag("art_skill_active"), "set_confidence": loc_prs.set_start_confidence, }, }, "photo_q": { RESPONSE: ["Do you like taking photos?"], TRANSITIONS: { ("photo", "what_photos"): cnd.any( [int_cnd.is_yes_vars, cnd.regexp(templates.LIKE_PATTERN)]) }, PROCESSING: {
dislikes_reading = cnd.any([ cnd.regexp( re.compile( r"((n['o]t (want|like) (to )?(go on|continue|hear|talk|discuss|speak|listen))|" r"(no more)|" r"(whatever)|" r"((stop|quit|exit)))", re.IGNORECASE, )), cnd.regexp(re.compile(NOT_LIKE_PATTERN)), ]) exit_skill = cnd.any([ is_side_or_stop, # int_cnd.is_switch_topic, # is_switch_topic, cnd.all([is_proposed_skill, int_cnd.is_no_vars]), ]) has_read_transitions = { ("concrete_book_flow", "ask_opinion", 2): int_cnd.is_yes_vars, ("genre_flow", "not_read_genrebook", 1.9): cnd.any([int_cnd.is_no_vars, hasnt_read]), ("genre_flow", "genrebook_info", 1.8): cnd.all([about_in_slots, tell_me_more]), ("undetected_flow", "change_branch", 1.7): cnd.true(), }
import logging from df_engine.core.keywords import GLOBAL, TRANSITIONS, RESPONSE from df_engine.core import Actor import df_engine.conditions as cnd import common.dff.integration.condition as int_cnd from . import condition as loc_cnd from . import response as loc_rsp logger = logging.getLogger(__name__) flows = { GLOBAL: {TRANSITIONS: {("story_flow", "fallback_node"): cnd.true()}}, "story_flow": { "start_node": { RESPONSE: "", TRANSITIONS: { "choose_story_node": cnd.all( [ loc_cnd.is_tell_me_a_story, loc_cnd.has_story_type, loc_cnd.has_story_left, ] ), "which_story_node": cnd.all([loc_cnd.is_tell_me_a_story, cnd.neg(loc_cnd.has_story_type)]), }, }, "choose_story_node": { RESPONSE: loc_rsp.choose_story,
), cnd.any([int_cnd.is_yes_vars, loc_cnd.no_entities]), cnd.neg(loc_cnd.book_in_request), cnd.neg(loc_cnd.author_in_request), cnd.neg(loc_cnd.movie_in_request), ] ), } }, "global_flow": { "start": { RESPONSE: "", PROCESSING: {"set_can_continue": int_prs.set_can_continue(CAN_CONTINUE_SCENARIO)}, TRANSITIONS: { ("books_general", "book_start"): loc_cnd.start_condition, lbl.repeat(): cnd.true(), }, }, "fallback": { RESPONSE: loc_rsp.append_unused( initial="Anyway, let's talk about something else! ", phrases=[ SWITCH_MOVIE_SKILL_PHRASE, OFFER_TALK_ABOUT_SCIENCE, "What's on your mind?", ], ), PROCESSING: { "set_flag": loc_prs.set_flag("book_skill_active"), "set_confidence": int_prs.set_confidence(ZERO_CONFIDENCE), "set_can_continue": int_prs.set_can_continue(CAN_NOT_CONTINUE),
"service": { "start": { RESPONSE: "" }, "fallback": { RESPONSE: "", PROCESSING: { "set_confidence": int_prs.set_confidence(ZERO_CONFIDENCE) } }, }, GLOBAL: { TRANSITIONS: { ("context_driven_response", "intent_catcher"): loc_cnd.intent_catcher_exists_condition, ("simple", "default"): cnd.true(), }, }, "context_driven_response": { "intent_catcher": { RESPONSE: rsp.intent_catcher_response, PROCESSING: { "set_confidence": rsp.set_confidence_from_input }, }, }, "simple": { "default": { RESPONSE: rsp.default_response, PROCESSING: { "set_confidence": int_prs.set_confidence(ZERO_CONFIDENCE)
dislikes_reading = cnd.any( [ cnd.regexp( re.compile( r"((n['o]t (want|like) (to )?(go on|continue|hear|talk|discuss|speak|listen))|" r"(no more)|" r"(whatever)|" r"((stop|quit|exit)))", re.IGNORECASE, ) ), cnd.regexp(re.compile(NOT_LIKE_PATTERN)), ] ) exit_skill = cnd.any( [ is_side_or_stop, # int_cnd.is_switch_topic, # is_switch_topic, cnd.all([is_proposed_skill, int_cnd.is_no_vars]), ] ) has_read_transitions = { ("concrete_book_flow", "ask_opinion", 2): int_cnd.is_yes_vars, ("genre_flow", "not_read_genrebook", 1.9): cnd.any([int_cnd.is_no_vars, hasnt_read]), ("genre_flow", "genrebook_info", 1.8): cnd.all([about_in_slots, tell_me_more]), ("undetected_flow", "change_branch", 1.7): cnd.true(), }
import logging from df_engine.core.keywords import RESPONSE, TRANSITIONS from df_engine.core import Actor import df_engine.labels as lbl import df_engine.conditions as cnd from .responses import grounding_response logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO) logger = logging.getLogger(__name__) flows = { "grounding": { "start_node": { RESPONSE: "", TRANSITIONS: {"grounding_response_node": cnd.true()}, }, "grounding_response_node": { RESPONSE: grounding_response, TRANSITIONS: {lbl.repeat(): cnd.true()}, }, }, } actor = Actor( flows, start_label=("grounding", "start_node"), fallback_node_label=("grounding", "grounding_response_node") )
("weather", "continue_question"): chat_about_weather_condition, }, }, "fallback": { RESPONSE: "Oops", PROCESSING: { "set_confidence": int_prs.set_confidence(ZERO_CONF) }, }, }, "weather": { "forecast": { RESPONSE: forecast_response, TRANSITIONS: { "activity_question": cnd.true() } }, "location_request": { RESPONSE: "Hmm. Which particular city would you like a weather forecast for?", PROCESSING: { "location_request_processing": location_request_processing }, TRANSITIONS: { "forecast": cnd.true() }, }, "continue_question": { RESPONSE: ASK_WEATHER_SKILL_PHRASE, PROCESSING: {