def test_generate_message_raises_on_overlapping_but_not_identical_spans( message_text: Text, entities: List[Dict[Text, Any]], ): message = Message.build(message_text, "dummy_intent", entities=entities) with pytest.raises(ValueError): TrainingDataWriter.generate_message(message)
def test_generate_message( message_text: Text, expected_text: Text, entities: List[Dict[Text, Any]], ): message = Message.build(message_text, "dummy_intent", entities=entities) message_text = TrainingDataWriter.generate_message(message) assert message_text == expected_text
def md_format_message( text: Text, intent: Optional[Text], entities: Union[Text, List[Any]] ) -> Text: """Uses NLU parser information to generate a message with inline entity annotations. Arguments: text: text of the message intent: intent of the message entities: entities of the message Return: Message with entities annotated inline, e.g. `I am from [Berlin]{"entity": "city"}`. """ from rasa.shared.nlu.training_data.formats.readerwriter import TrainingDataWriter from rasa.shared.nlu.training_data import entities_parser message_from_md = entities_parser.parse_training_example(text, intent) deserialised_entities = deserialise_entities(entities) return TrainingDataWriter.generate_message( {"text": message_from_md.get(TEXT), "entities": deserialised_entities} )