REST API

Each library component or skill can be easily made available for inference as a REST web service. The general method is:

python -m deeppavlov riseapi <config_path> [-d] [-p <port_number>]

(optional -d key is for dependencies download before service start)

Web service properties (host, port, model endpoint, GET request arguments) are provided in utils/settings/server_config.json, but port can be overridden with the -p key in command line. Properties from common_defaults section are used by default unless they are overridden by component-specific properties, provided in model_defaults section of the server_config.json. Component-specific properties are bound to the component by server_utils label in metadata/labels section of the component config. Value of server_utils label from component config should match with properties key from model_defaults section of server_config.json.

For example, metadata/labels/server_utils tag from go_bot/gobot_dstc2.json references to the GoalOrientedBot section of server_config.json. Therefore, model_endpoint parameter in common_defaults will be will be overridden with the same parameter from model_defaults/GoalOrientedBot.

Model argument names are provided as list in model_args_names parameter, where arguments order corresponds to component API. When inferencing model via REST api, JSON payload keys should match component arguments names from model_args_names. Default argument name for one argument components is “context”. Here are POST requests examples for some of the library components:

Component

POST request JSON payload example

One argument components

NER component

{“context”:[“Elon Musk launched his cherry Tesla roadster to the Mars orbit”]}

Intent classification component

{“context”:[“I would like to go to a restaurant with Asian cuisine this evening”]}

Automatic spelling correction component

{“context”:[“errror”]}

Ranking component

{“context”:[“What is the average cost of life insurance services?”]}

(Seq2seq) Goal-oriented bot

{“context”:[“Hello, can you help me to find and book a restaurant this evening?”]}

Multiple arguments components

Question Answering component

{“context”:[“After 1765, growing philosophical and political differences strained the relationship between Great Britain and its colonies.”],
 “question”:[“What strained the relationship between Great Britain and its colonies?”]}

Flasgger UI for API testing is provided on <host>:<port>/apidocs when running a component in riseapi mode.