rasa/core/training/interactive.py
def _chat_history_table(evts: List[Dict[Text, Any]]) -> Text:
    """Create a table containing bot and user messages.

    Also includes additional information, like any events and
    prediction probabilities."""

    def wrap(txt, max_width):
        return "\n".join(textwrap.wrap(txt, max_width,
                                       replace_whitespace=False))

    def colored(txt, color):
        return "{" + color + "}" + txt + "{/" + color + "}"

    def format_user_msg(user_evt, max_width):
        _parsed = user_evt.get('parse_data', {})
        _intent = _parsed.get('intent', {}).get("name")
        _confidence = _parsed.get('intent', {}).get("confidence", 1.0)
        _md = _as_md_message(_parsed)

        _lines = [
            colored(wrap(_md, max_width), "hired"),
            "intent: {} {:03.2f}".format(_intent, _confidence)
        ]
        return "\n".join(_lines)

    def bot_width(_table: AsciiTable) -> int:
        return _table.column_max_width(1)

    def user_width(_table: AsciiTable) -> int:
        return _table.column_max_width(3)

    def add_bot_cell(data, cell):
        data.append([len(data), Color(cell), "", ""])

    def add_user_cell(data, cell):
        data.append([len(data), "", "", Color(cell)])

    # prints the historical interactions between the bot and the user,
    # to help with correctly identifying the action
    table_data = [
        ["#  ",
         Color(colored('Bot      ', 'autoblue')),
         "  ",
         Color(colored('You       ', 'hired'))],
    ]

    table = SingleTable(table_data, 'Chat History')

    bot_column = []
    for idx, evt in enumerate(evts):
        if evt.get("event") == ActionExecuted.type_name:
            bot_column.append(colored(evt['name'], 'autocyan'))
            if evt['confidence'] is not None:
                bot_column[-1] += (
                    colored(" {:03.2f}".format(evt['confidence']),
                            'autowhite'))

        elif evt.get("event") == UserUttered.type_name:
            if bot_column:
                text = "\n".join(bot_column)
                add_bot_cell(table_data, text)
                bot_column = []

            msg = format_user_msg(evt, user_width(table))
            add_user_cell(table_data, msg)

        elif evt.get("event") == BotUttered.type_name:
            wrapped = wrap(format_bot_output(evt), bot_width(table))
            bot_column.append(colored(wrapped, 'autoblue'))

        else:
            e = Event.from_parameters(evt)
            if e.as_story_string():
                bot_column.append(wrap(e.as_story_string(), bot_width(table)))

    if bot_column:
        text = "\n".join(bot_column)
        add_bot_cell(table_data, text)

    table.inner_heading_row_border = False
    table.inner_row_border = True
    table.inner_column_border = False
    table.outer_border = False
    table.justify_columns = {0: 'left', 1: 'left', 2: 'center', 3: 'right'}

    return table.table
Create a table containing bot and user messages.

    Also includes additional information, like any events and
    prediction probabilities.
Create a table containing bot and user messages.
Also includes additional information, like any events and
prediction probabilities.
Create a table containing bot and user messages . Also includes additional information like any events and prediction probabilities .
def _chat_history_table(evts: List[Dict[Text, Any]]) -> Text:
    def wrap(txt, max_width):
        return "\n".join(textwrap.wrap(txt, max_width,
                                       replace_whitespace=False))
    def colored(txt, color):
        return "{" + color + "}" + txt + "{/" + color + "}"
    def format_user_msg(user_evt, max_width):
        _parsed = user_evt.get('parse_data', {})
        _intent = _parsed.get('intent', {}).get("name")
        _confidence = _parsed.get('intent', {}).get("confidence", 1.0)
        _md = _as_md_message(_parsed)
        _lines = [
            colored(wrap(_md, max_width), "hired"),
            "intent: {} {:03.2f}".format(_intent, _confidence)
        ]
        return "\n".join(_lines)
    def bot_width(_table: AsciiTable) -> int:
        return _table.column_max_width(1)
    def user_width(_table: AsciiTable) -> int:
        return _table.column_max_width(3)
    def add_bot_cell(data, cell):
        data.append([len(data), Color(cell), "", ""])
    def add_user_cell(data, cell):
        data.append([len(data), "", "", Color(cell)])
    table_data = [
        ["#  ",
         Color(colored('Bot      ', 'autoblue')),
         "  ",
         Color(colored('You       ', 'hired'))],
    ]
    table = SingleTable(table_data, 'Chat History')
    bot_column = []
    for idx, evt in enumerate(evts):
        if evt.get("event") == ActionExecuted.type_name:
            bot_column.append(colored(evt['name'], 'autocyan'))
            if evt['confidence'] is not None:
                bot_column[-1] += (
                    colored(" {:03.2f}".format(evt['confidence']),
                            'autowhite'))
        elif evt.get("event") == UserUttered.type_name:
            if bot_column:
                text = "\n".join(bot_column)
                add_bot_cell(table_data, text)
                bot_column = []
            msg = format_user_msg(evt, user_width(table))
            add_user_cell(table_data, msg)
        elif evt.get("event") == BotUttered.type_name:
            wrapped = wrap(format_bot_output(evt), bot_width(table))
            bot_column.append(colored(wrapped, 'autoblue'))
        else:
            e = Event.from_parameters(evt)
            if e.as_story_string():
                bot_column.append(wrap(e.as_story_string(), bot_width(table)))
    if bot_column:
        text = "\n".join(bot_column)
        add_bot_cell(table_data, text)
    table.inner_heading_row_border = False
    table.inner_row_border = True
    table.inner_column_border = False
    table.outer_border = False
    table.justify_columns = {0: 'left', 1: 'left', 2: 'center', 3: 'right'}
    return table.table
