Skip to content

Formatters

Daniel Kornev edited this page Dec 7, 2020 · 3 revisions

Overview

Formatters are the functions that allow converting the input and output API of services into Agent's API. These functions are written in Python.

Types of Formatters

Dialog formatters

These functions should accept a single parameter: dialog (in dict form), and return a list of tasks for service processing. Each task should be in a format which is correct for associated service. From a dict form of a dialog you can extract data on:

  • Human - dialog['human']
  • Bot - dialog['bot']
  • List of all utterances - dialog['utterances']
  • List of only human utterances - dialog['human_utterances']
  • List of only bot utterances - dialog['bot_utterances']

Each utterance (both bot and human) has a number of same parameters:

  • Text - utterance['text']
  • Annotations - utterance['annotations']
  • User (human or bot, depending on type of utterance) - utterance['user']

Human utterance has additional parameters:

  • List of hypotheses - utterance['hypotheses']
  • Additional attributes - utterance['attributes']

Bot utterance also has additional attributes:

  • Active skill name (skill, which provided actual response) - utterance['active_skill']
  • Response confidence - utterance['confidence']
  • Original response text (not modified by postprocessors) - utterance['orig_text']

Response formatters

These functions should accept one sample of skill response, and re-format it, making further processing available. These formatters are optional.

Developing Own Formatter

TBD

Registering Own Formatter

To use a formatter you simply should specify its name in the config of your Skill, Annotator, or Response Selector, like this:

"harvesters_maintenance_skill": {
                "connector": {
                    "protocol": "http",
                    "url": "http://harvesters_maintenance_skill:3002/respond"
                },
                "dialog_formatter": "dp_formatters:full_dialog",
                "response_formatter": "dp_formatters:base_skill_formatter",
                "state_manager_method": "add_hypothesis",
                "previous_services": ["annotators"]
            },

Here, both dialog_formatter and response_formatter are used.

Resources