REST API

Each DeepPavlov model 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>]
  • -d: downloads model specific data before starting the service.

  • -p <port>: sets the port to <port>. Overrides default settings from deeppavlov/utils/settings/server_config.json.

The command will print the used host and port. Default web service properties (host, port, POST request arguments) can be modified via changing deeppavlov/utils/settings/server_config.json file.

API routes

/model

Send POST request to <host>:<port>/model to infer model. See details at /docs.

/probe

Send POST request to <host>:<port>/probe to check if API is working. The server will send a response ["Test passed"] if it is working. Requests to /probe are not logged.

/api

To get model argument names send GET request to <host>:<port>/api. Server will return list with argument names.

/docs

To interact with the REST API via graphical interface open <host>:<port>/docs in a browser (Flasgger UI).

Advanced configuration

By modifying deeppavlov/utils/settings/server_config.json you can change host, port, POST request arguments and other properties of the API service.

Properties from common_defaults section are used by default unless they are overridden by model-specific properties, provided in model_defaults section of the server_config.json. Model-specific properties are bound to the model by server_utils label in metadata/labels section of the model config. Value of server_utils label from model 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, all parameters with non empty (i.e. not "", not [] etc.) values from model_defaults/GoalOrientedBot will overwrite the parameter values in common_defaults.

If model_args_names parameter of server_config.json is empty string, then model argument names are provided as list from chainer/in section of the model config file, where arguments order corresponds to model API. When inferencing model via REST api, JSON payload keys should match model arguments names from chainer/in section. If model_args_names parameter of server_config.json is list, its values are used as model argument names instead of the list from model config’s chainer/in section. Here are POST request payload examples for some of the library models:

Model

POST request JSON payload example

One argument models

NER model

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

Intent classification model

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

Automatic spelling correction model

{“x”:[“errror”]}

Ranking model

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

Goal-oriented bot

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

Multiple arguments models

Question Answering model

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