def _chat_history_table ( evts : List [ Dict [ Text , Any ] ] ) -> Text : def wrap ( txt , max_width ) : return "\n" . join ( textwrap . wrap ( txt , max_width , replace_whitespace = False ) ) def colored ( txt , color ) : return "{" + color + "}" + txt + "{/" + color + "}" def format_user_msg ( user_evt , max_width ) : _parsed = user_evt . get ( 'parse_data' , { } ) _intent = _parsed . get ( 'intent' , { } ) . get ( "name" ) _confidence = _parsed . get ( 'intent' , { } ) . get ( "confidence" , 1.0 ) _md = _as_md_message ( _parsed ) _lines = [ colored ( wrap ( _md , max_width ) , "hired" ) , "intent: {} {:03.2f}" . format ( _intent , _confidence ) ] return "\n" . join ( _lines ) def bot_width ( _table : AsciiTable ) -> int : return _table . column_max_width ( 1 ) def user_width ( _table : AsciiTable ) -> int : return _table . column_max_width ( 3 ) def add_bot_cell ( data , cell ) : data . append ( [ len ( data ) , Color ( cell ) , "" , "" ] ) def add_user_cell ( data , cell ) : data . append ( [ len ( data ) , "" , "" , Color ( cell ) ] ) table_data = [ [ "#  " , Color ( colored ( 'Bot      ' , 'autoblue' ) ) , "  " , Color ( colored ( 'You       ' , 'hired' ) ) ] , ] table = SingleTable ( table_data , 'Chat History' ) bot_column = [ ] for idx , evt in enumerate ( evts ) : if evt . get ( "event" ) == ActionExecuted . type_name : bot_column . append ( colored ( evt [ 'name' ] , 'autocyan' ) ) if evt [ 'confidence' ] is not None : bot_column [ - 1 ] += ( colored ( " {:03.2f}" . format ( evt [ 'confidence' ] ) , 'autowhite' ) ) elif evt . get ( "event" ) == UserUttered . type_name : if bot_column : text = "\n" . join ( bot_column ) add_bot_cell ( table_data , text ) bot_column = [ ] msg = format_user_msg ( evt , user_width ( table ) ) add_user_cell ( table_data , msg ) elif evt . get ( "event" ) == BotUttered . type_name : wrapped = wrap ( format_bot_output ( evt ) , bot_width ( table ) ) bot_column . append ( colored ( wrapped , 'autoblue' ) ) else : e = Event . from_parameters ( evt ) if e . as_story_string ( ) : bot_column . append ( wrap ( e . as_story_string ( ) , bot_width ( table ) ) ) if bot_column : text = "\n" . join ( bot_column ) add_bot_cell ( table_data , text ) table . inner_heading_row_border = False table . inner_row_border = True table . inner_column_border = False table . outer_border = False table . justify_columns = { 0 : 'left' , 1 : 'left' , 2 : 'center' , 3 : 'right' } return table . table
Create a table containing bot and user messages.
Create a table containing bot and user messages .
"""Create a table containing bot and user messages.

    Also includes additional information, like any events and
    prediction probabilities.""" # prints the historical interactions between the bot and the user, # to help with correctly identifying the action
evts
List[Dict[Text, Any]]