dream

Форк
0
1105 строк · 45.7 Кб
1
# %%
2
import json
3
import logging
4
import os
5
import random
6
import re
7

8
from common.fact_random import get_fact
9
from enum import Enum, auto
10

11
import sentry_sdk
12
from spacy import load
13

14
from dff import dialogflow_extension
15
import common.dialogflow_framework.utils.state as state_utils
16
import common.dialogflow_framework.utils.condition as condition_utils
17
import dialogflows.scopes as scopes
18
from common.universal_templates import if_chat_about_particular_topic, DONOTKNOW_LIKE, COMPILE_NOT_WANT_TO_TALK_ABOUT_IT
19
from common.constants import CAN_CONTINUE_SCENARIO, CAN_CONTINUE_PROMPT, MUST_CONTINUE, CAN_NOT_CONTINUE
20
from common.utils import is_yes, is_no, get_entities, join_words_in_or_pattern, get_comet_conceptnet_annotations
21
from common.food import (
22
    TRIGGER_PHRASES,
23
    FOOD_WORDS,
24
    WHAT_COOK,
25
    FOOD_UTTERANCES_RE,
26
    CUISINE_UTTERANCES_RE,
27
    CONCEPTNET_SYMBOLOF_FOOD,
28
    CONCEPTNET_HASPROPERTY_FOOD,
29
    CONCEPTNET_CAUSESDESIRE_FOOD,
30
    ACKNOWLEDGEMENTS,
31
    FOOD_FACT_ACKNOWLEDGEMENTS,
32
)
33
from common.link import link_to_skill2i_like_to_talk
34
from dialogflows.flows.fast_food import State as FFState
35
from dialogflows.flows.fast_food import fast_food_request
36

37

38
sentry_sdk.init(dsn=os.getenv("SENTRY_DSN"))
39

40

41
logger = logging.getLogger(__name__)
42

43

44
spacy_nlp = load("en_core_web_sm")
45

46

47
with open("cuisines_facts.json", "r") as f:
48
    CUISINES_FACTS = json.load(f)
49

50
FOOD_WORDS_RE = re.compile(FOOD_WORDS, re.IGNORECASE)
51
WHAT_COOK_RE = re.compile(WHAT_COOK, re.IGNORECASE)
52
DONOTKNOW_LIKE_RE = re.compile(join_words_in_or_pattern(DONOTKNOW_LIKE), re.IGNORECASE)
53
NO_WORDS_RE = re.compile(r"(\bnot\b|n't|\bno\b) ", re.IGNORECASE)
54
# FAV_RE = re.compile(r"favou?rite|like", re.IGNORECASE)
55
LIKE_RE = re.compile(r"\bi (like|love|adore)( to (bake|cook|eat)|)", re.IGNORECASE)
56

57
MEALS = [
58
    "lazagna",
59
    "mac and cheese",
60
    "instant pot beef chili",
61
    "tomato basil soup",
62
    "spaghetti with tomato sauce",
63
    "chicken noodle soup",
64
    "rice with chicken and salad",
65
    "potatoes with cheese and beans",
66
    "fries with beef and tomatoes",
67
    "quinoa with turkey and broccoli",
68
]
69
CUISINES_COUNTRIES = {
70
    "french": "France",
71
    "chinese": "China",
72
    "japanese": "Japan",
73
    "italian": "Italy",
74
    "greek": "Greece",
75
    "spanish": "Spain",
76
    "mediterranean": "Italy",
77
    "thai": "Thailand",
78
    "indian": "India",
79
    "mexican": "Mexico",
80
}
81
CONF_HIGH = 1.0
82
CONF_MIDDLE = 0.95
83
CONF_LOW = 0.9
84
CONF_LOWEST = 0.8
85

86

87
class State(Enum):
88
    USR_START = auto()
89
    #
90
    SYS_WHAT_COOK = auto()
91
    SYS_WHAT_FAV_FOOD = auto()
92
    SYS_WHAT_CUISINE = auto()
93
    USR_WHAT_FAV_FOOD = auto()
94
    SYS_FAV_FOOD = auto()
95
    USR_WHAT_CUISINE = auto()
96
    SYS_CUISINE = auto()
97
    USR_CUISINE_FACT = auto()
98
    USR_HOW_ABOUT_MEAL1 = auto()
99
    SYS_YES_RECIPE = auto()
100
    SYS_NO_RECIPE1 = auto()
101
    SYS_NO_RECIPE2 = auto()
102
    USR_RECIPE = auto()
103
    USR_HOW_ABOUT_MEAL2 = auto()
104
    USR_GOURMET = auto()
105
    USR_FOOD_FACT = auto()
106
    SYS_YES_FOOD_FACT = auto()
107
    SYS_NO_FOOD_FACT = auto()
108
    SYS_SOMETHING = auto()
109
    USR_WHERE_R_U_FROM = auto()
110
    SYS_TO_TRAVEL_SKILL = auto()
111
    USR_COUNTRY = auto()
112
    SYS_BOT_PERSONA_FAV_FOOD = auto()
113
    SYS_SAID_FAV_FOOD = auto()
114
    SYS_CHECK_COOKING = auto()
115
    USR_SUGGEST_COOK = auto()
116
    SYS_YES_COOK = auto()
117
    SYS_NO_COOK = auto()
118
    SYS_ENSURE_FOOD = auto()
119
    SYS_LINKTO_PLUS_NO = auto()
120
    SYS_LINKTO_PLUS_NO_RECIPE = auto()
121
    SYS_MORE_FACTS = auto()
122
    #
123
    SYS_ERR = auto()
124
    USR_ERR = auto()
125

126

127
# %%
128

129
##################################################################################################################
130
# Init DialogFlow
131
##################################################################################################################
132

133

134
simplified_dialogflow = dialogflow_extension.DFEasyFilling(State.USR_START)
135

136
##################################################################################################################
137
##################################################################################################################
138
# Design DialogFlow.
139
##################################################################################################################
140
##################################################################################################################
141
##################################################################################################################
142
# yes
143
##################################################################################################################
144

145

146
def yes_request(ngrams, vars):
147
    flag = condition_utils.is_yes_vars(vars)
