Can a python string that is colored be printed in rasa?

.can anyone solve this for me if possible …can a python string that is colored be printed in rasa,i tried but it only prints in the cusom action terminal

Hi, I’m not sure I understand what you’re trying to achieve. Have you tried using the print_color method in

@fkoerner…I used termcolor library and it works fine In custom action terminal as u can see the picture the word Note:- came out in red color but in rasa shell it says none (dont do it at home)…the ways I thought it was suppose to came out was "Note:-dont do it at home " where the word “Note:-” in red as a warning that I want to display…but in rasa shell it jumps it and make the display as "none dont do it at home "…did u get me ?

Hi @faiza_conte not sure what you are trying to achieve, but perhaps you could use logs instead of print. like

import logging
logging.error('Your string') 

Since I did logging.error the output will be red

@jusce17 the “print” part works fine but the problem is when i try to display it in rasa shell

yes, if you use logging, it should display the info in rasa shell in red as you want

@jusce17 still the same ,nothing changed at all

If it is just to print with different colors, perhaps you can use termcolor

from termcolor import colored

class ActionPrintColor(Action):

    def name(self) -> Text:
        return "action_print_color"

    def run(self, dispatcher, tracker, domain):
        print(colored("EXAMPLE EXAMPLE", "green"))

        return []

that will print in the custom action or python terminal well but not in the rasa shell anyways forgot it…i have another issue with rasa…am trying to get the normalized value of an entity duration that is extracted using duckling but i dont know what i did wrong it gives me this error

Oh, I see. You can’t print colours with dispatcher.utter_message, and your formatting is being lost when you convert the message to a string.

This is a syntax issue. next() returns the value of the entity (in this case the integer duration value), and not a dictionary, so you can’t subscript it (appending ["entities"], for example will not work). You can remove next() to get more values.

@fkoerner here is the rasa shell nlu value for entity duration …and from the picture I wanted to get the normalised value

You can get the entities from the latest message like so: tracker.latest_message["entities"]

yes @fkoerner…i would get the entity but for duration there is 3 values that duckling extracted if you see in the nlu shell…with "tracker.get_slot(“duration”) i will get the first value …but i want to extract the normalized value …please if you see the picture you will see the normalized word

tracker.latest_message["entities"] returns a list of entities. I think this snippet should work for you:

[entity["additional_info"]["normalized"]["value"] for entity in tracker.latest_message["entities"] if entity.get(ENTITY_ATTRIBUTE_TYPE) == "duration"]

@fkoerner so with is duration_normalized_val= [entity["additional_info"]["normalized"]["value"] for entity in tracker.latest_message["entities"] if entity.get(ENTITY_ATTRIBUTE_TYPE) == "duration"] would give me the normalized value which is in second?

duration_normalized_val = \
             for entity in tracker.latest_message["entities"]
             if (entity.get(ENTITY_ATTRIBUTE_TYPE) == "duration" and
             entity.get("extractor") == "DucklingEntityExtractor")]

maybe add the last condition for good measure. The above code worked for me.

Note that it will give you a list of values (in case there is more than one duration entity in the message).

thanks @fkoerner i have another issue…am getting an output twice and i dont know what i did wrong can you see it for me please

@fkoerner with small letter “amoxa” works fine but for capital “Amoxa” the output becomes twice

        for e in entities:
            if e['entity'] == 'drug':
                drug_name = e['value']
            if drug_name == "amoxa" or drug_name == "Amoxa":
            elif drug_name == "tablet":

                dispatcher.utter_message(template="utter_notfound") ```