Like with many things, it depends on what you're trying to accomplish.
The two major parameters you can tweak are:
temperature
- Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
top_p
- An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered
In terms of some reference values, the forum post on Mastering Temperature and Top_p in ChatGPT API provides the following examples:
Use Case |
Temp |
Top_p |
Description |
Code Generation |
0.2 |
0.1 |
Generates code that adheres to established patterns and conventions. Output is more deterministic and focused. Useful for generating syntactically correct code. |
Creative Writing |
0.7 |
0.8 |
Generates creative and diverse text for storytelling. Output is more exploratory and less constrained by patterns. |
Chatbot Responses |
0.5 |
0.5 |
Generates conversational responses that balance coherence and diversity. Output is more natural and engaging. |
Code Comment Generation |
0.3 |
0.2 |
Generates code comments that are more likely to be concise and relevant. Output is more deterministic and adheres to conventions. |
Data Analysis Scripting |
0.2 |
0.1 |
Generates data analysis scripts that are more likely to be correct and efficient. Output is more deterministic and focused. |
Exploratory Code Writing |
0.6 |
0.7 |
Generates code that explores alternative solutions and creative approaches. Output is less constrained by established patterns. |
Note: It is generally recommended that you set either temp or top_p, but not both. So for the table above, the values can be seen as roughly equivalent ways to achieve the desired outcome.
Another reason you might include a higher temperature is if the user indicates the first response is wrong and you want to attempt again, but get a different response. Although re-prompting with the new information can also work as well.