148
    logger.info(f"yes_request {flag}")
149
    return flag
150

151

152
##################################################################################################################
153
# no
154
##################################################################################################################
155

156

157
def no_request(ngrams, vars):
158
    flag = condition_utils.is_no_vars(vars)
159
    logger.info(f"no_request {flag}")
160
    return flag
161

162

163
def dont_want_talk(vars):
164
    utt = state_utils.get_last_human_utterance(vars)["text"]
165
    flag = bool(re.search(COMPILE_NOT_WANT_TO_TALK_ABOUT_IT, utt))
166
    logger.info(f"dont_want_talk {flag}")
167
    return flag
168

169

170
##################################################################################################################
171
# error
172
##################################################################################################################
173

174

175
def error_response(vars):
176
    state_utils.set_confidence(vars, 0)
177
    return "Sorry"
178

179

180
##################################################################################################################
181
# let's talk about food
182
##################################################################################################################
183

184

185
def is_question(vars):
186
    annotations_sentseg = state_utils.get_last_human_utterance(vars)["annotations"].get("sentseg", {})
187
    flag = "?" in annotations_sentseg.get("punct_sent", "")
188
    return flag
189

190

191
def check_conceptnet(vars):
192
    annotations_conceptnet = get_comet_conceptnet_annotations(state_utils.get_last_human_utterance(vars))
193
    conceptnet = False
194
    food_item = None
195
    for elem, triplets in annotations_conceptnet.items():
196
        symbol_of = triplets.get("SymbolOf", [])
197
        conceptnet_symbolof = any(
198
            [i in symbol_of for i in CONCEPTNET_SYMBOLOF_FOOD] + ["chicken" in i for i in symbol_of]
199
        )
200
        has_property = triplets.get("HasProperty", [])
201
        conceptnet_hasproperty = any([i in has_property for i in CONCEPTNET_HASPROPERTY_FOOD])
202
        causes_desire = triplets.get("CausesDesire", [])
203
        conceptnet_causesdesire = any(
204
            [i in causes_desire for i in CONCEPTNET_CAUSESDESIRE_FOOD]
205
            + ["eat" in i for i in causes_desire]
206
            + ["cook" in i for i in causes_desire]
207
            + ["food" in i for i in causes_desire]
208
        )
209
        conceptnet = any([conceptnet_symbolof, conceptnet_hasproperty, conceptnet_causesdesire])
210
        if conceptnet:
211
            food_item = elem
212
            return conceptnet, food_item
213
    return conceptnet, food_item
214

215

216
def lets_talk_about_check(vars):
217
    # user_lets_chat_about = (
218
    #     "lets_chat_about" in get_intents(state_utils.get_last_human_utterance(vars), which="intent_catcher")
219
    #     or if_chat_about_particular_topic(state_utils.get_last_human_utterance(vars), prev_uttr)
220
    # )
221
    human_utt = state_utils.get_last_human_utterance(vars)
222
    bot_utt = state_utils.get_last_bot_utterance(vars)
223
    # if "weather" in human_utt["text"].lower():
224
    #     flag = ""
225
    #     logger.info(f"lets_talk_about_check {flag}, weather detected")
226
    #     return flag
227
    if dont_want_talk(vars):
228
        flag = ""
229
    elif if_chat_about_particular_topic(human_utt, bot_utt, compiled_pattern=FOOD_WORDS_RE):
230
        flag = "if_chat_about_particular_topic"
231
    elif bool(re.search(FOOD_WORDS_RE, human_utt["text"])):
232
        flag = "FOOD_WORDS_RE"
233
    elif bool(re.search(FOOD_UTTERANCES_RE, bot_utt["text"])):
234
        flag = "FOOD_UTTERANCES_RE"
235
    elif bool(re.search(CUISINE_UTTERANCES_RE, bot_utt["text"])):
236
        flag = "CUISINE_UTTERANCES_RE"
237
    elif check_conceptnet(vars)[0]:
238
        flag = "check_conceptnet"
239
    elif bool(re.search(DONOTKNOW_LIKE_RE, human_utt["text"])):
240
        flag = "DONOTKNOW_LIKE_RE"
241
    else:
242
        flag = ""
243
    # user_lets_chat_about_food = any(
244
    #     [
245
    #         bool(re.search(FOOD_WORDS_RE, human_utt["text"].lower())),
246
    #         if_chat_about_particular_topic(human_utt, bot_utt, compiled_pattern=FOOD_WORDS_RE),
247
    #         check_conceptnet(vars)[0],
248
    #         bool(re.search(FOOD_SKILL_TRANSFER_PHRASES_RE, human_utt["text"].lower())),
249
    #         bool(re.search(DONOTKNOW_LIKE_RE, human_utt["text"].lower()))
250
    #     ]
251
    # )
252
    # and (not state_utils.get_last_human_utterance(vars)["text"].startswith("what"))
253
    # flag = user_lets_chat_about_food
254
    logger.info(f"lets_talk_about_check {flag}")
255
    return flag
256

257

258
def what_cuisine_response(vars):
259
    user_utt = state_utils.get_last_human_utterance(vars)
260
    bot_utt = state_utils.get_last_bot_utterance(vars)["text"].lower()
261
    banned_words = ["water"]
262
    linkto_food_skill_agreed = any([req.lower() in bot_utt for req in TRIGGER_PHRASES])
263
    lets_talk_about_asked = bool(lets_talk_about_check(vars))
264
    try:
265
        if not any([i in user_utt["text"].lower() for i in banned_words]):
266
            if linkto_food_skill_agreed:
267
                if is_yes(user_utt):
268
                    state_utils.set_confidence(vars, confidence=CONF_HIGH)
269
                    state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE)
270
                elif not is_no(user_utt):
271
                    state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
272
                    state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_PROMPT)
273
                elif is_no(user_utt):
274
                    state_utils.set_confidence(vars, confidence=CONF_HIGH)
275
                    state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
276
                    return ACKNOWLEDGEMENTS["cuisine"]
277
            elif lets_talk_about_asked:
278
                state_utils.set_confidence(vars, confidence=CONF_HIGH)
279
                state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE)
280
            else:
