From b5e0d76e09bfc82c1be14e787de9b0ba2da40e46 Mon Sep 17 00:00:00 2001 From: Lucain Date: Thu, 18 Jul 2024 10:08:52 +0200 Subject: [PATCH 1/2] Update _async_client.py --- src/huggingface_hub/inference/_generated/_async_client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/inference/_generated/_async_client.py b/src/huggingface_hub/inference/_generated/_async_client.py index be3d549ffa..1d53060a3f 100644 --- a/src/huggingface_hub/inference/_generated/_async_client.py +++ b/src/huggingface_hub/inference/_generated/_async_client.py @@ -2282,7 +2282,12 @@ async def text_generation( if stream: return _async_stream_text_generation_response(bytes_output, details) # type: ignore - data = _bytes_to_dict(bytes_output)[0] # type: ignore[arg-type] + data = _bytes_to_dict(bytes_output) # type: ignore[arg-type] + + # Data can be a single element (dict) or an iterable of dicts where we select the first element of. + if isinstance(data, list): + data = data[0] + return TextGenerationOutput.parse_obj_as_instance(data) if details else data["generated_text"] async def text_to_image( From 1f9dbf896e791bc7beb7a3a855856e43d08ee3cf Mon Sep 17 00:00:00 2001 From: Leon Camus Date: Thu, 18 Jul 2024 10:11:17 +0200 Subject: [PATCH 2/2] fix: Handle single return value. (#2396) Co-authored-by: Lucain --- src/huggingface_hub/inference/_client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/inference/_client.py b/src/huggingface_hub/inference/_client.py index a23b7d7f0a..bd61f012e2 100644 --- a/src/huggingface_hub/inference/_client.py +++ b/src/huggingface_hub/inference/_client.py @@ -2251,7 +2251,12 @@ def text_generation( if stream: return _stream_text_generation_response(bytes_output, details) # type: ignore - data = _bytes_to_dict(bytes_output)[0] # type: ignore[arg-type] + data = _bytes_to_dict(bytes_output) # type: ignore[arg-type] + + # Data can be a single element (dict) or an iterable of dicts where we select the first element of. + if isinstance(data, list): + data = data[0] + return TextGenerationOutput.parse_obj_as_instance(data) if details else data["generated_text"] def text_to_image(