Пример #1
0
 def slot_wrapper(ctx: Context, actor: Actor) -> Context:
     results = func(ctx, actor)
     if results is None:
         return ctx
     return save_slots_to_ctx({slot: result for slot, result in zip(slots, results) if result is not None})(
         ctx, actor
     )
Пример #2
0
             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(),
         },
     },
     "node1": {
         RESPONSE: int_rsp.multi_response(replies=["Hi, how are you?", "Hi, what's up?"]),  # several hypothesis
         PROCESSING: {
             "save_slots_to_ctx": int_prs.save_slots_to_ctx({"topic": "science", "user_name": "Gordon Freeman"})
         },
         TRANSITIONS: {"node2": cnd.regexp(r"how are you", re.IGNORECASE)},
     },
     "node2": {
         RESPONSE: loc_rsp.example_response("Good. What do you want to talk about?"),
         # loc_rsp.example_response is just for an example, you can use just str without example_response func
         TRANSITIONS: {"node3": loc_cnd.example_lets_talk_about()},
     },
     "node3": {
         RESPONSE: "Sorry, I can not talk about that now. Maybe late. Do you like {topic}?",
         PROCESSING: {"fill_responses_by_slots": int_prs.fill_responses_by_slots()},
         TRANSITIONS: {
             "node4": int_cnd.is_yes_vars,
             "node5": int_cnd.is_no_vars,
             "node6": int_cnd.is_do_not_know_vars,
Пример #3
0
         },
     },
     "genrebook_info": {
         RESPONSE: loc_rsp.append_question(initial="{cur_book_about} Anyway, "),
         PROCESSING: {
             "about_bookreads": loc_prs.about_bookreads,
             "execute_response": loc_prs.execute_response,
             "fill_responses_by_slots": int_prs.fill_responses_by_slots(),
         },
         TRANSITIONS: {},
     },
     "bot_fav": {
         RESPONSE: loc_rsp.genre_phrase,
         PROCESSING: {
             "save_slots_to_ctx": int_prs.save_slots_to_ctx(
                 {"cur_genre", random.choice(list(loc_rsp.GENRE_PHRASES.keys()))}
             )
         },
         TRANSITIONS: {},
     },
 },
 "bible_flow": {
     "bible_start": {
         RESPONSE: (
             "You have good taste in books! "
             "By the way, I know that Bible is one of the most widespread books on Earth. "
             "It is the foundation stone of Christianity. Have you read the whole Bible?"
         ),
         TRANSITIONS: {
             "bible_elaborate": cnd.true(),
         },
Пример #4
0
def save_next_key(keys: Iterator, maindict: dict) -> Callable:
    try:
        return save_slots_to_ctx(maindict[next(keys)])
    except StopIteration:
        return save_slots_to_ctx(maindict[random.choice(list(maindict.keys()))])
Пример #5
0
 def slot_wrapper(ctx: Context, actor: Actor) -> Optional[str]:
     result = func(ctx, actor)
     if result is None:
         return ctx
     return save_slots_to_ctx({slots: result})(ctx, actor)