281
                state_utils.set_confidence(vars, confidence=CONF_LOW)
282
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
283
            return "I'm a fan of Mediterranean cuisine dishes. What cuisine do you prefer?"
284
    except Exception as exc:
285
        logger.exception(exc)
286
        sentry_sdk.capture_exception(exc)
287
        return error_response(vars)
288

289

290
def cuisine_request(ngrams, vars):
291
    # nounphr = get_entities(state_utils.get_last_human_utterance(vars), only_named=False, with_labels=False)
292
    # flag = bool(nounphr)
293
    utt = state_utils.get_last_human_utterance(vars)["text"].lower()
294
    spacy_utt = spacy_nlp(utt)
295
    utt_adj = any([w.pos_ == "ADJ" for w in spacy_utt])
296
    all_words = any([i in utt for i in ["all", "many", "multiple"]])
297
    flag = any([utt_adj, check_conceptnet(vars)[0], all_words]) and (
298
        not any([bool(re.search(NO_WORDS_RE, utt)), dont_want_talk(vars)])
299
    )
300
    logger.info(f"cuisine_request {flag}")
301
    return flag
302

303

304
def cuisine_fact_response(vars):
305
    cuisine_fact = ""
306
    try:
307
        state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
308
        last_utt = state_utils.get_last_human_utterance(vars)
309
        last_utt_lower = last_utt["text"].lower()
310
        conceptnet_flag, food_item = check_conceptnet(vars)
311
        if any([w.pos_ == "ADJ" for w in spacy_nlp(last_utt_lower)]):
312
            for cuisine in list(CUISINES_FACTS.keys()):
313
                if cuisine in last_utt_lower:
314
                    cuisine_fact = CUISINES_FACTS.get(cuisine, "")
315
                    state_utils.save_to_shared_memory(vars, cuisine=cuisine)
316
                    state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
317
                    return cuisine_fact
318
            if not cuisine_fact:
319
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
320
                response = "You have such a refined taste in food! "
321
                "I haven't tried it yet. What do you recommend to start with?"
322
                state_utils.add_acknowledgement_to_response_parts(vars)
323
                return response
324
        elif conceptnet_flag:
325
            entity_linking = last_utt["annotations"].get("entity_linking", [])
326
            if entity_linking:
327
                _facts = entity_linking[0].get("entity_pages", [])
328
                if _facts:
329
                    state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
330
                    response = f"You're a gourmet! I know about {food_item} that {_facts[0]}"
331
                    state_utils.add_acknowledgement_to_response_parts(vars)
332
                    return response
333
                else:
334
                    return ""
335
            else:
336
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
337
                return (
338
                    "My favorite cuisine is French. I'm just in love "
339
                    "with pastry, especially with profiteroles! How about you?"
340
                )
341
        else:
342
            state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
343
            return (
344
                "My favorite cuisine is French. I'm just in love "
345
                "with pastry, especially with profiteroles! How about you?"
346
            )
347
    except Exception as exc:
348
        logger.exception(exc)
349
        sentry_sdk.capture_exception(exc)
350
        return error_response(vars)
351

352

353
def country_response(vars):
354
    shared_memory = state_utils.get_shared_memory(vars)
355
    cuisine_discussed = shared_memory.get("cuisine", "")
356
    try:
357
        if cuisine_discussed:
358
            if cuisine_discussed in CUISINES_COUNTRIES:
359
                state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
360
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
361
                return f"Have you ever been in {CUISINES_COUNTRIES[cuisine_discussed]}?"
362
            else:
363
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
364
                return error_response(vars)
365
        else:
366
            state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
367
            return error_response(vars)
368
    except Exception as exc:
369
        logger.exception(exc)
370
        sentry_sdk.capture_exception(exc)
371
        return error_response(vars)
372

373

374
def to_travel_skill_request(ngrams, vars):
375
    flag = False
376
    shared_memory = state_utils.get_shared_memory(vars)
377
    cuisine_discussed = shared_memory.get("cuisine", "")
378
    if cuisine_discussed:
379
        if cuisine_discussed in CUISINES_COUNTRIES:
380
            flag = True
381
    logger.info(f"to_travel_skill_request {flag}")
382
    return flag
383

384

385
def what_fav_food_response(vars):
386
    food_types = {
387
        "food": [
388
            "lava cake",
389
            "This cake is delicious, decadent, addicting, divine, just so incredibly good!!!"
390
            " Soft warm chocolate cake outside giving way to a creamy, smooth stream of warm "
391
            "liquid chocolate inside, ensuring every forkful is bathed in velvety chocolate. "
392
            "It is my love at first bite.",
393
        ],
394
        "drink": [
395
            "orange juice",
396
            "Isually I drink it at breakfast - it’s sweet with natural sugar for quick energy."
397
            " Oranges have lots of vitamins and if you drink it with pulp, it has fiber. Also,"
398
            " oranges are rich in vitamin C that keeps your immune system healthy.",
399
        ],
400
        "fruit": [
401
            "mango",
402
            "Every year I wait for the summers so that I can lose myself in the aroma of perfectly"
403
            " ripened mangoes and devour its heavenly sweet taste. Some people prefer mangoes which"
404
            " are tangy and sour. However, I prefer sweet ones that taste like honey.",
405
        ],
406
        "dessert": [
407
            "profiteroles",
408
            "Cream puffs of the size of a hamburger on steroids, the two pate a choux ends"
409
            " showcased almost two cups of whipped cream - light, fluffy, and fresh. "
410
            "There is nothing better than choux pastry!",
411
        ],
412
        "vegetable": [
413
            "broccoli",
414
            "This hearty and tasty vegetable is rich in dozens of nutrients. It is said "
415
            "to pack the most nutritional punch of any vegetable. When I think about green"
416
            " vegetables to include in my diet, broccoli is one of the foremost veggies to "
417
            "come to my mind.",
418
        ],
419
        "berry": [
420
            "blueberry",
421
            "Fresh blueberries are delightful and have a slightly sweet taste that is mixed"
422
            " with a little bit of acid from the berry. When I bite down on a blueberry,"
423
            " I enjoy a burst of juice as the berry pops, and this juice is very sweet. "
424
            "Blueberries are the blues that make you feel good!",
425
        ],
426
        "snack": [
427
            "peanut butter",
428
            "It tastes great! Creamy, crunchy or beyond the jar, there is a special place "
429
            "among my taste receptors for that signature peanutty flavor. I always gravitate"
430
            " toward foods like peanut butter chocolate cheesecake, and peanut butter cottage"
431
            " cookies. There are so many peanut butter flavored items for all kinds of food products!"
432
            " Still, sometimes it’s best delivered on a spoon.",
433
        ],
434
    }
