async def record_messages( sender_id: Text, server_url: Text = DEFAULT_SERVER_URL, auth_token: Text = "", max_message_limit: Optional[int] = None, use_response_stream: bool = True, request_timeout: Optional[int] = None, ) -> int: """Read messages from the command line and print bot responses.""" exit_text = INTENT_MESSAGE_PREFIX + "stop" rasa.shared.utils.cli.print_success( "Bot loaded. Type a message and press enter " "(use '{}' to exit): ".format(exit_text)) num_messages = 0 previous_response = None await asyncio.sleep(0.5) # Wait for server to start while not utils.is_limit_reached(num_messages, max_message_limit): text = _get_user_input(previous_response) if text == exit_text or text is None: break if use_response_stream: bot_responses = _send_message_receive_stream( server_url, auth_token, sender_id, text, request_timeout=request_timeout) previous_response = None async for response in bot_responses: if previous_response is not None: _print_bot_output(previous_response) previous_response = response else: bot_responses = await send_message_receive_block( server_url, auth_token, sender_id, text) previous_response = None for response in bot_responses: if previous_response is not None: _print_bot_output(previous_response) previous_response = response num_messages += 1 await asyncio.sleep(0) # Yield event loop for others coroutines return num_messages
async def record_messages( sender_id, server_url=DEFAULT_SERVER_URL, auth_token="", max_message_limit=None, use_response_stream=True, ) -> int: """Read messages from the command line and print bot responses.""" # import pdb # pdb.set_trace() exit_text = INTENT_MESSAGE_PREFIX + "stop" cli_utils.print_success("Bot loaded. Type a message and press enter " "(use '{}' to exit): ".format(exit_text)) num_messages = 0 previous_response = None await asyncio.sleep(0.5) # Wait for server to start while not utils.is_limit_reached(num_messages, max_message_limit): text = get_user_input(previous_response) if text == exit_text or text is None: break if use_response_stream: bot_responses = send_message_receive_stream( server_url, auth_token, sender_id, text) previous_response = None async for response in bot_responses: if previous_response is not None: print_bot_output(previous_response) previous_response = response else: bot_responses = await send_message_receive_block( server_url, auth_token, sender_id, text) previous_response = None for response in bot_responses: if previous_response is not None: print_bot_output(previous_response) previous_response = response num_messages += 1 await asyncio.sleep(0) # Yield event loop for others coroutines return num_messages
async def record_messages( server_url=DEFAULT_SERVER_URL, auth_token=None, sender_id=UserMessage.DEFAULT_SENDER_ID, max_message_limit=None, use_response_stream=True, ): """Read messages from the command line and print bot responses.""" auth_token = auth_token if auth_token else "" exit_text = INTENT_MESSAGE_PREFIX + "stop" cli_utils.print_success( "Bot loaded. Type a message and press enter " "(use '{}' to exit): ".format(exit_text) ) num_messages = 0 button_question = None while not utils.is_limit_reached(num_messages, max_message_limit): text = get_user_input(button_question) if text == exit_text or text is None: break if use_response_stream: bot_responses = send_message_receive_stream( server_url, auth_token, sender_id, text ) async for response in bot_responses: button_question = print_bot_output(response) else: bot_responses = await send_message_receive_block( server_url, auth_token, sender_id, text ) for response in bot_responses: button_question = print_bot_output(response) num_messages += 1 return num_messages