Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions instill/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from instill.helpers.protobufs.parse import (
Metadata,
construct_infer_response,
construct_metadata_response,
)
1 change: 1 addition & 0 deletions instill/helpers/protobufs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

77 changes: 77 additions & 0 deletions instill/helpers/protobufs/parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from dataclasses import dataclass
from typing import List

from instill.helpers.protobufs.ray_pb2 import (
ModelMetadataRequest,
ModelMetadataResponse,
RayServiceCallRequest,
RayServiceCallResponse,
InferTensor,
)


@dataclass
class Metadata:
name: str
datatype: str
shape: list


def construct_metadata_response(
req: ModelMetadataRequest,
inputs: List[Metadata],
outputs: List[Metadata],
) -> ModelMetadataResponse:
resp = ModelMetadataResponse(
name=req.name,
versions=req.version,
framework="python",
inputs=[],
outputs=[],
)

for i in inputs:
resp.inputs.append(
ModelMetadataResponse.TensorMetadata(
name=i.name,
datatype=i.datatype,
shape=i.shape,
)
)

for o in outputs:
resp.outputs.append(
ModelMetadataResponse.TensorMetadata(
name=o.name,
datatype=o.datatype,
shape=o.shape,
)
)

return resp


def construct_infer_response(
req: RayServiceCallRequest,
outputs: List[Metadata],
raw_outputs,
) -> RayServiceCallResponse:
resp = RayServiceCallResponse(
model_name=req.model_name,
model_version=req.model_version,
outputs=[],
raw_output_contents=[],
)

for o in outputs:
resp.outputs.append(
InferTensor(
name=o.name,
datatype=o.datatype,
shape=o.shape,
)
)

resp.raw_output_contents.append(raw_outputs)

return resp