435
    user_utt = state_utils.get_last_human_utterance(vars)
436
    bot_utt = state_utils.get_last_bot_utterance(vars)["text"].lower()
437
    question = ""
438
    shared_memory = state_utils.get_shared_memory(vars)
439
    used_food = shared_memory.get("used_food", [])
440
    unused_food = []
441
    linkto_food_skill_agreed = any(
442
        [req.lower() in state_utils.get_last_bot_utterance(vars)["text"].lower() for req in TRIGGER_PHRASES]
443
    )
444
    lets_talk_about_asked = lets_talk_about_check(vars)
445
    try:
446
        if used_food:
447
            unused_food = [i for i in food_types.keys() if i not in used_food]
448
            if unused_food:
449
                food_type = random.choice(unused_food)
450
            else:
451
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
452
                return error_response(vars)
453
        else:
454
            food_type = "food"
455

456
        if linkto_food_skill_agreed:
457
            if is_yes(user_utt):
458
                if food_type == "food":
459
                    state_utils.set_confidence(vars, confidence=CONF_HIGH)
460
                    state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE)
461
                elif food_type == "snack":
462
                    state_utils.set_confidence(vars, confidence=CONF_LOWEST)
463
                    state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
464
                elif unused_food:
465
                    state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
466
                    state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
467
                else:
468
                    state_utils.set_confidence(vars, confidence=CONF_LOWEST)
469
                    state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
470

471
            elif not is_no(user_utt):
472
                state_utils.set_confidence(vars, confidence=CONF_LOW)
473
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
474
            elif is_no(user_utt):
475
                state_utils.set_confidence(vars, confidence=CONF_HIGH)
476
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
477
                return ACKNOWLEDGEMENTS["fav_food_cook"]
478

479
        elif bool(lets_talk_about_asked):
480
            if (food_type == "food") or (lets_talk_about_asked == "if_chat_about_particular_topic"):
481
                state_utils.set_confidence(vars, confidence=CONF_HIGH)
482
                state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE)
483
            elif food_type == "snack":
484
                state_utils.set_confidence(vars, confidence=CONF_LOWEST)
485
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
486
            elif unused_food:
487
                state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
488
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
489
            else:
490
                state_utils.set_confidence(vars, confidence=CONF_LOWEST)
491
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
492
        else:
493
            state_utils.set_confidence(vars, confidence=CONF_LOW)
494
            state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
495

496
        state_utils.save_to_shared_memory(vars, used_food=used_food + [food_type])
497
        fav_item = food_types.get(food_type, [])
498
        if fav_item:
499
            if food_type != "drink":
500
                if "what is your favorite food" in bot_utt:
501
                    question = f" What {food_type} do you like?"
502
                else:
503
                    question = " What is a typical meal from your country?"
504
                return f"I like to eat {fav_item[0]}. {fav_item[1]}" + question
505
            else:
506
                if "what is your favorite food" in bot_utt:
507
                    question = f" What {food_type} do you prefer?"
508
                else:
509
                    question = " What do you usually like to drink when you go out?"
510
                return f"I like to drink {fav_item[0]}. {fav_item[1]}" + question
511
        else:
512
            state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
513
            return error_response(vars)
514
    except Exception as exc:
515
        logger.exception(exc)
516
        sentry_sdk.capture_exception(exc)
517
        return error_response(vars)
518

519

520
def fav_food_check(vars):
521
    flag = False
522
    user_fav_food = get_entities(state_utils.get_last_human_utterance(vars), only_named=False, with_labels=False)
523
    # cobot_topic = "Food_Drink" in get_topics(state_utils.get_last_human_utterance(vars), which="cobot_topics")
524
    food_words_search = bool(re.search(FOOD_WORDS_RE, state_utils.get_last_human_utterance(vars)["text"]))
525
    if all(
526
        [
527
            any([user_fav_food, check_conceptnet(vars), food_words_search]),
528
            # condition_utils.no_requests(vars),
529
            not bool(re.search(NO_WORDS_RE, state_utils.get_last_human_utterance(vars)["text"])),
530
            not dont_want_talk(vars),
531
        ]
532
    ):
533
        flag = True
534
    logger.info(f"fav_food_check {flag}")
535
    return flag
536

537

538
def fav_food_request(ngrams, vars):
539
    flag = fav_food_check(vars)
540
    logger.info(f"fav_food_request {flag}")
541
    return flag
542

543

544
def food_fact_response(vars):
545
    human_utt = state_utils.get_last_human_utterance(vars)
546
    annotations = human_utt["annotations"]
547
    human_utt_text = human_utt["text"].lower()
548
    bot_utt_text = state_utils.get_last_bot_utterance(vars)["text"]
549
    shared_memory = state_utils.get_shared_memory(vars)
550
    used_facts = shared_memory.get("used_facts", [])
551

552
    fact = ""
553
    facts = []
554
    entity = ""
555
    berry_name = ""
556

557
    linkto_check = any([linkto in bot_utt_text for linkto in link_to_skill2i_like_to_talk["dff_food_skill"]])
558
    black_list_check = any(list(annotations.get("badlisted_words", {}).values()))
559
    conceptnet_flag, food_item = check_conceptnet(vars)
560

561
    entities_facts = annotations.get("fact_retrieval", {}).get("topic_facts", [])
562
    for entity_facts in entities_facts:
563
        if entity_facts["entity_type"] in ["food", "fruit", "vegetable", "berry"]:
564
            if entity_facts["facts"]:
565
                facts = entity_facts["facts"][0].get("sentences", [])
566
                entity = entity_facts["entity_substr"]
567
            else:
568
                facts = []
569

