Пример #1
0
    def test_modelmetadata_grpc(self, namespace, s2i_python_version):
        create_push_s2i_image(s2i_python_version, "modelmetadata", "grpc")
        retry_run(
            f"kubectl apply -f ../resources/metadata_modelmetadata_grpc.yaml -n {namespace}"
        )
        wait_for_status("mymodel-modelmetadata", namespace)
        wait_for_rollout("mymodel-modelmetadata", namespace)
        r = initial_grpc_request("mymodel-modelmetadata", namespace)

        r = grpc_request_ambassador_metadata(
            "mymodel-modelmetadata", namespace, model_name="my-model"
        )

        res = json.loads(json_format.MessageToJson(r))
        logging.info(res)

        # Cast reference model metadata to proto and back in order to have int->float
        # infamous casting in google.protobuf.Value
        metadata_proto = prediction_pb2.SeldonModelMetadata()
        json_format.ParseDict(
            model_metadata, metadata_proto, ignore_unknown_fields=True
        )
        assert res == json.loads(json_format.MessageToJson(metadata_proto))

        r = grpc_request_ambassador_metadata("mymodel-modelmetadata", namespace)

        res = json.loads(json_format.MessageToJson(r))
        logging.info(res)

        graph_metadata_proto = prediction_pb2.SeldonGraphMetadata()
        json_format.ParseDict(
            graph_metadata_grpc, graph_metadata_proto, ignore_unknown_fields=True
        )
        assert res == json.loads(json_format.MessageToJson(graph_metadata_proto))
Пример #2
0
def json_to_seldon_model_metadata(
    metadata_json: Dict,
) -> prediction_pb2.SeldonModelMetadata:
    """
    Parses JSON input to SeldonModelMetadata proto

    Parameters
    ----------
    metadata_json
        JSON input

    Returns
    -------
        SeldonModelMetadata
    """
    if metadata_json is None:
        metadata_json = {}
    metadata_proto = prediction_pb2.SeldonModelMetadata()
    try:
        json_format.ParseDict(metadata_json, metadata_proto, ignore_unknown_fields=True)
        return metadata_proto
    except json_format.ParseError as pbExc:
        raise SeldonMicroserviceException(f"Invalid metadata: {pbExc}")