Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0 is a valid value for temperature, top-p in the openAI API, but is not forwarded by go-openai #678

Open
chrbsg opened this issue Mar 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@chrbsg
Copy link
Contributor

chrbsg commented Mar 6, 2024

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:

@chrbsg chrbsg added the bug Something isn't working label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant