def print_bot_output(message, color=rasa.cli.utils.bcolors.OKBLUE): if "text" in message: rasa.cli.utils.print_color(message.get("text"), color=color) if "image" in message: rasa.cli.utils.print_color("Image: " + message.get("image"), color=color) if "attachment" in message: rasa.cli.utils.print_color("Attachment: " + message.get("attachment"), color=color) if "buttons" in message: rasa.cli.utils.print_color("Buttons:", color=color) for idx, button in enumerate(message.get("buttons")): rasa.cli.utils.print_color(button_to_string(button, idx), color=color) if "elements" in message: rasa.cli.utils.print_color("Elements:", color=color) for idx, element in enumerate(message.get("elements")): rasa.cli.utils.print_color(element_to_string(element, idx), color=color) if "quick_replies" in message: rasa.cli.utils.print_color("Quick Replies:", color) for idx, element in enumerate(message.get("quick_replies")): rasa.cli.utils.print_color(button_to_string(element, idx), color=color) if "custom" in message: rasa.cli.utils.print_color("Custom json:", color=color) return rasa.cli.utils.print_color(json.dumps(message.get("custom"), indent=2), color=color)
def print_bot_output(message, color=rasa.cli.utils.bcolors.OKBLUE): if "text" in message: rasa.cli.utils.print_color(message.get("text"), color=color) if "image" in message: rasa.cli.utils.print_color("Image: " + message.get("image"), color=color) if "attachment" in message: rasa.cli.utils.print_color("Attachment: " + message.get("attachment"), color=color) if "buttons" in message: rasa.cli.utils.print_color("Buttons:", color=color) for idx, button in enumerate(message.get("buttons")): rasa.cli.utils.print_color(button_to_string(button, idx), color=color) if "elements" in message: for idx, element in enumerate(message.get("elements")): element_str = "Elements:\n" + element_to_string(element, idx) rasa.cli.utils.print_color(element_str, color=color) if "quick_replies" in message: for idx, element in enumerate(message.get("quick_replies")): element_str = "Quick Replies:\n" + button_to_string(element, idx) rasa.cli.utils.print_color(element_str, color=color)
def format_bot_output(message: Dict[Text, Any]) -> Text: """Format a bot response to be displayed in the history table.""" # First, add text to output output = message.get("text") or "" # Then, append all additional items data = message.get("data", {}) if not data: return output if data.get("image"): output += "\nImage: " + data.get("image") if data.get("attachment"): output += "\nAttachment: " + data.get("attachment") if data.get("buttons"): output += "\nButtons:" for idx, button in enumerate(data.get("buttons")): button_str = button_to_string(button, idx) output += "\n" + button_str if data.get("elements"): output += "\nElements:" for idx, element in enumerate(data.get("elements")): element_str = element_to_string(element, idx) output += "\n" + element_str if data.get("quick_replies"): output += "\nQuick replies:" for idx, element in enumerate(data.get("quick_replies")): element_str = element_to_string(element, idx) output += "\n" + element_str return output
async def _predict_till_next_listen( endpoint: EndpointConfig, sender_id: Text, finetune: bool, sender_ids: List[Text], plot_file: Optional[Text], ) -> None: """Predict and validate actions until we need to wait for a user msg.""" listen = False while not listen: result = await request_prediction(endpoint, sender_id) predictions = result.get("scores") probabilities = [prediction["score"] for prediction in predictions] pred_out = int(np.argmax(probabilities)) action_name = predictions[pred_out].get("action") policy = result.get("policy") confidence = result.get("confidence") await _print_history(sender_id, endpoint) await _plot_trackers( sender_ids, plot_file, endpoint, unconfirmed=[ActionExecuted(action_name)] ) listen = await _validate_action( action_name, policy, confidence, predictions, endpoint, sender_id, finetune=finetune, ) await _plot_trackers(sender_ids, plot_file, endpoint) tracker_dump = await retrieve_tracker( endpoint, sender_id, EventVerbosity.AFTER_RESTART ) events = tracker_dump.get("events", []) if len(events) >= 2: last_event = events[-2] # last event before action_listen # if bot message includes buttons the user will get a list choice to reply # the list choice is displayed in place of action listen if last_event.get("event") == BotUttered.type_name and last_event["data"].get( "buttons", None ): data = last_event["data"] message = last_event.get("text", "") choices = [ button_to_string(button, idx) for idx, button in enumerate(data.get("buttons")) ] question = questionary.select(message, choices) button_payload = cliutils.payload_from_button_question(question) await send_message(endpoint, sender_id, button_payload)
def print_bot_output( message, color=rasa.cli.utils.bcolors.OKBLUE) -> Optional[questionary.Question]: if ("text" in message) and not ("buttons" in message): rasa.cli.utils.print_color(message.get("text"), color=color) if "image" in message: rasa.cli.utils.print_color("Image: " + message.get("image"), color=color) if "attachment" in message: rasa.cli.utils.print_color("Attachment: " + message.get("attachment"), color=color) if "buttons" in message: choices = [ button_to_string(button, idx) for idx, button in enumerate(message.get("buttons")) ] question = questionary.select( message.get("text"), choices, style=Style([("qmark", "#6d91d3"), ("", "#6d91d3"), ("answer", "#b373d6")]), ) return question if "elements" in message: rasa.cli.utils.print_color("Elements:", color=color) for idx, element in enumerate(message.get("elements")): rasa.cli.utils.print_color(element_to_string(element, idx), color=color) if "quick_replies" in message: rasa.cli.utils.print_color("Quick Replies:", color=color) for idx, element in enumerate(message.get("quick_replies")): rasa.cli.utils.print_color(button_to_string(element, idx), color=color) if "custom" in message: rasa.cli.utils.print_color("Custom json:", color=color) rasa.cli.utils.print_color(json.dumps(message.get("custom"), indent=2), color=color)