deeppavlov.models.api_requester¶
- class deeppavlov.models.api_requester.api_requester.ApiRequester(url: str, out: [<class 'int'>, <class 'list'>], param_names: [<class 'list'>, <class 'tuple'>] = None, debatchify: bool = False, *args, **kwargs)[source]¶
Component for forwarding parameters to APIs
- Parameters
url – url of the API.
out – count of expected returned values or their names in a chainer.
param_names – list of parameter names for API requests.
debatchify – if
True
, single instances will be sent to the API endpoint instead of batches.
- url¶
url of the API.
- out_count¶
count of expected returned values.
- param_names¶
list of parameter names for API requests.
- debatchify¶
if True, single instances will be sent to the API endpoint instead of batches.
- __call__(*args: List[Any], **kwargs: Dict[str, Any])[source]¶
- Parameters
*args – list of parameters sent to the API endpoint. Parameter names are taken from self.param_names.
**kwargs – named parameters to send to the API endpoint. If not empty, args are ignored
- Returns
result of the API request(s)
- async get_async_response(data: dict, batch_size: int) AsyncIterable [source]¶
Helper function for sending requests asynchronously if the API endpoint does not support batching
- Parameters
data – data to be passed to the API endpoint
batch_size – requests count
- Yields
requests results parsed as json
- class deeppavlov.models.api_requester.api_router.ApiRouter(api_requesters: List[ApiRequester], n_workers: int = 1, *args, **kwargs)[source]¶
A helper class for running multiple API requesters on the same data in parallel
- Parameters
api_requesters – list of ApiRequester objects
n_workers – The maximum number of subprocesses to run
- api_requesters¶
list of ApiRequester objects
- n_workers¶
The maximum number of subprocesses to run