openai-python
openai-python copied to clipboard
[Bug Assistant] temperature setting not working
Confirm this is an issue with the Python library and not an underlying OpenAI API
- [X] This is an issue with the Python library
Describe the bug
Even if I change temperature for assistant, the response shows temperature is set to 1.0
To Reproduce
Create an assistant and pass a temperature value.
Code snippets
assistant = client.beta.assistants.create(
name=f"temperature_test_assistant",
instructions="",
model=model_name,
tools=[{"type": "code_interpreter"}],
temperature=0.2,
)
OS
Linux
Python version
python 3.11
Library version
openai==1.23.3
Update:
It seems the assistants created on the platform has correct temperature, but when I fetch it by client.beta.threads.runs.retrieve() It shows incorrect temperature.
This matches the behavior specified in the API documentation,
temperature
number or nullThe sampling temperature used for this run. If not set, defaults to 1.
This is problematic because 1 is a valid value within the domain [0,2] of temperature. None | NOT_GIVEN might be better, but could break existing code consuming the run object (i.e., AttributeError: no property with name 'temperature' exists or ValueError 'temperature' is None); if the code hadn't been written to check for None.
There are a few workarounds you may be able to try, although they are inconvenient:
- When the
temperature== 1 then you could use theassistant_idon therunto retrieve the correspondingassistant, and read the correcttemperaturefrom there. Otherwise, you know the value oftemperatureonrunmust have been set. - When creating the
runobject withcreate, always pass-in theassistant.temperatureas thetemperatureargument so that it never depends on this default value. - Adopt the convention to not use 1 as a temperature in the application; instead use values such as 0.99 or 1.01 that are close enough to 1 for your needs. Then you'll know that if the
runhas atemperatureof 1 then you can treat it as if it had not been set.
Thanks for the report – I agree this sounds confusing.
This sounds like an issue for the underlying OpenAI API and not the Python library, so I'm going to go ahead and close this issue.
Would you mind reposting at community.openai.com?
Thanks for reporting this and sorry for the trouble -- this is a bug on our end and we'll rollout a fix very soon.
@nknj Appreciate the help. @rattrayalex I already posted an initial post on https://community.openai.com/t/bug-or-feature-temperature-setting-in-assistant-v2-confusing/727312 but sadly it got overlooked.
So sorry for the bug here! The fix rolled out, please let me know if you see other issues