570
    if not facts:
571
        facts = annotations.get("fact_random", [])
572

573
    if black_list_check:
574
        state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
575
        return error_response(vars)
576
    elif conceptnet_flag and all(["shower" not in human_utt_text, " mela" not in human_utt_text]):
577
        if "berry" in bot_utt_text.lower():
578
            berry_names = get_entities(state_utils.get_last_human_utterance(vars), only_named=False, with_labels=False)
579
            if berry_names:
580
                berry_name = berry_names[0]
581

582
            if all(["berr" not in human_utt_text, len(human_utt_text.split()) == 1, berry_name]):
583
                berry_name += "berry"
584
                fact = get_fact(berry_name, f"fact about {berry_name}")
585
                entity = berry_name
586
            elif berry_name:
587
                if facts and entity:
588
                    fact = random.choice([i for i in facts if i not in used_facts])
589
                    # facts[0]
590
                elif facts:
591
                    for facts_item in facts:
592
                        if all(
593
                            [
594
                                facts_item.get("entity_substr", "xxx") in food_item,
595
                                facts_item.get("fact", "") not in used_facts,
596
                            ]
597
                        ):
598
                            fact = facts_item.get("fact", "")
599
                            entity = facts_item.get("entity_substr", "")
600
                            break
601
                        else:
602
                            fact = ""
603
                            entity = ""
604
        else:
605
            if all([facts, entity, entity in food_item]):
606
                fact = random.choice([i for i in facts if i not in used_facts])
607
                # facts[0]
608
            elif facts and not entity:
609
                for facts_item in facts:
610
                    if all(
611
                        [
612
                            facts_item.get("entity_substr", "xxx") in food_item,
613
                            facts_item.get("fact", "") not in used_facts,
614
                        ]
615
                    ):
616
                        fact = facts_item.get("fact", "")
617
                        entity = facts_item.get("entity_substr", "")
618
                        break
619
                    else:
620
                        fact = ""
621
                        entity = ""
622
            else:
623
                fact = ""
624
                entity = ""
625
        acknowledgement = random.choice(FOOD_FACT_ACKNOWLEDGEMENTS).replace("ENTITY", entity.lower())
626
        state_utils.save_to_shared_memory(vars, used_facts=used_facts + [fact])
627

628
        try:
629
            if bot_persona_fav_food_check(vars) or len(state_utils.get_last_human_utterance(vars)["text"].split()) == 1:
630
                state_utils.set_confidence(vars, confidence=CONF_HIGH)
631
            else:
632
                state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
633
            if bool(re.search(DONOTKNOW_LIKE_RE, human_utt_text)):
634
                state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
635
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
636
                return "Well, as for me, I am a fan of pizza despite I cannot eat as humans."
637
            elif any([dont_want_talk(vars), bool(re.search(NO_WORDS_RE, human_utt_text))]):
638
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
639
                return error_response(vars)
640
            elif (not fact) and conceptnet_flag:
641
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
642
                return "Why do you like it?"
643
            elif not fact:
644
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
645
                return error_response(vars)
646
            elif fact and entity:
647
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
648
                if len(used_facts):
649
                    return f"{fact} Do you want me to tell you more about {entity}?"
650
                else:
651
                    response = acknowledgement + f"{fact} Do you want to hear more about {entity}?"
652
                    state_utils.add_acknowledgement_to_response_parts(vars)
653
                    return response
654
            elif fact:
655
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
656
                if len(used_facts):
657
                    return f"{fact} Do you want me to tell you more about {entity}?"
658
                else:
659
                    return f"Okay. {fact} I can share with you one more cool fact. Do you agree?"
660
            elif linkto_check:
661
                state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
662
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
663
                return "Sorry. I didn't get what kind of food you have mentioned. Could you repeat it please?"
664
            else:
665
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
666
                return error_response(vars)
667
        except Exception as exc:
668
            logger.exception(exc)
669
            sentry_sdk.capture_exception(exc)
670
            return error_response(vars)
671
    elif linkto_check:
672
        state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
673
        state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
674
        return "Sorry. I didn't get what kind of food you have mentioned. Could you repeat it please?"
675
    else:
676
        state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
677
        return error_response(vars)
678

679

680
def more_facts_request(ngrams, vars):
681
    shared_memory = state_utils.get_shared_memory(vars)
682
    used_facts = shared_memory.get("used_facts", [])
683

684
    flag = all([bool(len(used_facts)), condition_utils.no_special_switch_off_requests(vars), yes_request(ngrams, vars)])
685
    logger.info(f"more_facts_request {flag}")
686
    return flag
687

688

689
def are_you_gourmet_response(vars):
690
    try:
691
        state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
692
        state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
693
        return "Are you a gourmet?"
694
    except Exception as exc:
695
        logger.exception(exc)
696
        sentry_sdk.capture_exception(exc)
697
        return error_response(vars)
698

699

700
##################################################################################################################
701
# what to cook
702
##################################################################################################################
703

704

705
def what_cook_request(ngrams, vars):
706
    what_cook_re_search = re.search(WHAT_COOK_RE, state_utils.get_last_human_utterance(vars)["text"])
707
    flag = bool(what_cook_re_search)
708
    logger.info(f"what_cook_request {flag}")
709
    return flag
710

711

712
def how_about_meal_response(vars):
713
    shared_memory = state_utils.get_shared_memory(vars)
714
    used_meals = shared_memory.get("used_meals", "")
715
    meal = random.choice([i for i in MEALS if i != used_meals])
716
    try:
717
        state_utils.set_confidence(vars, confidence=CONF_HIGH)
718
        state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE)
719
        # first attempt to suggest a meal
720
        state_utils.save_to_shared_memory(vars, used_meals=meal)
721
        if not used_meals:
722
            return f"I've recently found a couple easy and healthy meals. How about cooking {meal}?"
723
        else:
724
            return f"Okay. Give me one more chance. I recommend {meal}."
725
    except Exception as exc:
726
        logger.exception(exc)
727
        sentry_sdk.capture_exception(exc)
728
        return error_response(vars)
729

730

731
def recipe_response(vars):
732
    try:
733
        shared_memory = state_utils.get_shared_memory(vars)
