Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To unify text_generation()'s stop_sequences and TextGenerationInput's stop params #2471

Closed
sadra-barikbin opened this issue Aug 21, 2024 · 5 comments · Fixed by #2473
Closed

Comments

@sadra-barikbin
Copy link

sadra-barikbin commented Aug 21, 2024

Hi there! 🤗

It would be great if text_generation()'s stop_sequences and TextGenerationInput's stop params are unified just like chat_completion and ChatCompletionInput to be able to feed the input dataclasses to the client methods directly:

client.text_generation(prepared_request.inputs, **prepared_request.parameters) # currently raises `TypeError: text_generation() got an unexpected keyword argument 'stop'`
# or
client.chat_completion(**prepared_request)

stop_sequences: Optional[List[str]] = None, # Same as `stop`

@sadra-barikbin
Copy link
Author

Currently I should do this as the alternative:

from dataclasses import asdict

input_as_dict = asdict(input)
input_as_dict["parameters"]["stop_sequences"] = input_as_dict["parameters"]["stop"]
del input_as_dict["parameters"]["stop"]
client.text_generation(input.inputs, **input_as_dict["parameters"])

@Wauplin
Copy link
Contributor

Wauplin commented Aug 21, 2024

Hi @sadra-barikbin, yes I definitely agree this parameter should be unified. I opened a PR to fix it :) #2473

@sadra-barikbin
Copy link
Author

Thanks @Wauplin ! 👍

@sadra-barikbin
Copy link
Author

There's also a discrepancy between ChatCompletionInput's stream param which is optional defaulting to None and chat_completion()'s stream param which should be either True or False. Is this OK?

@Wauplin
Copy link
Contributor

Wauplin commented Aug 21, 2024

Thanks for flagging this @sadra-barikbin. It's a slight discrepancy but it allows us to simplify the @overload logic in InferenceClient.chat_completion. If we add the type annotation for None value, we would have to overload the method even more. The problem is that bool and Literal[True, False] is not considered the same by mypy / code editors. It led to quite some headaches when trying to solve that (the main thing I was focused on was to have correct autocomplete for the lib'). So all of this to say, the slight discrepancy is fine for now especially because it doesn't change anything in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants