openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

[Bug Assistant] temperature setting not working

Open ayansengupta17 opened this issue 1 year ago • 2 comments

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

ayansengupta17 avatar Apr 24 '24 03:04 ayansengupta17

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.

ayansengupta17 avatar Apr 24 '24 10:04 ayansengupta17

This matches the behavior specified in the API documentation,

temperature number or null The 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 the assistant_id on the run to retrieve the corresponding assistant, and read the correct temperature from there. Otherwise, you know the value of temperature on run must have been set.
  • When creating the run object with create, always pass-in the assistant.temperature as the temperature argument 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 run has a temperature of 1 then you can treat it as if it had not been set.

derekharmon avatar May 03 '24 02:05 derekharmon

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?

rattrayalex avatar May 13 '24 01:05 rattrayalex

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 avatar May 13 '24 22:05 nknj

@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.

ayansengupta17 avatar May 14 '24 01:05 ayansengupta17

So sorry for the bug here! The fix rolled out, please let me know if you see other issues

erinkav-openai avatar May 15 '24 19:05 erinkav-openai