734
        used_meal = shared_memory.get("used_meals", "")
735
        recipe = get_fact(used_meal, f"how to cook {used_meal}")
736
        state_utils.set_confidence(vars, confidence=CONF_HIGH)
737
        if not (used_meal and recipe):
738
            state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
739
            recipe = "Great! Enjoy your meal!"
740
        else:
741
            state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_PROMPT)
742
        return recipe
743
    except Exception as exc:
744
        logger.exception(exc)
745
        sentry_sdk.capture_exception(exc)
746
        return error_response(vars)
747

748

749
def gourmet_response(vars):
750
    try:
751
        state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
752
        state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_PROMPT)
753
        response = "It seems you're a gourmet! What meal do you like?"
754
        state_utils.add_acknowledgement_to_response_parts(vars)
755
        return response
756
    except Exception as exc:
757
        logger.exception(exc)
758
        sentry_sdk.capture_exception(exc)
759
        return error_response(vars)
760

761

762
def smth_request(ngrams, vars):
763
    flag = condition_utils.no_requests(vars) and (not dont_want_talk(vars))
764
    logger.info(f"smth_request {flag}")
765
    return flag
766

767

768
def smth_random_request(ngrams, vars):
769
    flag = condition_utils.no_requests(vars)
770
    flag = flag and random.choice([True, False])
771
    logger.info(f"smth_random_request {flag}")
772
    return flag
773

774

775
def where_are_you_from_response(vars):
776
    try:
777
        state_utils.set_confidence(vars, confidence=CONF_LOW)
778
        state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
779
        return "Where are you from?"
780
    except Exception as exc:
781
        logger.exception(exc)
782
        sentry_sdk.capture_exception(exc)
783
        return error_response(vars)
784

785

786
def suggest_cook_response(vars):
787
    user_utt = state_utils.get_last_human_utterance(vars)
788
    try:
789
        linkto_food_skill_agreed = any(
790
            [req.lower() in state_utils.get_last_bot_utterance(vars)["text"].lower() for req in TRIGGER_PHRASES]
791
        )
792
        if linkto_food_skill_agreed:
793
            if is_yes(user_utt) or bool(re.search(LIKE_RE, user_utt["text"].lower())):
794
                state_utils.set_confidence(vars, confidence=CONF_HIGH)
795
                state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE)
796
            elif not is_no(user_utt):
797
                state_utils.set_confidence(vars, confidence=CONF_MIDDLE)
798
                state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO)
799
            elif is_no(user_utt):
800
                state_utils.set_confidence(vars, confidence=CONF_HIGH)
801
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
802
                return ACKNOWLEDGEMENTS["fav_food_cook"]
803
            else:
804
                state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
805
                return error_response(vars)
806
            return "May I recommend you a meal to try to practice cooking?"
807
        else:
808
            state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE)
809
            return error_response(vars)
810
    except Exception as exc:
811
        logger.exception(exc)
812
        sentry_sdk.capture_exception(exc)
813
        return error_response(vars)
814

815

816
def what_fav_food_request(ngrams, vars):
817
    food_topic_checked = lets_talk_about_check(vars)
818
    food_1st_time = condition_utils.is_first_time_of_state(vars, State.SYS_WHAT_FAV_FOOD)
819
    cuisine_1st_time = condition_utils.is_first_time_of_state(vars, State.SYS_WHAT_CUISINE)
820
    if any([not bool(food_topic_checked), food_topic_checked == "CUISINE_UTTERANCES_RE", dont_want_talk(vars)]):
821
        flag = False
822
    elif (food_topic_checked == "FOOD_UTTERANCES_RE") or (food_topic_checked == "if_chat_about_particular_topic"):
823
        flag = True
824
    elif food_1st_time and cuisine_1st_time:
825
        flag = random.choice([True, False])
826
    elif food_1st_time or (not cuisine_1st_time):
827
        flag = True
828
    else:
829
        flag = False
830
    logger.info(f"what_fav_food_request {flag}")
831
    return flag
832

833

834
def check_cooking_request(ngrams, vars):
835
    linkto_food_skill_agreed = any(
836
        [req.lower() in state_utils.get_last_bot_utterance(vars)["text"].lower() for req in TRIGGER_PHRASES]
837
    ) and any(
838
        [
839
            is_yes(state_utils.get_last_human_utterance(vars)),
840
            not is_no(state_utils.get_last_human_utterance(vars)),
841
            bool(re.search(LIKE_RE, state_utils.get_last_human_utterance(vars)["text"].lower())),
842
        ]
843
    )
844
    if linkto_food_skill_agreed:
845
        flag = True
846
    else:
847
        flag = False
848
    logger.info(f"check_cooking_request {flag}")
849
    return flag
850

851

852
def said_fav_food_request(ngrams, vars):
853
    flag = False
854
    user_utt_text = state_utils.get_last_human_utterance(vars)["text"]
855
    bot_utt_text = state_utils.get_last_bot_utterance(vars)["text"]
856
    food_topic_checked = lets_talk_about_check(vars)
857
    # fav_in_bot_utt = bool(re.search(FAV_RE, state_utils.get_last_bot_utterance(vars)["text"]))
858
    food_checked = any([bool(re.search(FOOD_WORDS_RE, user_utt_text)), check_conceptnet(vars)[0]])
859
    linkto_check = any([linkto in bot_utt_text for linkto in link_to_skill2i_like_to_talk["dff_food_skill"]])
860
    if any(
861
        [
862
            dont_want_talk(vars),
863
            food_topic_checked == "FOOD_UTTERANCES_RE",
864
            food_topic_checked == "if_chat_about_particular_topic",
865
        ]
866
    ):
867
        flag = False
868
    # (fav_in_bot_utt and
869
    elif linkto_check or food_checked:
870
        flag = True
871
    else:
872
        flag = False
873
    logger.info(f"said_fav_food_request {flag}")
874
    return flag
875

876

877
def bot_persona_fav_food_check(vars):
878
    flag = False
879
    if all(
880
        [
881
            "my favorite food is lava cake" in state_utils.get_last_bot_utterance(vars)["text"].lower(),
882
            fav_food_check(vars),
883
        ]
884
    ):
