def local_test()

in dynalab/handler.py [0:0]


def local_test():
    from dynalab.tasks import flores_small1

    bin_data = b"\n".join(json.dumps(d).encode("utf-8") for d in flores_small1.data)
    torchserve_data = [{"body": bin_data}]

    manifest = {"model": {"serializedFile": "model.pt"}}
    system_properties = {"model_dir": ".", "gpu_id": None}

    class Context(NamedTuple):
        system_properties: dict
        manifest: dict

    ctx = Context(system_properties, manifest)
    batch_responses = handle(torchserve_data, ctx)
    print(batch_responses)

    single_responses = [
        handle([{"body": json.dumps(d).encode("utf-8")}], ctx)[0]
        for d in flores_small1.data
    ]
    assert batch_responses == ["\n".join(single_responses)]