openai / openai-python

The official Python library for the OpenAI API
https://pypi.org/project/openai/
Apache License 2.0
23.09k stars 3.25k forks source link

Convert stream value to boolean if int passed in client.chat.completions.create #1818

Closed SmartManoj closed 4 weeks ago

SmartManoj commented 4 weeks ago

Update client.chat.completions.create to convert stream parameter to boolean if it is an integer.


For more details, open the Copilot Workspace session.

RobertCraigie commented 4 weeks ago

Thanks for the PR, why do you want to pass an integer?

SmartManoj commented 4 weeks ago

Thank you for the quick review. The reason I proposed allowing integers is for flexibility and convenience. In some cases, users might inadvertently pass an integer like 0 or 1 instead of a boolean. Converting these values internally ensures smooth operation without errors, improving the overall user experience.

Currently if passed 0 for model openai/nvidia/llama-3.1-nemotron-70b-instruct, got openai.InternalServerError: failed to decode json body: json: bool unexpected end of JSON input

RobertCraigie commented 4 weeks ago

Thanks for the PR but I don't think we want to support int here, we try to match what the API supports. I agree the error in that case could be improved, it should be a 400 instead of a 500, I've reported this to the OpenAI API team.