885
        flag = True
886
    logger.info(f"bot_persona_fav_food_check {flag}")
887
    return flag
888

889

890
def bot_persona_fav_food_request(ngrams, vars):
891
    flag = bot_persona_fav_food_check(vars)
892
    logger.info(f"bot_persona_fav_food_request {flag}")
893
    return flag
894

895

896
def what_cuisine_request(ngrams, vars):
897
    linkto_food_skill_agreed = any(
898
        [req.lower() in state_utils.get_last_bot_utterance(vars)["text"].lower() for req in TRIGGER_PHRASES]
899
    ) and any(
900
        [is_yes(state_utils.get_last_human_utterance(vars)), not is_no(state_utils.get_last_human_utterance(vars))]
901
    )
902
    flag = (bool(lets_talk_about_check(vars)) or linkto_food_skill_agreed) and (not dont_want_talk(vars))
903
    logger.info(f"what_cuisine_request {flag}")
904
    return flag
905

906

907
def ensure_food_request(ngrams, vars):
908
    flag = "I didn't get what kind of food have you mentioned" in state_utils.get_last_bot_utterance(vars)["text"]
909
    logger.info(f"ensure_food_request {flag}")
910
    return flag
911

912

913
def linkto_plus_no_request(ngrams, vars):
914
    bot_utt = state_utils.get_last_bot_utterance(vars)["text"]
915
    flag = any([ackn in bot_utt for ackn in ACKNOWLEDGEMENTS.values()])
916
    flag = flag and condition_utils.no_special_switch_off_requests(vars)
917
    logger.info(f"linkto_plus_no_request {flag}")
918
    return flag
919

920

921
##################################################################################################################
922
##################################################################################################################
923
# linking
924
##################################################################################################################
925
##################################################################################################################
926

927

928
##################################################################################################################
929
#  START
930

931

932
simplified_dialogflow.add_user_serial_transitions(
933
    State.USR_START,
934
    {
935
        State.SYS_WHAT_COOK: what_cook_request,
936
        State.SYS_BOT_PERSONA_FAV_FOOD: bot_persona_fav_food_request,
937
        State.SYS_CHECK_COOKING: check_cooking_request,
938
        State.SYS_SAID_FAV_FOOD: said_fav_food_request,
939
        State.SYS_WHAT_FAV_FOOD: what_fav_food_request,
940
        State.SYS_WHAT_CUISINE: what_cuisine_request,
941
    },
942
)
943
simplified_dialogflow.set_error_successor(State.USR_START, State.SYS_ERR)
944

945
##################################################################################################################
946

947
simplified_dialogflow.add_system_transition(State.SYS_SAID_FAV_FOOD, State.USR_FOOD_FACT, food_fact_response)
948
simplified_dialogflow.set_error_successor(State.SYS_SAID_FAV_FOOD, State.SYS_ERR)
949

950

951
simplified_dialogflow.add_system_transition(State.SYS_CHECK_COOKING, State.USR_SUGGEST_COOK, suggest_cook_response)
952
simplified_dialogflow.set_error_successor(State.SYS_CHECK_COOKING, State.SYS_ERR)
953

954

955
simplified_dialogflow.add_user_serial_transitions(
956
    State.USR_SUGGEST_COOK,
957
    {State.SYS_YES_COOK: yes_request, State.SYS_NO_COOK: no_request, State.SYS_LINKTO_PLUS_NO: linkto_plus_no_request},
958
)
959
simplified_dialogflow.set_error_successor(State.USR_SUGGEST_COOK, State.SYS_ERR)
960

961

962
simplified_dialogflow.add_system_transition(State.SYS_YES_COOK, State.USR_HOW_ABOUT_MEAL1, how_about_meal_response)
963
simplified_dialogflow.set_error_successor(State.SYS_YES_COOK, State.SYS_ERR)
964

965

966
simplified_dialogflow.add_system_transition(State.SYS_NO_COOK, State.USR_WHAT_FAV_FOOD, what_fav_food_response)
967
simplified_dialogflow.set_error_successor(State.SYS_NO_COOK, State.SYS_ERR)
968

969

970
simplified_dialogflow.add_system_transition(State.SYS_WHAT_FAV_FOOD, State.USR_WHAT_FAV_FOOD, what_fav_food_response)
971
simplified_dialogflow.set_error_successor(State.SYS_WHAT_FAV_FOOD, State.SYS_ERR)
972

973

974
simplified_dialogflow.add_system_transition(State.SYS_BOT_PERSONA_FAV_FOOD, State.USR_FOOD_FACT, food_fact_response)
975
simplified_dialogflow.set_error_successor(State.SYS_BOT_PERSONA_FAV_FOOD, State.SYS_ERR)
976

977

978
simplified_dialogflow.add_system_transition(State.SYS_WHAT_CUISINE, State.USR_WHAT_CUISINE, what_cuisine_response)
979
simplified_dialogflow.set_error_successor(State.SYS_WHAT_CUISINE, State.SYS_ERR)
980

981

982
simplified_dialogflow.add_user_serial_transitions(
983
    State.USR_WHAT_FAV_FOOD,
984
    {State.SYS_FAV_FOOD: fav_food_request, State.SYS_LINKTO_PLUS_NO_RECIPE: linkto_plus_no_request},
985
)
986
simplified_dialogflow.set_error_successor(State.USR_WHAT_FAV_FOOD, State.SYS_ERR)
987

988

989
simplified_dialogflow.add_system_transition(
990
    State.SYS_LINKTO_PLUS_NO_RECIPE, State.USR_SUGGEST_COOK, suggest_cook_response
991
)
992
simplified_dialogflow.set_error_successor(State.SYS_LINKTO_PLUS_NO_RECIPE, State.SYS_ERR)
993

994

995
simplified_dialogflow.add_user_serial_transitions(
996
    State.USR_WHAT_CUISINE,
997
    {State.SYS_CUISINE: cuisine_request, State.SYS_LINKTO_PLUS_NO: linkto_plus_no_request},
998
)
999
simplified_dialogflow.set_error_successor(State.USR_WHAT_CUISINE, State.SYS_ERR)
1000

