go-openai
go-openai copied to clipboard
0 is a valid value for temperature, top-p in the openAI API, but is not forwarded by go-openai
In chat.go and completion.go and edits.go temperature and top P are defined with json modifier omitempty:
chat.go: Temperature float32 `json:"temperature,omitempty"`
chat.go: TopP float32 `json:"top_p,omitempty"`
completion.go: Temperature float32 `json:"temperature,omitempty"`
completion.go: TopP float32 `json:"top_p,omitempty"`
edits.go: Temperature float32 `json:"temperature,omitempty"`
edits.go: TopP float32 `json:"top_p,omitempty"`
omitempty applies when the value is 0 and hence no temperature or topP value is set in the output JSON. In the case of chat and completions, the documented default value for temperature and top-p is 1, so someone explicitly setting the value to 0 will instead get the value of 1 applied. However, 0 is actually a valid value for temperature and top-p - these curl commands return success:
curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-3.5-turbo-instruct",
"prompt": "Say this is a test",
"max_tokens": 7,
"temperature": 0,
"top_p": 0,
}'
and
curl https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Hello!"
}
],
"max_tokens": 7,
"temperature": 0,
"top_p": 0,
}'
So 0 is a valid value, even thought there is some debate about how exactly a value of 0 is interpreted:
- https://community.openai.com/t/why-the-api-output-is-inconsistent-even-after-the-temperature-is-set-to-0/329541
- https://community.openai.com/t/a-question-on-determinism/8185
- https://community.openai.com/t/questions-regarding-api-sampling-parameters-temperature-top-p/335706
- https://community.openai.com/t/observing-discrepancy-in-completions-with-temperature-0/73380/6