Skip to content

Commit

Permalink
JSONCodec support single value
Browse files Browse the repository at this point in the history
  • Loading branch information
pepesi committed Aug 30, 2022
1 parent 38b68a2 commit bb07b1e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion runtimes/huggingface/mlserver_huggingface/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ def encode_output(cls, name: str, payload: Any, **kwargs) -> ResponseOutput:
@classmethod
def decode_output(cls, response_output: ResponseOutput) -> Any:
strs = StringCodec.decode_output(response_output)
if is_single_value(response_output):
if len(strs) == 0:
raise ValueError("can't decode empty data as a single value")
return json.loads(strs[0])
return [json.loads(el) for el in strs]

@classmethod
Expand All @@ -208,8 +212,12 @@ def encode_input(cls, name: str, payload: List[Dict[str, Any]]) -> RequestInput:
return rinput

@classmethod
def decode_input(cls, request_input: RequestInput) -> Dict[str, Any]:
def decode_input(cls, request_input: RequestInput) -> Any:
strs = StringCodec.decode_input(request_input)
if is_single_value(request_input):
if len(strs) == 0:
raise ValueError("can't decode empty data as a single value")
return json.loads(strs[0])
return [json.loads(el) for el in strs]


Expand Down

0 comments on commit bb07b1e

Please sign in to comment.