Skip to content

Commit

Permalink
fix: Handle single return value. (#2396)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucain <lucain@huggingface.co>
  • Loading branch information
28Smiles and Wauplin authored Jul 18, 2024
1 parent b5e0d76 commit 1f9dbf8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1f9dbf8

Please sign in to comment.