def what_word(turn: DialogTurn): word = turn.user_object.get('word') if word: turn.response_text = f'Вы говорили о слове {word}' turn.next_stage = 'word' else: turn.response_text = 'Вы ещё не искали синонимы'
def repeat(turn: DialogTurn): prev = turn.user_object.get('prev') if not prev: turn.response_text = 'Не поняла, что повторять' else: turn.response_text = f"<text>{prev['text']}</text><voice>{prev['voice']}</voice>" turn.suggests = prev['suggests'] turn.next_stage = prev['stage']
def make_synonym_response(turn: DialogTurn, word=None): if not word: word = turn.text if not word: return syns = find_synonyms(word) all_synonyms = sorted({ text for ss in syns for text in ss if word.upper() not in text.upper().split() }) if not all_synonyms: turn.response_text = f'Простите, не нашла синонимов к слову "{word}".' return turn.response_text = f'Синонимы к слову "{word}":' for syn in all_synonyms[:-1]: turn.response_text += '\n' + syn + ';' turn.response_text += '\n' + all_synonyms[-1] + '.' turn.user_object['word'] = word
def hello(turn: DialogTurn): turn.response_text = 'Hello! This is the only conditional phrase I have.'
def fallback(turn: DialogTurn): turn.response_text = 'Hi! Sorry, I do not understand you.' turn.suggests.append('hello')
def fallback(turn: DialogTurn): turn.response_text = 'hi'
def fallback(turn: DialogTurn): turn.response_text = 'shalom my friend'
def t3(turn: DialogTurn): turn.response_text = '2'
def do_help(turn: DialogTurn): turn.response_text = 'Привет! Вы в навыке "Синоним к слову". ' \ 'Скажите любое слово, а я найду синонимы к нему.' \ '\nЧтобы выйти, скажите "хватит".' turn.suggests.append('выход')
def hello(turn: DialogTurn): turn.response_text = 'Привет! Вы в навыке "Синоним к слову". ' \ 'Скажите любое слово, а я найду синонимы к нему.' turn.suggests.append('выход')
def t0(turn: DialogTurn): turn.response_text = '0'
def test_postprocess(): turn = DialogTurn(make_context(text='kek'), text='kek') turn.response_text = 'The weather is cool.' # without agenda, no postprocessors are called turn.release_control() csc.postprocess(turn) assert turn.response_text.endswith('cool.') # without control, no postprocessors are called turn.take_control() turn.add_agenda('ask_for_tea') csc.postprocess(turn) assert turn.response_text.endswith('cool.') # with control and agenda, postprocessors are called turn.release_control() csc.postprocess(turn) assert turn.response_text.endswith('tea?') # after postprocessing, agenda goes away assert not turn.agenda
def test_ranking_stage(): ctx = Context(message_text='kek', user_object={'stage': 's1'}, metadata=None) turn = DialogTurn(ctx, text='kek', intents={'i3': 1}) assert turn.old_user_object == {'stage': 's1'} assert turn.stage == 's1' assert csc(turn) == 't4'
def test_ranking(intents, result): turn = DialogTurn(make_context(text='kek'), text='kek', intents=intents) assert csc(turn) == result
def t4(turn: DialogTurn): turn.response_text = 'stage 1'
def total_exit(turn: DialogTurn): turn.response_text = 'Было приятно пообщаться! ' \ 'Чтобы обратиться ко мне снова, ' \ 'запустите навык "Синоним к слову".' turn.commands.append(COMMANDS.EXIT)
def try_forms(turn: DialogTurn): for dm in form_dms: form_response = dm.try_to_respond(turn.ctx) if form_response: turn.response = form_response return
def t1(turn: DialogTurn): turn.response_text = '1'