def confess_bot_never_played_game_and_ask_user_response( vars, candidate_game_id_is_already_set, did_user_play=False, how_long_user_played=False): if not (isinstance(did_user_play, bool) and isinstance(how_long_user_played, bool) and did_user_play + how_long_user_played == 1): raise ValueError( f"One of parameters `did_user_play` and `how_long_user_played` has to be `True` and the other" f"has to be `False`. did_user_play={did_user_play}, how_long_user_played={how_long_user_played}" ) gaming_memory.set_current_igdb_game_id_if_game_for_discussion_is_identified( vars, candidate_game_id_is_already_set) game = gaming_memory.get_current_igdb_game(vars, assert_not_empty=False) if game is None: logger.warning( "No appropriate igdb game description were found. Game description could be filtered because it lacked " "required keys. Another cause possible cause of this situation is that local igdb saved search results " "do not have detected game. In such a case you should update local copy of igdb.com search results." ) response = error_response(vars) state_utils.set_confidence(vars, confidence=common_nlg.CONF_0) state_utils.set_can_continue( vars, continue_flag=common_constants.CAN_NOT_CONTINUE) else: if "genres" not in game or not game["genres"]: logger.warning(f"No genre for game '{game['name']}'.") genres = "" elif len(game["genres"]) == 1: genres = IGDB_GAME_GENRES_FOR_REPLICAS[game["genres"][0]] else: genres = ( f"{IGDB_GAME_GENRES_FOR_REPLICAS[game['genres'][0]]} " f"and {IGDB_GAME_GENRES_FOR_REPLICAS[game['genres'][1]]}") response = f"I've heard it is a cool {genres}. Unfortunately, I haven't tried it out. " if did_user_play: response += f"Have you ever played {game['name']}?" elif how_long_user_played: response += f"When did you start to play {game['name']}?" else: assert False bot_text = state_utils.get_last_bot_utterance(vars).get("text", "").lower() human_uttr = state_utils.get_last_human_utterance(vars) flags_set = False if not if_chat_about_particular_topic( human_uttr, compiled_pattern= GAMES_WITH_AT_LEAST_1M_COPIES_SOLD_COMPILED_PATTERN): flags_set, response = common_nlg.maybe_set_confidence_and_continue_based_on_previous_bot_phrase( vars, bot_text, response) if not flags_set: state_utils.set_confidence(vars, confidence=common_nlg.CONF_1) state_utils.set_can_continue( vars, continue_flag=common_constants.MUST_CONTINUE) return response
def where_are_you_from_response(vars): try: state_utils.set_confidence(vars, confidence=CONF_LOW) state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE) return "Where are you from?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) return error_response(vars)
def are_you_gourmet_response(vars): try: state_utils.set_confidence(vars, confidence=CONF_MIDDLE) state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_SCENARIO) return "Are you a gourmet?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) return error_response(vars)
def wikihow_step_response(vars): shared_memory = state_utils.get_shared_memory(vars) wikihow_article = shared_memory.get("wikihow_article", "") prev_wikihow_title = shared_memory.get("prev_wikihow_title", "") used_wikihow_titles = shared_memory.get("used_wikihow_titles", []) found_title = "" facts_str = "" question = "" if wikihow_article: article_content = get_wikihow_content(wikihow_article) if article_content: all_page_titles = article_content.keys() for title in all_page_titles: if title not in used_wikihow_titles and title != "intro": found_title = title break if prev_wikihow_title: paragraphs = article_content[prev_wikihow_title] if paragraphs: paragraph = paragraphs[0] sentences = nltk.sent_tokenize(paragraph) sentences_list = [] cur_len = 0 max_len = 50 for sentence in sentences: words = nltk.word_tokenize(sentence) if cur_len + len(words) < max_len: sentences_list.append(sentence) cur_len += len(words) if sentences_list: facts_str = " ".join(sentences_list) logger.info( f"wikihow_step_response, sentences_list {sentences_list} facts_str {facts_str}" ) if found_title: question = f"Would you like to know about {found_title.lower()}?" logger.info( f"wikihow_step_response found_title {found_title} prev_wikihow_title {prev_wikihow_title}" ) response = f"{facts_str} {question}" response = response.strip() if found_title: state_utils.save_to_shared_memory(vars, prev_wikihow_title=found_title) used_wikihow_titles.append(found_title) state_utils.save_to_shared_memory( vars, used_wikihow_titles=used_wikihow_titles) if response: state_utils.set_confidence(vars, confidence=CONF_DICT["IN_SCENARIO"]) state_utils.set_can_continue( vars, continue_flag=common_constants.CAN_CONTINUE_SCENARIO) else: state_utils.set_confidence(vars, confidence=CONF_DICT["UNDEFINED"]) state_utils.set_can_continue( vars, continue_flag=common_constants.CAN_NOT_CONTINUE) return response
def check_later_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Oh, i will definitely check it out later." except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def concert_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Have you been to any live shows lately?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def dont_know_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Never heard about it. Is it a band, song, or a genre?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def taste_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Well, you can check them out later, but I must warn you that I have a very specific taste." except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def cool_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "So cool that we have the same taste in music!" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def social_mode_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "I am sorry, I am currently running in a social mode. You can ask me to do this after our talk." except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def prefer_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "I prefer electronic music, like Aphex Twin or Kraftwerk. Do you like them?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def want_play_music_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Do you want me to play music?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def what_music_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Sure. Which music do you like?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def concert_who_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Who was it?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def what_wild_response(vars): make_my_pets_info(vars) what_i_like = random.choice(WILD_ANIMALS) response = f"{what_i_like} What wild animals do you like?" state_utils.save_to_shared_memory(vars, start=True) state_utils.save_to_shared_memory(vars, what_wild=True) state_utils.set_confidence(vars, confidence=CONF_1) state_utils.set_can_continue(vars, continue_flag=common_constants.MUST_CONTINUE) return response
def heard_latest_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Have you been listening to it lately?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def concert_covid_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "There wasn't much going on due to CoVID-19. Hope we will get some in future." except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def no_science_response(vars): try: state_utils.set_confidence(vars, confidence=CONF_100) state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE) state_utils.save_to_shared_memory(vars, current_status="") return "Okay, if I'm always ready to talk about science, the achievements of humanity inspire me. " except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) return error_response(vars)
def end_response(vars): try: state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE) return "" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def thanks_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Thank you, I will check it out." except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def it_ok_response(vars): try: state_utils.set_confidence(vars, CAN_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=CAN_NOT_CONTINUE) return "Don't worry. What do you want to talk about then?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def concert_known_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "Oh, sounds familiar. Guess I've seen their live online." except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)
def start_talk_response(vars): used_titles = [] dialog = vars["agent"]["dialog"] found_entity_substr, found_entity_id, found_entity_types, found_page_title, _ = continue_after_topic_skill( dialog) page_content, _ = get_page_content(found_page_title) found_entity_substr_list = [found_entity_substr] found_entity_types_list = [list(found_entity_types)] curr_pages = [found_page_title] chosen_title, chosen_page_title = get_title_info(vars, found_entity_substr, found_entity_types, "", [], page_content) titles_q, titles_we_use, all_titles = get_titles(found_entity_substr, found_entity_types, page_content) question = "" if chosen_title: question = make_question(chosen_title, titles_q, found_entity_substr, []) chosen_title, chosen_page_title = choose_title(vars, all_titles, titles_we_use, "", [], curr_pages) response = question.strip() if chosen_title: used_titles.append(chosen_title) save_wiki_vars( vars, found_entity_substr_list, curr_pages, chosen_title, chosen_page_title, used_titles, found_entity_types_list, False, ) cross_link = state_utils.get_cross_link(vars, service_name="dff_wiki_skill") from_skill = cross_link.get("from_service", "") if from_skill: state_utils.save_to_shared_memory(vars, interrupted_skill=from_skill) if response: state_utils.save_to_shared_memory(vars, start=True) state_utils.set_confidence(vars, confidence=CONF_DICT["ENTITY_IN_HISTORY"]) if from_skill: state_utils.set_can_continue( vars, continue_flag=common_constants.MUST_CONTINUE) else: state_utils.set_can_continue( vars, continue_flag=common_constants.CAN_CONTINUE_PROMPT) else: state_utils.set_confidence(vars, confidence=CONF_DICT["UNDEFINED"]) state_utils.set_can_continue( vars, continue_flag=common_constants.CAN_NOT_CONTINUE) return response
def do_you_have_pets_response(vars): response = random.choice([ "I think that pets are a great source of entertainment. Do you have pets at home?", "We all know that pets are remarkable for their capacity to love. Do you have pets " "at home?", ]) state_utils.save_to_shared_memory(vars, asked_have_pets=True) state_utils.set_confidence(vars, confidence=CONF_1) state_utils.set_can_continue(vars, continue_flag=common_constants.MUST_CONTINUE) return response
def suggest_pet_response(vars): phrases = [ phrase for pet_phrases in CATS_DOGS_PHRASES.values() for phrase in pet_phrases ] response = random.choice(phrases) state_utils.save_to_shared_memory(vars, start=True) state_utils.set_confidence(vars, confidence=CONF_2) state_utils.set_can_continue( vars, continue_flag=common_constants.CAN_CONTINUE_SCENARIO) return response
def ask_advice(vars): game = gaming_memory.get_current_igdb_game(vars) response = ( f"Could you give me an advice? I like games in which I can create something and " f"my favorite game is Minecraft. Would you recommend me to try {game['name']}?" ) state_utils.set_confidence(vars, confidence=common_nlg.CONF_092_CAN_CONTINUE) state_utils.set_can_continue( vars, continue_flag=common_constants.CAN_CONTINUE_SCENARIO) return response
def top_favs_response(vars): try: state_utils.set_confidence(vars, confidence=CONF_LOW) state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_PROMPT) return "What are your top three favorite things in the world?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, 0) return error_response(vars)
def gourmet_response(vars): try: state_utils.set_confidence(vars, confidence=CONF_MIDDLE) state_utils.set_can_continue(vars, continue_flag=CAN_CONTINUE_PROMPT) response = "It seems you're a gourmet! What meal do you like?" state_utils.add_acknowledgement_to_response_parts(vars) return response except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) return error_response(vars)
def tell_how_to_and_ask_if_it_was_interesting_response(vars): how_to_index = state_utils.get_shared_memory(vars).get( "current_how_to_index") assert how_to_index is not None, ( "The shared memory field `current_how_to_index` should have been filled on one " "of previous turns") state_utils.set_confidence(vars, confidence=common_nlg.CONF_1) state_utils.set_can_continue(vars, continue_flag=common_constants.MUST_CONTINUE) shared_memory_ops.add_how_to_index_to_used_how_to_indices( vars, how_to_index) return MINECRAFT_HOW_TOS[how_to_index]["answer"] + " Was it interesting?"
def ask_advice_response(vars): try: state_utils.set_confidence(vars, MUST_CONTINUE_CONFIDENCE) state_utils.set_can_continue(vars, continue_flag=MUST_CONTINUE) return "You know, I often feel myself overwhelmed with everything. \ Can you suggest me something relaxing to listen to?" except Exception as exc: logger.exception(exc) sentry_sdk.capture_exception(exc) state_utils.set_confidence(vars, CANNOT_CONTINUE_CONFIDENCE) return error_response(vars)