# The generated code varies every time, even with a low temperature

**URL:** <https://community.openai.com/t/the-generated-code-varies-every-time-even-with-a-low-temperature/921970>\
**Category:** API\
**Tags:** assistants-api\
**Created:** [August 26, 2024, 2:46am UTC](https://community.openai.com/t/the-generated-code-varies-every-time-even-with-a-low-temperature/921970 "2024-08-26T02:46:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![takashi.asano](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/takashi.asano/32/146909_2.png) [@takashi.asano](https://community.openai.com/u/takashi.asano)\
**Post date:** [August 26, 2024, 2:46am UTC](https://community.openai.com/t/the-generated-code-varies-every-time-even-with-a-low-temperature/921970/1 "2024-08-26T02:46:21Z")

</div>

I am using “Assistants API” with gpt4o to generate the python code. We use “temprature=0.01” to get more less randomness with some instructions.  
With this environment, the generated code varies in every threads even if it is exact the same prompt.

I am wondering if the instruction is interfering, or temperature have no effect on the code generation… Does anyone solve this issue?  
I would appreciate your help. Thanks.

---

<div class="post-metadata">

**Author:** ![stevenic](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@stevenic](https://community.openai.com/u/stevenic)\
**Post date:** [August 26, 2024, 4:48am UTC](https://community.openai.com/t/the-generated-code-varies-every-time-even-with-a-low-temperature/921970/2 "2024-08-26T04:48:41Z")

</div>

> [@takashi.asano](#):
>
> We use “temprature=0.01” to get more less randomness with some instructions.  
> With this environment, the generated code varies in every threads even if it is exact the same prompt.

Setting **temperature** to 0.0 helps but it’s pretty much impossible to get completely deterministic outputs from the model. Setting the **seed** for your request to a constant value will get you even closer to the same output but I’ll tell you that even that doesn’t really work.

In addition to the fact these models are non-deterministic, OpenAI is constantly fine tuning the model so the weights are changing on you several times a day.

---

<div class="post-metadata">

**Author:** ![takashi.asano](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/takashi.asano/32/146909_2.png) [@takashi.asano](https://community.openai.com/u/takashi.asano)\
**Post date:** [August 26, 2024, 5:17am UTC](https://community.openai.com/t/the-generated-code-varies-every-time-even-with-a-low-temperature/921970/3 "2024-08-26T05:17:51Z")

</div>

As far as I understand, the assistant API does not support the seed parameter yet. Is this correct?

---

<div class="post-metadata">

**Author:** ![stevenic](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@stevenic](https://community.openai.com/u/stevenic)\
**Post date:** [August 26, 2024, 7:16am UTC](https://community.openai.com/t/the-generated-code-varies-every-time-even-with-a-low-temperature/921970/4 "2024-08-26T07:16:19Z")

</div>

I’m not sure but you could be right.

---

<div class="post-metadata">

**Author:** ![takashi.asano](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/takashi.asano/32/146909_2.png) [@takashi.asano](https://community.openai.com/u/takashi.asano)\
**Post date:** [August 27, 2024, 4:32am UTC](https://community.openai.com/t/the-generated-code-varies-every-time-even-with-a-low-temperature/921970/5 "2024-08-27T04:32:12Z")

</div>

I found out this which may help to control the temp and top\_p at the same time for the code generation purpose:

> [@Cheat Sheet: Mastering Temperature and Top\_p in ChatGPT API](https://community.openai.com/t/cheat-sheet-mastering-temperature-and-top-p-in-chatgpt-api/172683):
>
> Hello everyone! Ok, I admit had help from OpenAi with this. But what I “helped” put together I think can greatly improve the results and costs of using OpenAi within your apps and plugins, specially for those looking to guide internal prompts for plugins… @ruv I’d like to introduce you to two important parameters that you can use with OpenAI’s GPT API to help control text generation behavior: temperature and top\_p sampling. These parameters are especially useful when working with GPT for tas…

---

<div class="post-metadata">

**Author:** ![MrFriday](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/mrfriday/32/350887_2.png) [@MrFriday](https://community.openai.com/u/MrFriday)\
**Post date:** [August 27, 2024, 5:35am UTC](https://community.openai.com/t/the-generated-code-varies-every-time-even-with-a-low-temperature/921970/6 "2024-08-27T05:35:12Z")

</div>

Correct. It’s only available for Chat Completion as chat completion as a standard don’t maintain previous conversation state.