1001

1002
simplified_dialogflow.add_system_transition(State.SYS_CUISINE, State.USR_CUISINE_FACT, cuisine_fact_response)
1003
simplified_dialogflow.set_error_successor(State.SYS_CUISINE, State.SYS_ERR)
1004

1005

1006
simplified_dialogflow.add_system_transition(State.SYS_LINKTO_PLUS_NO, State.USR_WHAT_FAV_FOOD, what_fav_food_response)
1007
simplified_dialogflow.set_error_successor(State.SYS_LINKTO_PLUS_NO, State.SYS_ERR)
1008

1009

1010
simplified_dialogflow.add_user_serial_transitions(
1011
    State.USR_CUISINE_FACT,
1012
    {State.SYS_TO_TRAVEL_SKILL: to_travel_skill_request, State.USR_WHAT_FAV_FOOD: what_fav_food_response},
1013
)
1014
simplified_dialogflow.set_error_successor(State.USR_CUISINE_FACT, State.SYS_ERR)
1015

1016

1017
simplified_dialogflow.add_system_transition(State.SYS_TO_TRAVEL_SKILL, State.USR_COUNTRY, country_response)
1018
simplified_dialogflow.set_error_successor(State.SYS_TO_TRAVEL_SKILL, State.SYS_ERR)
1019

1020

1021
simplified_dialogflow.add_user_transition(State.USR_COUNTRY, State.SYS_SOMETHING, smth_request)
1022
simplified_dialogflow.set_error_successor(State.USR_COUNTRY, State.SYS_ERR)
1023

1024
##################################################################################################################
1025
#  SYS_WHAT_COOK
1026

1027
simplified_dialogflow.add_system_transition(State.SYS_WHAT_COOK, State.USR_HOW_ABOUT_MEAL1, how_about_meal_response)
1028
simplified_dialogflow.set_error_successor(State.SYS_WHAT_COOK, State.SYS_ERR)
1029

1030

1031
simplified_dialogflow.add_user_serial_transitions(
1032
    State.USR_HOW_ABOUT_MEAL1,
1033
    {
1034
        State.SYS_YES_RECIPE: yes_request,
1035
        State.SYS_NO_RECIPE1: no_request,
1036
    },
1037
)
1038
simplified_dialogflow.set_error_successor(State.USR_HOW_ABOUT_MEAL1, State.SYS_ERR)
1039

1040

1041
simplified_dialogflow.add_system_transition(State.SYS_YES_RECIPE, State.USR_RECIPE, recipe_response)
1042
simplified_dialogflow.set_error_successor(State.SYS_YES_RECIPE, State.SYS_ERR)
1043

1044

1045
simplified_dialogflow.add_user_transition(State.USR_RECIPE, State.SYS_SOMETHING, smth_request)
1046
simplified_dialogflow.set_error_successor(State.USR_RECIPE, State.SYS_ERR)
1047

1048

1049
simplified_dialogflow.add_system_transition(State.SYS_NO_RECIPE1, State.USR_HOW_ABOUT_MEAL2, how_about_meal_response)
1050
simplified_dialogflow.set_error_successor(State.SYS_NO_RECIPE1, State.SYS_ERR)
1051

1052

1053
simplified_dialogflow.add_user_serial_transitions(
1054
    State.USR_HOW_ABOUT_MEAL2,
1055
    {
1056
        State.SYS_YES_RECIPE: yes_request,
1057
        State.SYS_NO_RECIPE2: no_request,
1058
    },
1059
)
1060
simplified_dialogflow.set_error_successor(State.USR_HOW_ABOUT_MEAL2, State.SYS_ERR)
1061

1062

1063
simplified_dialogflow.add_system_transition(State.SYS_NO_RECIPE2, State.USR_GOURMET, gourmet_response)
1064
simplified_dialogflow.set_error_successor(State.SYS_NO_RECIPE2, State.SYS_ERR)
1065

1066

1067
simplified_dialogflow.add_user_transition(State.USR_GOURMET, State.SYS_FAV_FOOD, fav_food_request)
1068
simplified_dialogflow.set_error_successor(State.USR_GOURMET, State.SYS_ERR)
1069

1070

1071
simplified_dialogflow.add_system_transition(State.SYS_FAV_FOOD, State.USR_FOOD_FACT, food_fact_response)
1072
simplified_dialogflow.set_error_successor(State.SYS_FAV_FOOD, State.SYS_ERR)
1073

1074

1075
simplified_dialogflow.add_user_serial_transitions(
1076
    State.USR_FOOD_FACT,
1077
    {
1078
        State.SYS_ENSURE_FOOD: ensure_food_request,
1079
        State.SYS_MORE_FACTS: more_facts_request,
1080
        State.SYS_SOMETHING: smth_random_request,
1081
        (scopes.FAST_FOOD, FFState.USR_START): fast_food_request,
1082
    },
1083
)
1084
simplified_dialogflow.set_error_successor(State.USR_FOOD_FACT, State.SYS_ERR)
1085

1086

1087
simplified_dialogflow.add_system_transition(State.SYS_MORE_FACTS, State.USR_FOOD_FACT, food_fact_response)
1088
simplified_dialogflow.set_error_successor(State.SYS_MORE_FACTS, State.SYS_ERR)
1089

1090

1091
simplified_dialogflow.add_system_transition(State.SYS_ENSURE_FOOD, State.USR_FOOD_FACT, food_fact_response)
1092
simplified_dialogflow.set_error_successor(State.SYS_ENSURE_FOOD, State.SYS_ERR)
1093

1094

1095
simplified_dialogflow.add_system_transition(State.SYS_SOMETHING, State.USR_WHAT_FAV_FOOD, what_fav_food_response)
1096
simplified_dialogflow.set_error_successor(State.SYS_SOMETHING, State.SYS_ERR)
1097

1098
#################################################################################################################
1099
#  SYS_ERR
1100
simplified_dialogflow.add_system_transition(
1101
    State.SYS_ERR,
1102
    (scopes.MAIN, scopes.State.USR_ROOT),
1103
    error_response,
1104
)
1105
dialogflow = simplified_dialogflow.get_dialogflow()
1106

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.