Ejemplo n.º 1
0
def create_interface_routes(app, interface: Interface):
    for method in interface.exposed_methods():
        sig = interface.exposed_method_signature(method)
        rlogger.debug('registering %s with input type %s and output type %s',
                      method, sig.args, sig.output)

        spec = create_spec(method, sig)
        executor_function = create_executor_function(interface, method, spec)
        app.router.add_post('/' + method, executor_function)
Ejemplo n.º 2
0
 def _deserialize_json(interface: Interface, method: str,
                       request_json: dict):
     args = {a.name: a for a in interface.exposed_method_args(method)}
     try:
         return {
             k: deserialize(v, args[k].type)
             for k, v in request_json.items()
         }
     except KeyError:
         raise MalformedHTTPRequestException(
             f'Invalid request: arguments are {set(args.keys())}, got {set(request_json.keys())}'
         )
     except DeserializationError as e:
         raise MalformedHTTPRequestException(e.args[0])
Ejemplo n.º 3
0
    def _execute_method(interface: Interface, method: str, request_data,
                        ebonite_id: str):
        rlogger.debug('Got request for [%s]: %s', ebonite_id, request_data)

        try:
            result = interface.execute(method, request_data)
        except (ExecutionError, SerializationError) as e:
            raise MalformedHTTPRequestException(e.args[0])

        if isinstance(result, bytes):
            rlogger.debug('Got response for [%s]: <binary content>',
                          ebonite_id)
            return result

        rlogger.debug('Got response for [%s]: %s', result)
        return {'ok': True, 'data': result}
Ejemplo n.º 4
0
def create_interface_routes(app, interface: Interface):
    for method in interface.exposed_methods():
        sig = interface.exposed_method_signature(method)
        rlogger.debug('registering %s with input type %s and output type %s', method, sig.args, sig.output)
        _register_method(app, interface, method, sig)
Ejemplo n.º 5
0
 def run(self, executor: Interface):
     assert executor.exposed_methods() == exposed_methods
     predict_args = executor.exposed_method_args('predict')[0]
     assert issubclass(predict_args.type, DataFrameType)
     assert list(predict_args.type.columns) == model_params